Database/Table Recycle Bin
Introduction
DDL operations cannot be rolled back. If you delete a table or database by mistake, data may be lost. TaurusDB supports database/table recycle bin. After a table or database is deleted, it is temporarily moved to the __recyclebin__ database with a new name. You can adjust how long a deleted table or database stays in the recycle bin. You can also restore or permanently delete a table or database from the recycle bin at any time.
Tables and databases in the recycle bin occupy the storage space of the instance until the system automatically clears them. If you want to release the storage space, manually clear the tables and databases from the recycle bin.
Prerequisites
- Supported versions
Database/table recycle bin is only available for specific versions. For details about how to check the kernel version, see How Can I Check the Version of a TaurusDB Instance?
- If the kernel version is 2.0.57.240900 or later, database/table recycle bin is supported for DROP TABLE statements.
- If the kernel version is 2.0.63.250300 or later, database/table recycle bin is supported for DROP TABLE, DROP DATABASE, and TRUNCATE TABLE statements.
- Permissions control
Deleted tables are moved to database __recyclebin__ in the recycle bin. To view, restore, or clear those tables, you need to run commands provided by the recycle bin and have the following permissions:
- To view details about tables in the recycle bin, you must have the SELECT permission on the tables in __recyclebin__.
- To clear specified tables in the recycle bin, you must have the DROP permission on the tables in __recyclebin__.
- To restore specified tables in the recycle bin, you must have the ALTER and DROP permissions on the tables in __recyclebin__, and CREATE and INSERT permissions on the destination tables.
Principles
Constraints
- If there is a database named __recyclebin__ in your instance, the pre-upgrade check may fail when you upgrade your instance to 2.0.57.240900 or later. To upgrade your instance, delete the __recyclebin__ database first. If you want to retain the __recyclebin__ database for regular use, submit a service ticket.
- If tables specified in a DROP TABLE statement are not supported by the recycle bin, they will be directly deleted.
- If recycle bin is enabled for an instance and a table that has constraints with the same name is temporarily deleted, the table may fail to be moved to the recycle bin because database __recyclebin__ also has constraints with the same name. If the table fails to be moved to the recycle bin, check whether the deleted table has such constraints. If yes, delete the constraints and execute the DROP TABLE statement again to delete the table.
- Enabling recycle bin increases memory consumption for executing a DROP TABLE, DROP DATABASE, or TRUNCATE TABLE statement. The memory consumption is basically the same as that for renaming multiple tables using a single RENAME TABLE statement. If a single statement is used to delete too many tables, OOM may occur. If you need to delete a large number of tables with a single statement but are worried about OOM issues, you can disable database/table recycle bin by resetting the rds_recycle_bin_mode parameter at the session level.
- Table recycle bin is only available for regular InnoDB tables. It is unavailable for tables in shared tablespaces, tables with full-text indexes, temporary tables, non-InnoDB tables, tables with secondary engines, system catalogs, or hidden tables.
- Database/table recycle bin is unavailable for common tenants of instances with multi-tenancy enabled.
- After tables in the recycle bin are archived using cold and hot data separation, the archived tables cannot be cleared or restored using recycle bin commands.
- In some backup and restoration scenarios, such as table-level PITR, tables in the recycle bin are not restored.
- DRS does not support recycle bin. If replication is interrupted because recycle bin is enabled, reset the task or submit a service ticket.
- DRS does not synchronize session-level recycle bin switches of a single DROP TABLE statement. Instead, it determines whether the DROP TABLE statement temporarily stores tables to the recycle bin on the destination instance based on the global-level recycle bin parameters of the destination instance.
- DRS does not synchronize the restore_table, restore_db, purge_table, and automatic backend cleanup operations of the recycle bin on the source instance.
If you execute restore_table or restore_db on the source instance, tables will not be restored on the destination instance. If you write data into a restored table on the source instance, the replication will be interrupted. You are advised to use INSERT INTO ... SELECT ... to restore tables when there is a replication task.
- If the kernel version of the source instance is earlier than 2.0.63.250300, after tables in its recycle bin are migrated to the destination instance using DRS, the restore and show commands cannot be executed on the tables, and the backend cleanup thread will not automatically clear the tables. To clear the tables, manually run the purge_table command.
- Table recycle bin in version 2.0.57.240900 supports only tables with names composed of ASCII characters, such as English letters, numbers, and common punctuation marks. Other table name character types, such as Latin letters, Greek letters, and Chinese characters, will be supported in version 2.0.60.241200.
If you try to recycle or restore tables whose names contain unsupported character types in version 2.0.57.240900, the connection may hang. In such cases, reboot the instance or perform a primary/standby switchover. Once the instance is recovered, disable the recycle bin and delete the tables.
- Instances whose kernel version is 2.0.63.xxxxxx support recycle bin. Some third-party binlog collection tools may be incompatible. You are advised to assess whether to upgrade the kernel version based on your specific service requirements. For details about how to upgrade the kernel version, see Upgrading the Minor Version of a DB Instance.
Enabling Database/Table Recycle Bin
You can set the rds_recycle_bin_mode parameter to enable or disable database/table recycle bin. After this function is enabled, data is recycled according to the recycling mechanism.
You can enable database/table recycle bin in either of the following ways:
- Click the TaurusDB instance name. Choose Parameters in the navigation pane and reset the rds_recycle_bin_mode parameter.
- Run the following command in a session:
Parameter |
Level |
Description |
---|---|---|
rds_recycle_bin_mode |
Global, Session |
Controls whether to enable recycle bin. Value:
|
rds_recycle_scheduler |
Global |
Controls whether the backend automatically clears expired tables from the recycle bin. Value:
|
rds_recycle_bin_retention |
Global |
Controls how many seconds tables in the recycle bin are stored for. Default value: 259200 (three days); value range: 0 to 2592000. After the rds_recycle_bin_retention parameter is modified, the recycle bin recalculates the estimated time for automatically clearing all tables in the recycle bin based on the time they were first placed in the recycle bin. If rds_recycle_scheduler is set to ON, and the retention period of tables in the recycle bin exceeds the parameter value, the tables will be automatically deleted and cannot be restored. |
rds_recycle_bin_binlog_mode |
Global, Session |
Controls how DDL statements related to the recycle bin are recorded in binlogs. The TRANSLATE option has been deprecated since kernel version 2.0.63.250300. Statements are directly recorded. Value:
|
Managing Database/Table Recycle Bin
Function |
How to Use |
Example |
---|---|---|
Viewing tables in the recycle bin |
You can run the show command to view table details in the recycle bin such as the current and original database and table names, as well as the time when a table was moved to the recycle bin and when it will be automatically cleared. |
|
Restoring a table in the recycle bin to the original table in the original database |
You can run the restore command to restore a table from the recycle bin to the original table in the original database or a specified table in a specified database. After the restoration is successful, the table in the recycle bin is deleted and cannot be restored again. |
|
Restoring all tables with the original database specified from the recycle bin |
You can run the restore db command to restore a table from the recycle bin to the original database or a specified database. After the restoration is successful, the table in the recycle bin is deleted and cannot be restored again. |
|
Automatic backend cleanup |
You can enable automatic backend cleanup in the following way: Click the TaurusDB instance name. Choose Parameters in the navigation pane and change the value of rds_recycle_scheduler to ON. |
- |
Clearing specified tables |
You can run the purge command to clear a table in the recycle bin. After the command is executed, the table is permanently deleted and cannot be restored. |
Examples
Table recycle bin provides the following commands to allow you to operate tables temporarily stored in the recycle bin.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot