Purpose
The ALTER SYSTEM RECOVER TABLE statement is used to recover table data. Specifically, it recovers a user-specified table from a backup to an existing tenant. This existing tenant can be the same as the original tenant where the table was located, or it can be a different tenant, even in a different cluster.
Limitations and considerations
When recovering a table, only user tables can be recovered. Temporary tables, views, and indexes cannot be recovered separately.
When recovering a table, foreign keys, triggers, and statistics on the table cannot be recovered.
When recovering a table, the source and destination tenants must be compatible. For example, both must be Oracle-compatible tenants or both must be MySQL-compatible tenants.
Like tenant recovery, table recovery currently only supports restoring tables from a lower version backup to the same version or a higher version. It does not support reverse recovery between minor versions within the same major version.
When recovering a table, the specified table name must match the actual stored table name in the system. For example, if a table named
testis created in an Oracle-compatible tenant, the system internally stores it asTEST. Therefore, when recovering the table, you must specify the table name asTEST. Otherwise, the system will return an error indicating that the table does not exist.When using the
ALTER SYSTEM RECOVER TABLEstatement to recover a table, an auxiliary tenant is required. Before executing the statement, ensure that the necessary resource pools have been created for the auxiliary tenant in the cluster where the destination tenant resides. For detailed instructions on creating the required resource pools for the auxiliary tenant, see Prepare for table recovery.
Privilege requirements
Only the root user of the sys tenant (root@sys) can execute the ALTER SYSTEM RECOVER TABLE statement.
Syntax
ALTER SYSTEM
RECOVER TABLE table_name_list
TO [TENANT [=]] dest_tenant_name
FROM uri [ UNTIL {TIME ='timestamp'}| {SCN = scn} ]
WITH 'restore_option' [WITH KEY FROM 'backup_key_path' ENCRYPTED BY 'password']
[REMAP TABLE remap_table_name_list]
[REMAP TABLEGROUP remap_tablegroup_list]
[REMAP TABLESPACE remap_tablespace_list]
[DESCRIPTION [=] description];
table_name_list:
database_name.table_name [, database_name.table_name ...]
remap_table_name_list:
/* The database name remains unchanged, and only the table name is changed. */
database_name.old_table_name:new_table_name
/* The table name remains unchanged, and only the database name is changed. */
|old_database_name.table_name:new_database_name.table_name
/* Both the database name and the table name are changed. */
| old_database_name.old_table_name:new_database_name.new_table_name
/* All tables in the source database are recovered to a new database. */
| old_database_name.`*`:new_database_name.`*`
remap_tablegroup_list:
old_tablegroup_name:new_tablegroup_name
remap_tablespace_list:
old_tablespace_name:new_tablespace_name
Parameters
| Parameter | Description |
|---|---|
| table_name_list | The name of the table to be restored, in the format of database_name.table_name1,database_name.table_name2,.... Multiple tables are separated by commas (,).
|
| dest_tenant_name | The name of the target tenant for table-level restore. In the current version, only user tenants are supported. |
| uri | The path for data backup and log archiving. If the data backup was initiated using the PLUS ARCHIVELOG method, you only need to specify one path. Otherwise, you need to separately input the paths for data backup and log archiving (at least 2 paths), for example, 'file:///backup/archive, file:///backup/data'. For more information about data backup methods, please refer to the BACKUP command. |
| UNTIL | The endpoint for restore, up to and including this point. When specifying a TIME or SCN, you must use = to connect to the specified value. If the UNTIL clause is not specified, the default is to restore to the latest point.
|
| restore_option | The pool_list, locality, primary_zone, and concurrency of the auxiliary tenant, separated by &:
|
| WITH KEY FROM 'backup_key_path' ENCRYPTED BY 'password' | Specifies the encrypted tenant key backup information, which is optional. This parameter is required only when the source tenant is configured with transparent encryption. The parameters are as follows:
|
| REMAP | Specifies the mapping relationship. If the REMAP parameter is not specified, the system will attempt to place the target table in the same TableSpace->Table Group->Database as the original table. |
| remap_table_name_list | The new name of the restored table. You can rename only the table name, leaving the database name unchanged; you can also keep the table name unchanged and rename it to another database; or you can rename both the table name and the database name. The source object and the renamed object are connected by a colon (:). |
| remap_tablegroup_list | The new name of the table group to which the table belongs. If the source table is bound to a table group, the system will default to restoring the table to the same-named table group in the target tenant. If the same-named table group does not exist, the table restore will fail. If there are other table groups in the target tenant, you can use this statement to restore the table to other table groups. The source object and the renamed object are connected by a colon (:). |
| remap_tablespace_list | The new name of the tablespace to which the table belongs. In OceanBase Database, a tablespace is a logical unit, primarily used for data encryption. If the source table is bound to a tablespace, the system will default to restoring the table to the same-named tablespace in the target tenant. If the same-named tablespace does not exist, the table restore will fail. If there are other tablespaces in the target tenant, you can also use this statement to restore the table to other tablespaces. The source object and the renamed object are connected by a colon (:). |
| description | The description of the operation, which is optional. |
Examples
In the test database of the MySQL mode tenant obt, the data backup path is set to 'file:///data/backup/data', and the log archiving path is set to 'file:///data/backup/archive'. Log archiving is enabled, and a full data backup has been performed. During the operation, the student table was mistakenly deleted. The following example shows how to restore the test.student table in a specific tenant to the time point '2023-08-21 19:47:20' using table-level recovery and rename it to student_recover.
In the
systenant, create the resources required for the table-level recovery process. In this example, create a resource pool with a4c4gspecification.Create a resource unit.
obclient [oceanbase]> CREATE RESOURCE UNIT recover_4c5g MAX_CPU 4, MEMORY_SIZE = '5G', MAX_IOPS 1024, MIN_IOPS=1024;Create a resource pool.
obclient [oceanbase]> CREATE RESOURCE POOL recover_tmp_pool UNIT = 'recover_4c5g', UNIT_NUM = 1, ZONE_LIST = ('z1','z2','z3');
Restore the
studenttable to thetestdatabase in the target tenantobt, rename it tostudent_recover, use the data backup pathfile:///data/backup/data, the archive log pathfile:///data/backup/archive, and restore it to the time point'2023-08-21 19:47:20'. The auxiliary tenant will use the Resource Poolrecover_tmp_pooland the Primary Zonez1.obclient [oceanbase]> ALTER SYSTEM RECOVER TABLE test.student TO TENANT obt FROM 'file:///data/backup/data,file:///data/backup/archive' UNTIL TIME='2023-08-21 19:47:20' WITH 'pool_list=recover_tmp_pool&primary_zone=z1' REMAP TABLE test.student:student_recover;After the table-level recovery command is executed successfully, you can view the recovery progress in the
CDB_OB_RECOVER_TABLE_JOBSview. TheSTATUScolumn indicates the recovery stage, andRESTORE_AUX_TENANTindicates that the auxiliary tenant is being restored.obclient [oceanbase]> SELECT * FROM oceanbase.DBA_OB_RECOVER_TABLE_JOBS\GThe query result is as follows:
*************************** 1. row *************************** TENANT_ID: 1 JOB_ID: 2 INITIATOR_TENANT_ID: 1 INITIATOR_JOB_ID: 2 START_TIMESTAMP: 2023-08-21 19:54:25 END_TIMESTAMP: 1970-01-01 08:00:00 STATUS: RESTORE_AUX_TENANT AUX_TENANT_NAME: AUX_RECOVER$1692618864733548 TARGET_TENANT_NAME: OBT IMPORT_ALL: 0 DB_LIST: NULL TABLE_LIST: `TEST`.`STUDENT` RESTORE_SCN: 1692618440000000000 RESTORE_SCN_DISPLAY: 21-AUG-23 07.47.20.000000000 PM RESTORE_OPTION: pool_list=RECOVER_TMP_POOL&primary_zone=z1 BACKUP_DEST: file:///data/backup/data,file:///data/backup/archive BACKUP_SET_LIST: file:///data/backup/data/backup_set_1_full BACKUP_PIECE_LIST: file:///data/backup/archive/piece_d1002r1p1 BACKUP_PASSWD: NULL EXTERNAL_KMS_INFO: NULL REMAP_DB_LIST: NULL REMAP_TABLE_LIST: `TEST`.`STUDENT`:`TEST`.`STUDENT_RECOVER` REMAP_TABLEGROUP_LIST: NULL REMAP_TABLESPACE_LIST: NULL RESULT: SUCCEESS COMMENT: NULL DESCRIPTION: NULL
