tencent cloud

TDSQL Boundless

Database Table Recycle Bin

PDF
Mode fokus
Ukuran font
Terakhir diperbarui: 2026-03-06 18:48:23

Overview

TDSQL Boundless recycle bin feature provides a data security safeguard mechanism. When a user accidentally deletes a table, they can quickly recover data through the recycle bin. The system uses a data dictionary table to store information about deleted database objects (including databases, tables, and so on), supporting data recovery operations.

How It Works

When the recycle bin feature is enabled, if a DROP TABLE operation is executed, the system automatically converts it to RENAME TABLE db.t TO __tdsql__recycle_bin__.<RECYCLED_TABLE> and moves the dropped table to __tdsql__recycle_bin__.
When a table is restored, perform the reverse operation by executing RENAME TABLE __tdsql__recycle_bin__.<RECYCLED_TABLE> TO db.t, and restore the dropped table to the original database.

Use Limits

Restoring the specified database to any point in time is not supported.
Database-level recycling and restoration is not supported.
The recycling and restoration of database triggers, functions, and stored procedures is not supported.
Restoring tables by regular users is not supported.
Recycling or restoring indexes separately is not supported.
The recycling and restoration of any subpartition (including first-level and second-level) of a partitioned table is not supported.
Temporary tables are not supported.
Flashback Query by specifying the original table name before the DROP operation is not supported.
The recycle bin feature cannot be enabled simultaneously with Log Service. The recycle bin feature converts DROP TABLE operations into RENAME TABLE operations, which are mutually exclusive with features that rely on binlog for data synchronization. Therefore, the recycle bin cannot be enabled in the following scenarios:
Instances with binlog enabled.
Primary instances that have been configured with disaster recovery instances.
Note:
To use the recycle bin feature, first ensure that the instance does not have Log Service (binlog) enabled and is not associated with disaster recovery instances. Forcibly enabling the feature may cause abnormal disaster recovery synchronization or data inconsistency.

Usage Instructions

When the recycle bin feature is enabled, tables deleted by users are placed in the recycle bin by default (meaning storage space is not released), unless manually purged (PURGE) by users or automatically removed by the database system periodically.

Enable the Recycle Bin Feature

Enable recycle bin:
tdsql> SET PERSIST tdsql_recycle_bin_enabled=1;
Disable recycle bin:
tdsql> SET PERSIST tdsql_recycle_bin_enabled=0;
Note:
The recycle bin feature is disabled by default. When the recycle bin feature is enabled, deleted tables automatically enter the recycle bin.
tdsql_recycle_bin_enabled is a global variable.

View Recycle Bin Table Information

tdsql>SHOW RECYCLEBIN;
Example output:
tdsql > SHOW RECYCLEBIN;
+-----------+---------------+--------------+--------------------------------+---------------------+---------------------+
| tindex_id | origin_schema | origin_table | recycle_table | drop_time | purge_time |
+-----------+---------------+--------------+--------------------------------+---------------------+---------------------+
| 53135 | sbtest | sbtest1_*** | bin$zxrh/bsnned9vygu4ioafg==$1 | 2026-01-14 16:19:54 | 2026-01-21 16:19:54 |
+-----------+---------------+--------------+--------------------------------+---------------------+---------------------+
1 row in set (0.01 sec)
Field description:
Parameter
Description
tindex_id
Table object ID.
origin_schema
Original database name.
origin_table
Original table name.
recycle_table
Table names in the recycle bin.
Description of naming rules: Since the recycle bin needs to centrally manage tables deleted from different databases, the system uses a specific encoding to ensure global uniqueness of table names. The encoding format is: bin$base64(md5(__ + tdsql_ + {db_name} + {table_name}))${version}, where ${version} is an incremental numeric tag used to distinguish multiple deletion records of the same table name.
drop_time
Deletion time.
purge_time
Automatic cleanup time (by default after 7 days).

Restore Table

Syntax:
FLASHBACK TABLE $recycle_table_name TO BEFORE DROP [RENAME TO $new_table_name];
Recover the table in the specified way. If another table shares the same name, an error will be reported.
Specify:
$recycle_table: the alias after the table enters the recycle bin.
$new_table_name: the new name assigned when the table is restored.
Note:
Permission requirements: You must have operational permissions for the original table, or administrator/superuser permissions.
Use Case:
-- Recover the table and rename it
tdsql> FLASHBACK TABLE `bin$zxrh/bsnned9vygu4ioafg==$1` TO BEFORE DROP RENAME TO sbtest11;

Delete Table Directly (Not Transfer to Recycle Bin)

DROP TABLE $NAME PURGE;

Clean Up Recycle Bin

Clean up specific table:
PURGE RECYCLEBIN $recyele_table_name;
Empty the entire recycle bin
PURGE RECYCLEBIN;

Relevant parameters

Parameter
Type
Default Value
Description
tdsql_recycle_bin_enabled
bool
0
Whether to enable the recycle bin.
0 (default value): disable.
1: enable
tdsql_recycle_bin_max_size
ulong
18446744073709551615
Limit on the maximum number of objects in the recycle bin.
tdsql_recycle_bin_drop_if_exceed_limit
ulong
1
Whether to DROP the table when the limit is exceeded.
0: No.
1 (default value): Yes.
tdsql_recycle_bin_retention
ulong
604800
Retention period for objects in the recycle bin (in seconds). The default is 7 days. Tables exceeding this period will be automatically cleaned up.

Bantuan dan Dukungan

Apakah halaman ini membantu?

masukan