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_second
parameter 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_db
RECOVER DATABASE example_db;
-
Recover a table named
example_tbl
RECOVER TABLE example_db.example_tbl;
-
Recover a partition named
p1
from the tableexample_tbl
RECOVER PARTITION p1 FROM example_tbl;
-
Recover a database with ID
example_db_id
and nameexample_db
RECOVER DATABASE example_db example_db_id;
-
Recover a table with ID
example_tbl_id
and nameexample_tbl
RECOVER TABLE example_db.example_tbl example_tbl_id;
-
Recover a partition with ID
p1_id
and namep1
from the tableexample_tbl
RECOVER PARTITION p1 p1_id FROM example_tbl;
-
Recover a database with ID
example_db_id
and nameexample_db
, and rename it tonew_example_db
RECOVER DATABASE example_db example_db_id AS new_example_db;
-
Recover a table named
example_tbl
and rename it tonew_example_tbl
RECOVER TABLE example_db.example_tbl AS new_example_tbl;
-
Recover a partition with ID
p1_id
and namep1
from the tableexample_tbl
, and rename it tonew_p1
RECOVER PARTITION p1 p1_id AS new_p1 FROM example_tbl;