Note
This feature is an experimental feature in the current version.
Fork Database creates a new target database based on the full data of the source database at a specific snapshot point. The target database contains all user tables and their data from the source database, and is logically equivalent to a complete copy of the source database at that snapshot point.
Fork Database is implemented at the underlying level using Fork Table. It sequentially performs a fork operation on each user table in the source database, ensuring all tables within the database share the same snapshot version and guaranteeing cross-table data consistency.
Syntax
FORK DATABASE source_database TO destination_database;
Parameters
Parameter |
Description |
|---|---|
source_database |
Source database name |
destination_database |
Target database name |
Application scenarios
Create a database copy for read and write operations
-- Create a copy of the database
FORK DATABASE db_src TO db_fork;
-- The target database can be queried
USE db_fork;
SELECT count(*) FROM t1;
-- The target database can be written to (writing will not affect the source database db_src).
INSERT INTO t1 VALUES (...);
Full database branching and version management
-- 1) Create a branch version based on the major version (the data baseline is the snapshot at the time of the fork).
FORK DATABASE db_prod TO db_prod_branch_v2;
-- 2) Perform experimental changes on the branch database.
-- ... Perform DML or business processes on the tables in the db_prod_branch_v2 database ...
-- 3a) Quick rollback: Stop using the branch version.
DROP DATABASE db_prod_branch_v2;
Fork an empty database
CREATE DATABASE db_empty;
FORK DATABASE db_empty TO db_empty_fork;
-- The target database db_empty_fork is empty and contains no tables.
Core features
Note
Parallel fork and background parallel processing are supported starting from V4.6.2.1.
Features |
Description |
|---|---|
| Database-level cloning | Clones all user tables and data from the source database in one operation, eliminating the need to perform table-by-table operations. |
| Consistent snapshot versions | All tables in the database have the same snapshot version, ensuring cross-table data consistency. |
| Independently writable | The target database can independently perform read/write operations and DDL without affecting the source database. |
| Online execution | The source database can continue DML read and write operations during the Fork process. |
| Progressive availability | The target database becomes accessible after creation. The refinement of background data organization does not affect snapshot semantics or availability. |
| Inherit source database attributes | The target database inherits the character set (charset), collation, and other database attributes of the source database. |
| Multiple forks | The same source database can be forked into multiple target databases multiple times, each time using its own snapshot point. The target databases are independent of each other. |
| Parallel fork | The same source database can be forked into multiple different target databases simultaneously. |
| Background parallel processing | Background data processing uses multi-threaded parallel execution to improve the overall completion efficiency of forks. |
| Empty database support | You can fork an empty database, and the created target database is also empty. |
Privilege requirements
To initiate a Fork Database operation, you must have both:
- The
SELECTprivilege at the database level on the source database (either a global privilege or a database-level privilege on the source database is sufficient; table-levelSELECTprivileges on individual tables in the source database are not sufficient). - The
CREATEprivilege on the target database.
Fork only replicates the schema and data, not the privileges on the source database. The target database determines privileges based on whether the object is created normally. Fork can only be executed within user tenant and does not support the sys tenant.
Operation mutual exclusion
During a Fork Database operation, the source database and its tables are mutually exclusive with DDL operations, such as DROP TABLE and DROP DATABASE. During fork, the source database can still perform DML read and write operations.
Limitations
Object or scenario |
Handling |
|---|---|
oceanbase, mysql, and other system or internal databases |
Not supported |
| Routine (stored procedure, function) | Ignored during fork |
| Package | Ignored during fork |
| Trigger | Ignored during fork |
| Sequence | Not supported |
| Outline | Ignored during fork |
User tables in a Fork Database must also meet the requirements for table type, index type, and storage format specified for Fork Table. For details, see Fork Table.
Fork Database only processes user base tables; other non-base table objects such as views are ignored.
Considerations
- Fork Database clones all user tables and their data from the source database.
- After creation, the target database is completely independent of the source database. Modifications made to either side will not be reflected in the other.
- DDL operations on the source database (such as adding tables or modifying table structures) will not be automatically synchronized to the target database.
- The fork operation will not affect the normal operation of the source database.