This topic describes how to perform a table-level restore.
Table restore methods
There are two methods for the physical restore auxiliary tenant phase of table restore: full restore and quick restore.
The table restore process consists of three phases: physical restore auxiliary tenant, cross-tenant table import, and cleanup auxiliary tenant. In previous versions, the full restore method was used in the physical restore auxiliary tenant phase. This method requires restoring all data from the source tenant to the auxiliary tenant from backup media, which leads to the following two issues:
- You must reserve sufficient CPU, memory, and disk resources on the cluster to support the temporary restoration of the auxiliary tenant.
- Restoring all data from backup media to the auxiliary tenant consumes a significant amount of time and network bandwidth.
To address these issues, OceanBase Database supports restoring auxiliary tenants using the quick restore method. When restoring an auxiliary tenant using this method, only a read-only auxiliary tenant needs to be restored. User data within the tenant does not need to be restored from backup media; instead, during the cross-tenant table import phase, the backup macroblock data for the tables to be restored can be directly read from backup media. This method reduces resource usage for restoring the temporary auxiliary tenant during table restore and shortens the time overhead of the restore task.
Notice
In the current version, if the data version number of the backup set used for restore is V4.3.5.0 or later, the system automatically uses the quick restore method to perform the restoration of the auxiliary tenant during table restore. If the data version number of the backup set used for restore is earlier than V4.3.5.0, the full restore method is still used to restore the auxiliary tenant. You can confirm the data version number of the backup set used for restore by querying the TENANT_COMPATIBLE column in the CDB_OB_BACKUP_SET_FILES (sys tenant) or DBA_OB_BACKUP_SET_FILES (user tenant) view.
After performing table restore, you can query the RESTORE_TYPE column in the CDB_OB_RESTORE_HISTORY view in the sys tenant to confirm the restore method used for the auxiliary tenant.
Limitations and considerations
Only user tables can be restored. Temporary tables, views, materialized views, materialized view logs, indexes, etc., cannot be restored separately.
When restoring tables, tables with full-text indexes, JSON multi-valued indexes, or vector indexes are supported.
Tables in columnar and hybrid row-column formats are supported.
The source tenant and target tenant for table restore must have the same compatibility level. For example, both must be Oracle-compatible tenants or both must be MySQL-compatible tenants.
When restoring tables, 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, but the actual stored table name in the system isTEST, then the table nameTESTmust be specified when restoring the table. Otherwise, the system will report an error indicating the table does not exist.Similar to backup data versions supported for tenant-level restore, table-level restore currently only supports restoring tables from lower-version backup data to the same or higher version. Reverse restore between minor versions within the same version is also not supported. For detailed information about backup data versions supported for tenant-level restore, see Prepare for restore.
In addition to restoring the table, table-level restore also restores much information associated with that table, but some information is not restored. For specific information that can be restored, see Schema restore description for table-level restore.
Prerequisites
Since an auxiliary tenant is required during the restore process for a specified table, you must create the required resource pool for the auxiliary tenant in the cluster where the target tenant resides before performing table restore. For detailed operations on creating the required resource pool for the auxiliary tenant, see Prepare for table restore.
Procedure
Log in to the
systenant of the cluster where the target tenant is located as therootuser.(Optional) If encryption was configured for the backup data used to restore the specified table, you need to configure the encryption information for the backup set.
The restore password for the backup is required only if a password was added during data backup.
SET DECRYPTION IDENTIFIED BY 'password';Here,
passwordneeds to be replaced with the password added during backup. If the passwords set for full backup and incremental backup are different, you need to enter multiple passwords, separated by commas (the full backup password comes first, followed by the incremental backup passwords).An example where the passwords for full backup and incremental backup are the same is as follows:
SET DECRYPTION IDENTIFIED BY '******';An example where the passwords for full backup and incremental backup are different is as follows:
SET DECRYPTION IDENTIFIED BY '******','******';(Optional) Set the table-level restore parallelism.
Single-table parallel restore
Before performing table-level restore, you can set the concurrency through the parameter recover_table_dop. After setting it, the system will use this parallelism in the following two phases:
- Primary table data restore phase: The system splits each partition of the primary table into multiple subtasks for parallel execution.
- Index restore phase: Based on the restored primary table data, the system rebuilds the table's index using parallel execution (PX).
The syntax is as follows:
-- tenant_name is the target tenant. ALTER SYSTEM SET recover_table_dop=INT_VALUE tenant=tenant_name;Multi-table parallel restore (Optional)
Before performing multi-table level restore, you can set the concurrency through the parameter recover_table_concurrency. After setting it, multiple tables can execute restore tasks in parallel, improving restore performance.
The syntax is as follows:
-- tenant_name is the target tenant. ALTER SYSTEM SET recover_table_concurrency=INT_VALUE tenant=tenant_name;Set the number of worker threads for restoring primary table data per observer node in a tenant
After setting the single-table parallelism
recover_table_dopand multi-table parallelismrecover_table_concurrency, you also need to set the number of worker threads for data restoration per observer node in a tenant through the ddl_thread_score parameter. During the cross-tenant table import phase of table-level restore, the restoration of primary table data depends on specific DAG threads on the target tenant.The syntax is as follows:
-- tenant_name is the target tenant. ALTER SYSTEM SET ddl_thread_score=INT_VALUE tenant=tenant_name;Notice
- During the physical restore of the auxiliary tenant phase, you can dynamically adjust the restore concurrency by modifying the ha_high_thread_score parameter. The change takes effect immediately. You can view the name of the auxiliary tenant in the CDB_OB_RECOVER_TABLE_JOBS table. For more information, see Physical restore.
- During the cross-tenant table import phase, you can dynamically adjust the restore concurrency for multiple tables or a single table by modifying the
recover_table_concurrencyorrecover_table_dopparameter of the target tenant. The change takes effect immediately.
Run the following command to restore the specified table.
The SQL statement is as follows:
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];The parameters are described as follows:
table_name_list: The tables to be restored, in the formatdatabase_name.table_name1,database_name.table_name2,.... Separate multiple tables with commas (,).When specifying
database_nameandtable_name:table_namemust match the actual table name stored in the system. For example, if you create a table namedtestin an Oracle-compatible tenant, but the system actually stores it asTEST, you must specifyTESTwhen restoring the table. Otherwise, the system reports an error indicating the table does not exist.If
database_nameortable_namecontains special characters, enclose it in backticks (`).To restore all tables under a database, use
database_name.*.To restore all user tables under a tenant, use
*.*.
dest_tenant_name: The target tenant where the tables are to be restored. Tables can only be restored to a user tenant; restoration to thesysor Meta tenant is not supported.uri: Specifies the paths for data backup and log archiving, similar to the parameters in a tenant-level physical restore command. If data backup was initiated via the PLUS ARCHIVELOG method, only one path is required. Otherwise, enter at least two paths for data backup and log archiving, for example:'file:///backup/archive, file:///backup/data'.{TIME='timestamp'} \| {SCN=scn}: The specified restore endpoint. Restores to this point in time, including it. When specifying to restore toTIMEorSCN, you must use=to connect the specified values. If theUNTILclause is not specified, the latest point in time is restored by default.restore_option: Specifies thepool_list,locality,primary_zone, andconcurrencyfor the auxiliary tenant. Separate different parameters with&. When specifyinglocalityandprimary_zone, it is recommended to keep them as homogeneous as possible with the source tenant.For
concurrency, if not specified, it defaults to the MAX_CPU allocated to the auxiliary tenant. For example, in this document, the system tenant allocates a MAX_CPU of 16 to the auxiliary tenant.For detailed descriptions of each parameter, see Table-level restore parameters.
WITH KEY FROM 'backup_key_path' ENCRYPTED BY 'password': Specifies the key backup information for encrypted tenants. Specify the key backup information during restore only if transparent encryption is configured in the source tenant.backup_key_path: The backup path of the key.password: The encryption password set when backing up the key.
For operations related to key backup, see Back up the key in Preparations before backup.
remap_table_name_list: Renames the restored tables. You can rename only the table name while keeping the database unchanged; rename only the database while keeping the table name unchanged; or rename both the table name and its database to another database. Separate the source object from the renamed object with a colon (:). Example formats:Rename the table
studenttostudent2, and keep the database unchanged:REMAP TABLE school.student:student2.When the database remains unchanged, when restoring a table to the target tenant, the system will by default restore the table to a database with the same name in the target tenant. If a database with the same name does not exist, the table restoration will fail.
Keep the table name unchanged, and change the database from
schooltocollege:REMAP TABLE school.student:college.student.Rename the table
studenttostudent2, and change the database fromschooltocollege:REMAP TABLE school.student:college.student2.Restore all tables under
schooltocollege:<code>REMAP TABLE school.:college.</code>
Note
If the renamed
database_nameortable_namecontains special characters, thedatabase_nameortable_namewith special characters must be enclosed in backticks (``).remap_tablegroup_list: Renames the table group to which a table belongs. If the source table is bound to a table group, when restoring it to the target tenant to create a table, the system will by default restore the table to a table group with the same name in the target tenant. If a table group with the same name does not exist, the table restoration will fail. If there are other table groups in the target tenant, you can use this statement to restore the table to another table group. The source object and the renamed object are separated by a colon (:).For example, restore all tables from the source table group
tg1to the target tenant's table groupnewtg1:REMAP TABLEGROUP tg1:newtg1.remap_tablespace_list: Renames the tablespace to which a table belongs. A tablespace is a logical unit in OceanBase Database, currently mainly used for data encryption. If the source table is bound to a tablespace, when restoring it to the target tenant to create a table, the system will by default restore the table to a tablespace with the same name in the target tenant. If a tablespace with the same name does not exist, the table restoration will fail. If there are other tablespaces in the target tenant, you can also use this statement to restore the table to another tablespace. The source object and the renamed object are separated by a colon (:).For example, restore all tables from the source tablespace
ts1to the target tenant's tablespacenewts1:REMAP TABLESPACE ts1:newts1.
For more detailed information about table restore parameters, see Table restore parameters.
Restore tables
tbl1andtbl2from theinfodbdatabase to theinfodbdatabase of the target tenant. Rename tabletbl1tonewtbl, redirect its table group tonewtg1, and redirect its tablespace tonewts1. Example:ALTER SYSTEM RECOVER TABLE infodb.tbl1,infodb.tbl2 TO TENANT oracle001 FROM 'file:///data/nfs/backup/data,file:///data/nfs/backup/archive' UNTIL TIME='2023-09-30 00:00:00' WITH 'pool_list=restore_pool' REMAP TABLE infodb.tbl1:newtbl REMAP TABLEGROUP tg1:newtg1 REMAP TABLESPACE ts1:newts1;
Notice
- The successful restoration of table data indicates a successful table restore. Indexes, constraints, or other associated schemas may fail to restore.
- After table-level restore is complete, it is recommended to restore the settings of the
ddl_thread_score,recover_table_concurrency, andrecover_table_dopparameters. If not restored, subsequent table-level restores will be executed according to the set parallel parameters. - The restoration of triggers associated with tables during table-level restore will follow this pattern:
- If the table name is not renamed (REMAP TABLE mapping) in the command initiating the table-level restore, meaning the table is restored by its original name, then the triggers associated with the table need to be restored.
- If the table name is renamed (REMAP TABLE mapping) in the command initiating the table-level restore, meaning the table is restored by its new name, then the triggers associated with the table will not be restored.
What to do next
After initiating the restore of a specified table, you can view the progress and results of the table restore through views. For more information, see View the progress of a table-level restore and View the results of a table-level restore.
After the restore of a specified table is complete, you must also execute the following command in the cluster where the auxiliary tenant resides to manually release the resource pool created for the auxiliary tenant.
DROP RESOURCE POOL restore_pool;Here,
restore_poolis the name of the resource pool created for the auxiliary tenant during preparation before the restore.For detailed operations and information on deleting a resource pool, see Delete a resource pool.
References
For information about the recovery status of schema information during table-level restore, see Schema recovery description for table-level restore.
