Skip to main content
Version: V1.4.1

Fork a database

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 moment and can be read and written as an independent database. Fork Database can be used through SQL or the SDK: you can run the FORK DATABASE statement directly, or initiate a database-level fork through the pyseekdb SDK. This topic focuses on what Fork Database does, when to use it, and how to use it with SQL. If you need to call it from Python or an automated workflow, see the pyseekdb API documentation linked at the end.

tip

In seekdb V1.2.0, Fork Database is an experimental feature. Use it cautiously in production environments.

Overview​

When developing and iterating at whole-database scope, you may need to branch quickly from the same business database for parallel data revisions, feature engineering, index and metadata policy changes, and regression validation, while keeping a clear data lineage. Traditional approaches that fully export/import an entire database or copy table by table are often slow and resource-heavy for large databases.

Fork Database creates a destination database copy from a source database at a consistent snapshot time chosen by the system. The destination database includes all user tables from the source and their data as of that snapshot, and inherits database-level properties such as character set and collation. The destination and source are independent of each other and can be read and written separately; writes to the destination do not affect the source. Under the hood, Fork Database builds on 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.

Use cases​

  • Whole-database branching and versioning: Branch quickly from the same business database for parallel data revisions, feature engineering, index/metadata policy changes, and regression validation, with a clear lineage. If a branch does not meet expectations, you can roll back quickly; if it does, you can promote it as a new version (the exact switch-over depends on your business and operations processes).
  • Whole-database sandboxes and A/B tests: Create an isolated copy from a production snapshot to safely validate different business logic, algorithm parameters, or large-model inference behavior, compare multiple approaches, and avoid impacting the online database.
  • Whole-database migration and backup: Create a database-level copy quickly for disaster recovery, test environments, or validation before archival.

How it works​

Fork Database's key semantics are:

  • 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.
  • Database property inheritance: The destination database inherits database-level properties from the source, such as character set and collation.
  • Read/write isolation: The destination and source are independent; writes to either database do not affect the 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.

Limitations and considerations​

  • Mutual exclusion with DDL: While a fork is in progress, the source database and its tables are mutually exclusive with DDL (for example, DROP TABLE, DROP DATABASE) until the fork finishes. The source database can continue to accept DML reads and writes during the fork.
  • Database-level restrictions:
    • The destination database must not already exist; otherwise an error is returned. Drop any existing destination database first.
    • 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 the support conditions for Fork Table; otherwise, the fork fails. Unsupported tables include internal tables, temporary tables, partitioned tables with global indexes, and tables with semantic, IVF, or spatial indexes. A source table with an HNSW vector index can create additional memory pressure. See Fork Table for details.
  • Foreign keys: In-database foreign keys between tables are kept in the destination; cross-database foreign keys are skipped during the fork and are not created in the destination.

Example: Create a database copy and verify isolation​

The following example walks through the basic Fork Database flow: create a source database and table → fork to a destination database → query and write in the destination to verify isolation from the source.

  1. Create the source database, create a table, and insert data.

    CREATE DATABASE db_src;
    USE db_src;
    CREATE TABLE t1 (c1 INT PRIMARY KEY, c2 INT);
    INSERT INTO t1 VALUES (1, 10);
  2. Create a destination database copy from the source database.

    FORK DATABASE db_src TO db_fork;
  3. Query and insert in the destination database to verify isolation from the source.

    USE db_fork;
    SELECT COUNT(*) FROM t1; -- Matches the source snapshot

    INSERT INTO t1 VALUES (2, 200); -- Writes do not affect source db_src
    USE db_src;
    SELECT * FROM t1; -- Still only (1, 10)

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: 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.

Q4: 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.

Q5: After the fork completes, do later changes to the source affect the destination?​

No. The destination is built from a consistent snapshot at fork time. Changes to the source after that do not affect the destination.

References​