Skip to main content
Version: V1.2.0

FORK DATABASE

Description​

FORK DATABASE creates a destination database copy from a source database at a snapshot time chosen by the system. The destination database is logically equivalent to the source database's data view at that snapshot. It includes all user tables and their data from the source, and inherits database-level properties such as character set and collation. The destination can be read and written as an independent database and is isolated from the source; writes to the destination do not affect the source.

Fork Database is implemented on top of Fork Table: it forks each user table in the source database in turn and ensures that all tables in the database share the same snapshot version, so you get a consistent data view for multi-table joins, foreign keys, and similar scenarios.

tip
  1. In seekdb V1.2.0, Fork Database is an experimental feature. Use it cautiously in production environments.
  2. Besides SQL syntax, Fork Database also supports database-level forks through the pyseekdb SDK. For details, see pyseekdb fork_database() API.

Privileges​

To execute FORK DATABASE, you need:

  • Access to the source database (for example, SELECT, to read table structure and data).
  • Permission to create databases (for example, CREATE), to create the destination database and its tables.

For subsequent reads, writes, or DDL on the destination database, you need the appropriate privileges on that database and its tables.

Syntax​

FORK DATABASE source_database TO destination_database;

Parameters​

ParameterDescription
source_databaseThe source database name.
destination_databaseThe destination database name. The destination will contain all user tables and data from the source as of the fork time, and will inherit the source database's database-level properties.

Behavior​

  • Atomic snapshot at database scope: All tables in the destination database share the same fork snapshot version, so multi-table joins and in-database foreign keys remain logically consistent after the fork.
  • Property inheritance: The destination database inherits database-level properties from the source, such as character set (charset) and collation.
  • Read/write isolation: The destination and source are independent. Writes to the destination do not affect the source, and writes to the source do not affect the destination.
  • Empty databases: Forking a database with no user tables is supported; the destination will be empty.
  • Multiple forks: You can fork the same source database to different destination databases multiple times. Each run uses its own snapshot time, and the destinations are independent of each other.
  • Foreign key handling: Foreign keys in the source that reference only other tables in the same database are fully preserved and enforced in the destination. Cross-database foreign keys that reference other databases are skipped during the fork and are not created in the destination.
  • Mutual exclusion with DDL: While a fork is in progress, the source database and its tables are mutually exclusive with DDL until the fork finishes; the source database can continue to accept DML reads and writes.

Limitations and considerations​

  • The destination database must not exist: If the destination database already exists, the system returns an error. Drop the existing destination database first or use a different name.
  • Source database restrictions:
    • Forking system or internal databases (for example, oceanbase, mysql) is not supported.
    • Forking a database that has been dropped and is in the recycle bin is not supported.
    • The source and destination cannot have the same name (for example, FORK DATABASE db1 TO db1).
    • Forking databases that contain the following objects is not supported: stored procedures/functions (routines), packages, triggers, sequences, and outlines.
  • Table-level restrictions: Each user table in the source must satisfy Fork Table's support conditions; otherwise the fork fails. This includes but is not limited to: internal tables, temporary tables, and materialized views are not supported; column-store tables are not supported; partitioned tables with global indexes are not supported; semantic indexes, IVF indexes, and spatial indexes are not supported; if a source table has an HNSW vector index, memory pressure may be higher. See Fork a table for details.
  • Mutual exclusion with DDL: During the fork, the source database and its tables are mutually exclusive with DDL until the fork finishes.

Examples​

Example 1: Create a database copy and read/write​

-- Create a database copy
FORK DATABASE db_src TO db_fork;

-- Query the destination database
USE db_fork;
SELECT COUNT(*) FROM t1;

-- Write to the destination database (writes do not affect source db_src)
INSERT INTO t1 VALUES (...);

Example 2: Whole-database branching and versioning​

-- 1) Create a branch from the main version (data baseline is the snapshot at fork time)
FORK DATABASE db_prod TO db_prod_branch_v2;

-- 2) Make experimental changes in the branch database
-- ... run DML / business workflows against tables in db_prod_branch_v2 ...

-- 3) Roll back quickly: stop using the branch database
DROP DATABASE db_prod_branch_v2;

Example 3: Fork an empty database​

CREATE DATABASE db_empty;
FORK DATABASE db_empty TO db_empty_fork;
-- Destination db_empty_fork is empty and contains no tables

FAQ​

Q1: How is Fork Database different from forking table by table with Fork Table?​

Fork Database forks all user tables in the source database using the same snapshot version, which preserves database-level consistency for multi-table joins, foreign keys, and similar cases. When you fork table by table with Fork Table, each table's snapshot time may differ, so database-level consistency is not guaranteed. Fork Database also inherits database properties (such as character set and collation) and creates the destination database and all tables in one step.

Q2: Can I fork an empty database?​

Yes. Forking an empty database creates an empty destination database with no tables.

Q3: What happens in the destination if the source has cross-database foreign keys?​

Cross-database foreign keys are skipped during the fork and are not created in the destination. Only in-database foreign keys between tables are preserved and enforced.

Q4: Can I fork the same source database multiple times?​

Yes. Each fork must use a different destination database. Each destination holds a snapshot from its own fork time and is independent of the others.

References​