Skip to main content
Skip to main content

RECOVER

RECOVER​

Name​

RECOVER

Description​

This statement is used to restore a previously deleted database, table or partition. It supports recover meta information by name or id, and you can set new name for recovered meta information.

You can get all meta informations that can be recovered by statement SHOW CATALOG RECYCLE BIN.

grammar:

  1. restore database by name

    RECOVER DATABASE db_name;
  2. restore table by name

    RECOVER TABLE [db_name.]table_name;
  3. restore partition by name

    RECOVER PARTITION partition_name FROM [db_name.]table_name;
  4. restore database by name and id

    RECOVER DATABASE db_name db_id;
  5. restore table by name and id

    RECOVER TABLE [db_name.]table_name table_id;
  6. restore partition by name and id

    RECOVER PARTITION partition_name partition_id FROM [db_name.]table_name;
  7. restore database by name, and set new db name

    RECOVER DATABASE db_name AS new_db_name;
  8. restore table by name and id, and set new table name

    RECOVER TABLE [db_name.]table_name table_id AS new_db_name;
  9. restore partition by name and id, and set new partition name

    RECOVER PARTITION partition_name partition_id AS new_db_name FROM [db_name.]table_name;

illustrate:

  • This operation can only restore meta information that was deleted in the previous period. Default is 1 day. (Configurable through the catalog_trash_expire_second parameter in fe.conf)
  • If you recover a meta information by name without id, it will recover the last dropped one which has same name.
  • You can get all meta informations that can be recovered by statement SHOW CATALOG RECYCLE BIN.

Example​

  1. Restore the database named example_db
RECOVER DATABASE example_db;
  1. Restore the table named example_tbl
RECOVER TABLE example_db.example_tbl;
  1. Restore the partition named p1 in table example_tbl
RECOVER PARTITION p1 FROM example_tbl;
  1. Restore the database named example_db with id example_db_id
RECOVER DATABASE example_db example_db_id;
  1. Restore the table named example_tbl with id example_tbl_id
RECOVER TABLE example_db.example_tbl example_tbl_id;
  1. Restore the partition named p1 with id p1_id in table example_tbl
RECOVER PARTITION p1 p1_id FROM example_tbl;
  1. Restore the database named example_db with id example_db_id, and set new name new_example_db
RECOVER DATABASE example_db example_db_id AS new_example_db;
  1. Restore the table named example_tbl, and set new name new_example_tbl
RECOVER TABLE example_db.example_tbl AS new_example_tbl;
  1. Restore the partition named p1 with id p1_id in table example_tbl, and new name new_p1
RECOVER PARTITION p1 p1_id AS new_p1 FROM example_tbl;

Keywords​

 RECOVER

Best Practice​