You can clone a tenant based on a specified source tenant. The number of units in the cloned tenant and the distribution of units across OBServer nodes are the same as those in the source tenant.
Limitations
You cannot clone a tenant during a switchover.
For more information about switchover, see Switchover.
You cannot clone a tenant during the addition, deletion, or attribute change of a leader server (LS).
You can run the
SELECT * FROM oceanbase.CDB_OB_BALANCE_JOBS WHERE tenant_id = XXX;statement in the sys tenant to check whether an LS operation is in progress.You cannot clone a tenant during a transfer.
You can run the
SELECT * FROM oceanbase.CDB_OB_BALANCE_JOBS WHERE tenant_id = XXX;statement in the sys tenant to check whether a transfer task is in progress.You cannot clone a tenant during a unit migration.
You can run the
SELECT * FROM oceanbase.DBA_OB_UNITS WHERE MIGRATE_FROM_SVR_PORT IS NOT NULL;statement in the sys tenant to check whether a unit migration task is in progress.You cannot clone a tenant when you reduce the number of
UNIT_NUMin a resource pool.You cannot clone a tenant if an OBServer node that hosts a unit in the source tenant is unavailable.
You cannot clone a tenant if a disaster recovery task is in progress for the log stream replica of the current tenant.
To check whether a disaster recovery task is in progress for the log stream replica of the current tenant, perform the following operations:
In the sys tenant, query the
CDB_OB_LS_REPLICA_TASKSview by specifying thetenant_idof the current tenant. If the query result is not empty, a disaster recovery task is in progress for the current tenant.In a user tenant, query the
DBA_OB_LS_REPLICA_TASKSview. If the query result is not empty, a disaster recovery task is in progress for the current tenant.
You cannot clone a tenant during an upgrade.
You cannot clone a tenant of a version earlier than OceanBase Database V4.3.0.
Considerations
The new tenant cloned from the source tenant is strictly isolated from the source tenant in terms of data and resources. Any data changes made to the new tenant do not affect the source tenant, and vice versa. The new tenant does not compete with the source tenant for resources such as CPU and memory.
The source tenant and the new tenant initially share physical macroblocks. As the source tenant and the new tenant write data separately, the shared macroblocks gradually decrease and the exclusive macroblocks gradually increase. The storage space occupied by the two tenants also increases. Therefore, you need to monitor the storage space occupied by the OBServer nodes.
During a tenant clone task, you cannot perform the following operations:
Perform a switchover on the source tenant.
Perform a tenant scale-out or scale-in operation by modifying the number of
UNIT_NUMor the primary zone of the source tenant.Perform an add replica, drop replica, or rebalance replica operation on the source tenant.
Manually perform a transfer operation on the source tenant.
Manually perform a unit migration operation on the source tenant.
Perform an upgrade operation on the source tenant.
If you must perform any of the preceding operations, you can cancel the tenant clone task and then perform the operation. For more information about how to cancel a tenant clone task, see Cancel a tenant clone task.
Prerequisites
The tenant clone feature depends on the log archiving feature of a tenant. Before you execute a tenant clone operation, make sure that log archiving is enabled for the source tenant and that log archiving is not disabled during the tenant clone operation. For more information about how to set the archive destination for the source tenant and enable log archiving, see Prepare for log archiving and Enable log archiving.
Notice
After you enable log archiving for a tenant, you can execute the ALTER SYSTEM MINOR FREEZE TENANT = tenant_name; statement to initiate a minor freeze for the tenant to perform a minor compaction. For more information about how to manually trigger a minor compaction, see Manually trigger a minor compaction.
Background information
The tenant clone feature applies to various scenarios. Some examples are as follows:
When you need to test and verify an application version, you can quickly clone an online tenant to create a test tenant and use the test tenant for application testing and verification.
When you need to execute relatively high-risk operations such as DDL operations on a database, you can:
Clone an online tenant to create a test tenant and run the DDL statement on the test tenant to verify the execution result.
Clone an online tenant to create a small-scale tenant at the current time point before executing the DDL statement. If the DDL statement execution fails, you can quickly roll back the data.
Procedure
Log in to the
systenant of the cluster as therootuser.obclient -h172.30.xx.xx -P2883 -uroot@sys#cluster -p**** -AExecute the following statement to clone a tenant.
CREATE TENANT new_tenant_name FROM source_tenant_name WITH RESOURCE_POOL [=] resource_pool_name, UNIT [=] unit_config;The parameters are described as follows:
new_tenant_name: the name of the new tenant to be cloned. You can clone only one tenant at a time. If you want to clone multiple tenants, you must wait until the current cloning task is completed before you can clone another tenant.source_tenant_name: the name of the source tenant.resource_pool_name: the name of the resource pool for the new tenant. When you clone a tenant, the system automatically creates a resource pool for the new tenant based on the resource distribution of the source tenant.unit_config: the specification of the unit for the new tenant. You can specify an existing unit specification in the system or create a new one. For more information about how to query existing unit specifications, see View resource specifications.
Here is an example of cloning a tenant named
mysqlto create a new tenant namedclone_tnt:obclient [oceanbase]> CREATE TENANT clone_tnt FROM mysql WITH RESOURCE_POOL = clone_tnt_pool, UNIT= S1_unit_config;In this example, the new tenant
clone_tntis associated with the resource poolclone_tnt_pooland the unit specificationS1_unit_config. The number of units and their distribution across OBServer nodes for the new tenant are the same as those for the source tenant.During the cloning process, you can view the status of the cloning task by querying views.
View the status of a running cloning task
obclient [oceanbase]> SELECT * FROM oceanbase.DBA_OB_CLONE_PROGRESS\GThe query result is as follows:
*************************** 1. row *************************** CLONE_JOB_ID: 1702211800546509768 TRACE_ID: YA4740B7C050F-00060C210F4A4848-0-0 SOURCE_TENANT_ID: 1004 SOURCE_TENANT_NAME: mysql CLONE_TENANT_ID: 1016 CLONE_TENANT_NAME: clone_tnt TENANT_SNAPSHOT_ID: 1702211800802135214 TENANT_SNAPSHOT_NAME: _inner_snapshot$1702211800702058206 RESOURCE_POOL_ID: 1008 RESOURCE_POOL_NAME: clone_tnt_pool UNIT_CONFIG_NAME: S1_unit_config RESTORE_SCN: 1702211802014048020 STATUS: CLONE_SYS_CREATE_TENANT CLONE_JOB_TYPE: FORK CLONE_START_TIME: 2023-12-10 20:36:40.551169 CLONE_FINISHED_TIME: NULL RET_CODE: NULL ERROR_MESSAGE: NULL 1 row in setView the history of cloning tasks
obclient [oceanbase]> SELECT * FROM oceanbase.DBA_OB_CLONE_HISTORY\GThe query result is as follows:
*************************** 1. row *************************** CLONE_JOB_ID: 1702211800546509768 TRACE_ID: YA4740B7C050F-00060C210F4A4848-0-0 SOURCE_TENANT_ID: 1004 SOURCE_TENANT_NAME: mysql CLONE_TENANT_ID: 1016 CLONE_TENANT_NAME: clone_tnt TENANT_SNAPSHOT_ID: 1702211800802135214 TENANT_SNAPSHOT_NAME: _inner_snapshot$1702211800702058206 RESOURCE_POOL_ID: 1008 RESOURCE_POOL_NAME: clone_tnt_pool UNIT_CONFIG_NAME: S1_unit_config RESTORE_SCN: 1702211802014048020 STATUS: CLONE_SYS_SUCCESS CLONE_JOB_TYPE: FORK CLONE_START_TIME: 2023-12-10 20:36:40.551169 CLONE_FINISHED_TIME: 2023-12-10 20:37:53.919247 RET_CODE: 0 ERROR_MESSAGE: NULL 1 row in set
What to do next
After the tenant cloning task is completed, the new tenant is a standby tenant. You can continue to use the new tenant as a standby tenant or switch it to a primary tenant. For more information about how to switch a standby tenant to a primary tenant, see Switch a standby tenant to a primary tenant.
In a scenario where an arbitration service is deployed, the arbitration service is not enabled by default for the new tenant. If you want to enable the arbitration service, you can do so after the cloning task is completed. For more information, see Enable the arbitration service for a tenant.
