This is a general method for creating a standby tenant. It restores a standby tenant from data backups and archived logs of the primary tenant or an existing standby tenant.
Step 1: Enable archivelog for the primary tenant or source standby tenant and back up data
New standby tenants are restored from data backups and archived logs. Therefore, before you create a standby tenant, you must enable archivelog for the primary tenant or source standby tenant and perform a full data backup.
Note
You can specify the archiving destination, enable archivelog, specify the backup destination, and perform data backup in the sys tenant or a user tenant. In the sys tenant, you must add tenant = 'tenant_name' to the end of the statements. This topic describes how to perform the operations in a user tenant.
Enable archivelog for the primary tenant or source standby tenant and ensure that the archiving status is
DOING.Specify the archiving destination.
Assuming that the archiving medium is Network File System (NFS), execute the following sample SQL statement in a user tenant to set the archiving destination path to
/data/1/sh_archive/:ALTER SYSTEM SET LOG_ARCHIVE_DEST = 'LOCATION=file:///data/1/sh_archive';For more information, see Preparations.
Enable archivelog for the primary tenant or source standby tenant.
Notice
To ensure archiving of all logs generated during data backup, you must enable archivelog for the tenant before you perform data backup.
Execute the following SQL statement in a user tenant to enable archivelog:
ALTER SYSTEM ARCHIVELOG;For more information, see Enable ARCHIVELOG.
Verify that the archiving status is
DOING.In the
systenant, you must query the archiving status from theCDB_OB_ARCHIVELOGview. Sample SQL statements:systenantSELECT DEST_ID, ROUND_ID, DEST_NO, STATUS, CHECKPOINT_SCN, CHECKPOINT_SCN_DISPLAY, PATH FROM oceanbase.CDB_OB_ARCHIVELOG;MySQL tenant
SELECT DEST_ID, ROUND_ID, DEST_NO, STATUS, CHECKPOINT_SCN, CHECKPOINT_SCN_DISPLAY, PATH FROM oceanbase.DBA_OB_ARCHIVELOG;Oracle tenant
SELECT DEST_ID, ROUND_ID, DEST_NO, STATUS, CHECKPOINT_SCN, CHECKPOINT_SCN_DISPLAY, PATH FROM SYS.DBA_OB_ARCHIVELOG;
The query result is as follows:
+---------+----------+---------+--------+---------------------+----------------------------+--------------------------------+ | DEST_ID | ROUND_ID | DEST_NO | STATUS | CHECKPOINT_SCN | CHECKPOINT_SCN_DISPLAY | PATH | +---------+----------+---------+--------+---------------------+----------------------------+--------------------------------+ | 1001 | 1 | 0 | DOING | 1680265982125159110 | 2023-03-31 20:33:02.125159 | file:///data/1/sh_archive | +---------+----------+---------+--------+---------------------+----------------------------+--------------------------------+ 1 row in setIn the query result, the value of
STATUSisDOING, which indicates that the system is archiving logs.For more information, see View the archiving progress.
Enable data backup for the primary tenant or source standby tenant and perform a full backup.
After you enable archivelog, you must perform a data backup for the primary tenant or source standby tenant.
Specify the backup destination.
Assuming that the backup medium is NFS, execute the following SQL statement in a user tenant to set the backup destination path to
/data/1/sh_databackup:ALTER SYSTEM SET DATA_BACKUP_DEST = 'file:///data/1/sh_databackup';For more information, see Preparations.
Perform a data backup.
Execute the following SQL statement in a user tenant:
ALTER SYSTEM BACKUP DATABASE;For more information about how to initiate a full data backup for a tenant, see Initiate a data backup job.
Check the data backup status.
You can check the data backup progress by querying the
DBA_OB_BACKUP_JOBSview in a user tenant or theCDB_OB_BACKUP_JOBSview in thesystenant. Sample SQL statements:systenantSELECT * FROM oceanbase.CDB_OB_BACKUP_JOBS;MySQL tenant
SELECT * FROM oceanbase.DBA_OB_BACKUP_JOBS;Oracle tenant
SELECT * FROM SYS.DBA_OB_BACKUP_JOBS;
If the backup has started, the progress of the backup job is displayed in the views. For more information, see View the data backup progress.
If the backup is completed, you can view the data backup history by querying the
DBA_OB_BACKUP_JOB_HISTORYview in a user tenant or theCDB_OB_BACKUP_JOB_HISTORYview in thesystenant. Sample SQL statements:systenantSELECT * FROM oceanbase.CDB_OB_BACKUP_JOB_HISTORY;MySQL tenant
SELECT * FROM oceanbase.DBA_OB_BACKUP_JOB_HISTORY;Oracle tenant
SELECT * FROM SYS.DBA_OB_BACKUP_JOB_HISTORY;
The query result is as follows:
+--------+-------------+---------------+---------------------+------------------+--------------------+-----------------+-------------+-------------+-----------------+--------+----------------------------+----------------------------+-----------+--------+---------+-------------+-------------------------------+ | JOB_ID | INCARNATION | BACKUP_SET_ID | INITIATOR_TENANT_ID | INITIATOR_JOB_ID | EXECUTOR_TENANT_ID | PLUS_ARCHIVELOG | BACKUP_TYPE | JOB_LEVEL | ENCRYPTION_MODE | PASSWD | START_TIMESTAMP | END_TIMESTAMP | STATUS | RESULT | COMMENT | DESCRIPTION | PATH | +--------+-------------+---------------+---------------------+------------------+--------------------+-----------------+-------------+-------------+-----------------+--------+----------------------------+----------------------------+-----------+--------+---------+-------------+-------------------------------+ | 1 | 1 | 1 | 1004 | 0 | 1004 | OFF | FULL | USER_TENANT | NONE | | 2023-03-31 20:48:32.342315 | 2023-03-31 20:49:39.908559 | COMPLETED | 0 | | | file:///data/1/sh_databackup | +--------+-------------+---------------+---------------------+------------------+--------------------+-----------------+-------------+-------------+-----------------+--------+----------------------------+----------------------------+-----------+--------+---------+-------------+-------------------------------+ 1 row in setIn the query result, the value of
STATUSisCOMPLETED, which indicates that the data backup is completed.
Step 2: Restore a standby tenant
Log on as the
rootuser to thesystenant of the cluster where you want to create the standby tenant.Create a unit with required specifications for the standby tenant.
The following sample statement creates a unit named
unit1that contains 1 CPU core and 5 GB of memory.CREATE RESOURCE UNIT unit1 MAX_CPU 1, MEMORY_SIZE = '5G';For more information, see Create a tenant.
Create a resource pool for the standby tenant.
We recommend that you create a resource pool with the same number of resource units as that of the resource pool for the source tenant.
The following sample statement creates a resource pool named
pool_for_standby.CREATE RESOURCE POOL pool_for_standby UNIT = 'unit1', UNIT_NUM = 1, ZONE_LIST = ('zone1','zone2','zone3');For more information, see Create a tenant.
Execute the
RESTOREstatement to restore the standby tenant by using the data backups and archived logs of thesystenant.The syntax is as follows:
ALTER SYSTEM RESTORE standby_tenant_name FROM uri UNTIL TIME =timestamp WITH restore_option [DESCRIPTION description];where
standby_tenant_nameindicates the name of the standby tenant to be restored.uriindicates the data backup path and archive path for the primary or source standby tenant.UNTIL TIME= timestampindicates the restore end point, which is the timestamp to which the standby tenant is restored. Join the parameter name and the value oftimestampwith an equal sign (=). The value oftimestampmust be in theYYYY-MM-DD HH24:MI:SS.FFformat, accurate to nanoseconds.For more information about how to specify
timestamp, see Parameters related to physical restore.restore_optionprovides the following options:pool_list,locality, andprimary_zone, wherepool_listis required and the others are optional. Different parameters are separated by ampersands (&). When you specifylocalityorprimary_zone, we recommend that you specify the same value as that of the source tenant. Otherwise, load balancing may be performed after the tenant is restored and activated as the primary tenant, which compromises the performance.For more information about options in
restore_option, see Parameters related to physical restore.WITH KEY FROM 'backup_key_path' ENCRYPTED BY 'password'indicates the backup information of the key for encrypting the tenant. You need to specify the key backup information for a tenant restore only when the tenant is configured with transparent encryption.backup_key_path: the backup path for the key.password: the encryption password specified during key backup.
Example: Restore a standby tenant named
standby_tenantfrom the log archive pathfile:///data/1/sh_archiveand data backup pathfile:///data/1/sh_databackup.ALTER SYSTEM RESTORE standby_tenant FROM 'file:///data/1/sh_databackup,file:///data/1/sh_archive' UNTIL TIME='2023-05-26 15:04:23.825558' WITH 'pool_list=pool_for_standby';For more information about the
RESTOREstatement, see Parameters related to physical restore.Verify that the restore is completed.
You can check the restore progress by querying the
DBA_OB_TENANTSview.SELECT TENANT_NAME, TENANT_TYPE, CREATE_TIME, STATUS, TENANT_ROLE,SCN_TO_TIMESTAMP(SYNC_SCN) FROM oceanbase.DBA_OB_TENANTS WHERE TENANT_NAME = 'standby_tenant';The query result is as follows:
+----------------+-------------+----------------------------+--------+-------------+----------------------------+ | TENANT_NAME | TENANT_TYPE | CREATE_TIME | STATUS | TENANT_ROLE | SCN_TO_TIMESTAMP(SYNC_SCN) | +----------------+-------------+----------------------------+--------+-------------+----------------------------+ | standby_tenant | USER | 2023-04-02 20:42:38.800518 | NORMAL | STANDBY | 2023-04-02 20:42:30.736135 | +----------------+-------------+----------------------------+--------+-------------+----------------------------+ 1 row in setIn the query result, the value of
TENANT_ROLEisSTANDBY, which indicates that the standby tenant is restored.For more information, see Query the physical restore progress.
Step 3: Enable continuous log synchronization
If you create a standby tenant by using the RESTORE statement, the new standby tenant does not continuously synchronize the archived logs of the primary tenant or source standby tenant by default. You must manually execute the RECOVER statement to specify a restore end point for the new standby tenant, to enable continuous log synchronization.
Log on as the administrator to the new standby tenant or the
systenant of the cluster where the new standby tenant resides.Execute the
RECOVERstatement to modify the restore end point for the new standby tenant as needed.Execute the following statement in the
systenant of the cluster where the new standby tenant resides to enable continuous log synchronization for the new standby tenant:ALTER SYSTEM RECOVER STANDBY TENANT = tenant_name UNTIL UNLIMITED;UNLIMITEDindicates that the end point is infinite.For example:
ALTER SYSTEM RECOVER STANDBY TENANT = standby_tenant UNTIL UNLIMITED;Execute the following statement in the new standby tenant to enable continuous log synchronization for the new standby tenant:
ALTER SYSTEM RECOVER STANDBY UNTIL UNLIMITED;
Query the synchronization timestamp for the new standby tenant from the
SYNC_SCNfield in theDBA_OB_TENANTSview.The synchronization progress of the new standby tenant is displayed in the
SCN_TO_TIMESTAMP(SYNC_SCN)field.Query the view from the
systenant of the cluster where the new standby tenant residesSELECT TENANT_NAME, TENANT_TYPE, CREATE_TIME, STATUS, TENANT_ROLE,SCN_TO_TIMESTAMP(SYNC_SCN) FROM oceanbase.DBA_OB_TENANTS WHERE TENANT_NAME = 'standby_tenant';Query the view from the new standby tenant
MySQL tenant
SELECT TENANT_NAME, TENANT_TYPE, CREATE_TIME, STATUS, TENANT_ROLE,SCN_TO_TIMESTAMP(SYNC_SCN) FROM oceanbase.DBA_OB_TENANTS WHERE TENANT_NAME = 'standby_tenant';The query result is as follows:
+----------------+-------------+----------------------------+--------+-------------+----------------------------+ | TENANT_NAME | TENANT_TYPE | CREATE_TIME | STATUS | TENANT_ROLE | SCN_TO_TIMESTAMP(SYNC_SCN) | +----------------+-------------+----------------------------+--------+-------------+----------------------------+ | standby_tenant | USER | 2023-04-02 20:42:38.800518 | NORMAL | STANDBY | 2023-04-02 21:06:50.810688 | +----------------+-------------+----------------------------+--------+-------------+----------------------------+ 1 row in setOracle tenant
SELECT TENANT_NAME, TENANT_TYPE, CREATE_TIME, STATUS, TENANT_ROLE,SCN_TO_TIMESTAMP(SYNC_SCN) FROM SYS.DBA_OB_TENANTS WHERE TENANT_NAME = 'standby_tenant';The query result is as follows:
+------------------+-------------+------------------------------+--------+-------------+---------------------------------+ | TENANT_NAME | TENANT_TYPE | CREATE_TIME | STATUS | TENANT_ROLE | SCN_TO_TIMESTAMP(SYNC_SCN) | +------------------+-------------+------------------------------+--------+-------------+---------------------------------+ | standby_tenant | USER | 23-MAY-23 02.37.58.647507 PM | NORMAL | STANDBY | 26-MAY-23 01.34.46.896905660 PM | +------------------+-------------+------------------------------+--------+-------------+---------------------------------+ 1 row in set