Purpose
The ALTER SYSTEM RECOVER TABLE statement is used to recover table data. Specifically, it restores a user-specified table from backup data into 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, indexes, and other objects cannot be recovered separately.
When recovering a table, foreign keys, triggers, and statistics on the table cannot be recovered.
When recovering a table, the compatibility of the source tenant and the destination tenant must be consistent. 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 lower-version backup data to the same version or a higher version. It also 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 table name stored 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.The
ALTER SYSTEM RECOVER TABLEstatement requires the use of an auxiliary tenant. Therefore, 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. The format is database_name.table_name1,database_name.table_name2,.... The names of multiple tables are separated with commas (,).
|
| dest_tenant_name | The name of the target tenant for table-level restore. In the current version, only user tenants can be specified. |
| uri | The path for data backup and log archiving. If the data backup is initiated by using the PLUS ARCHIVELOG option, you only need to specify one path. Otherwise, you need to separately specify the paths for data backup and log archiving (at least two paths), for example, 'file:///backup/archive, file:///backup/data'. For more information about data backup methods, see the BACKUP command. |
| UNTIL | The endpoint of the restore, which specifies that the restore will be performed up to and including this endpoint. When you specify the endpoint as a time or SCN, you must use = to connect to the specified value. If you do not specify the UNTIL clause, the restore will be performed up to the latest endpoint.
|
| restore_option | The pool_list, locality, primary_zone, and concurrency parameters of the auxiliary tenant, which are separated by &:
|
| WITH KEY FROM 'backup_key_path' ENCRYPTED BY 'password' | The information about the key backup of the encrypted tenant. This is an optional parameter. You need to specify the key backup information only when the source tenant is configured with transparent encryption. The parameters are described as follows:
|
| REMAP | The mapping relationship. If you do not specify REMAP, the system will attempt to restore the table to the same TableSpace->Table Group->Database as the original table. |
| remap_table_name_list | The new name of the restored table. You can rename the table without changing the database it belongs to; you can also keep the table name and rename it to another database; or you can rename the table and the database it belongs to another database. The source object and the renamed object are connected with a colon (:) in the statement. |
| 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 restore 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 the target tenant has other table groups, you can use this statement to restore the table to other table groups. The source object and the renamed object are connected with a colon (:) in the statement. |
| remap_tablespace_list | The new name of the table space to which the table belongs. In OceanBase Database, a table space is a logical unit, mainly used for data encryption. If the source table is bound to a table space, the system will restore the table to the same-named table space in the target tenant. If the same-named table space does not exist, the table restore will fail. If the target tenant has other table spaces, you can use this statement to restore the table to other table spaces. The source object and the renamed object are connected with a colon (:) in the statement. |
| description | The description of the operation. This is an optional parameter. |
Examples
In the test database of the MySQL-compatible mode tenant obt, the data backup path is set to 'file:///data/backup/data', and the log archive 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 demonstrates how to restore the test.student table of a tenant to the time point '2023-08-21 19:47:20' using the table-level restore feature and rename it to student_recover.
Create the resources required for the table-level restore process in the auxiliary tenant under the
systenant. In this example, a resource pool with the4c4gspecification is created.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 of 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 uses the Resource Poolrecover_tmp_pooland the Primary Zone isz1.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 restore command is executed successfully, you can view the restore progress in the
CDB_OB_RECOVER_TABLE_JOBSview. TheSTATUScolumn indicates the restore 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