RECOVER
Description
This statement is used to recover previously deleted databases, tables, or partitions.
It supports recovering specified metadata by name or ID and allows renaming the recovered metadata.
Syntax:
RECOVER { DATABASE <db_name> [<db_id>] [AS <new_db_name>]
| TABLE [<db_name>.]<table_name> [<table_id>] [AS <new_table_name>]
| PARTITION <partition_name> [<partition_id>] FROM [<db_name>.]<table_name> [AS <new_partition_name>] }
Required Parameters
Recover a database
1. <db_name>
The name of the database to recover.
Recover a table
1. <table_name>
The name of the table to recover.
Recover a partition
1. <partition_name>
The name of the partition to recover.
2. <table_name>
The name of the table where the partition resides.
Optional Parameters
Recover a database
1. <db_id>
The ID of the database to recover.
2. <new_db_name>
The new name of the recovered database.
Recover a table
1. <db_name>
The name of the database where the table resides.
2. <table_id>
The ID of the table to recover.
3. <new_table_name>
The new name of the recovered table.
Recover a partition
1. <partition_id>
The ID of the partition to recover.
2. <db_name>
The name of the database where the table resides.
3. <new_partition_name>
The new name of the recovered partition.
Access Control Requirements
| Privilege | Object | Note |
|---|---|---|
| ADMIN_PRIV |
Usage Notes
- This operation can only recover metadata deleted within a certain period. The default is 1 day (configurable via the
catalog_trash_expire_secondparameter infe.conf). - If no ID is specified when recovering metadata, the last deleted metadata with the same name is recovered by default.
- You can query the currently recoverable metadata using
SHOW CATALOG RECYCLE BIN.
Examples
-
Recover a database named
example_dbRECOVER DATABASE example_db; -
Recover a table named
example_tblRECOVER TABLE example_db.example_tbl; -
Recover a partition named
p1from the tableexample_tblRECOVER PARTITION p1 FROM example_tbl; -
Recover a database with ID
example_db_idand nameexample_dbRECOVER DATABASE example_db example_db_id; -
Recover a table with ID
example_tbl_idand nameexample_tblRECOVER TABLE example_db.example_tbl example_tbl_id; -
Recover a partition with ID
p1_idand namep1from the tableexample_tblRECOVER PARTITION p1 p1_id FROM example_tbl; -
Recover a database with ID
example_db_idand nameexample_db, and rename it tonew_example_dbRECOVER DATABASE example_db example_db_id AS new_example_db; -
Recover a table named
example_tbland rename it tonew_example_tblRECOVER TABLE example_db.example_tbl AS new_example_tbl; -
Recover a partition with ID
p1_idand namep1from the tableexample_tbl, and rename it tonew_p1RECOVER PARTITION p1 p1_id AS new_p1 FROM example_tbl;