This topic describes how to manage the recycle bin for tenants. This includes how to view objects in a recycle bin and how to enable, disable, and purge a recycle bin.
The sys tenant cannot be dropped. The recycle bin for tenants is managed by the sys tenant through the statements related to the recycle bin.
Only the tenant objects in the sys tenant can be placed in the recycle bin.
Considerations
The constraints on the tenants in the recycle bin are as follows:
The
DROP TENANTstatement converts a tenant name into a unified format within the recycle bin. The space occupied by the tenant is not released, but new connections to the tenant cannot be created.When executing
PURGE TENANT, you can use either the original tenant name or the tenant name in the recycle bin. UnlikeFLASHBACK, when purging a tenant with multiple identical original names,PURGE TENANTwill delete the one that entered the recycle bin first.For more information about flashing back objects in the recycle bin, see Flash back objects in the recycle bin.
The constraints on the primary/standby cluster are as follows:
In a standby cluster, automatic execution of operations such as
DROP TENANT,DROP TENANT FORCE,DROP TENANT PURGE,FLASHBACK TENANT, orPURGE TENANTis not allowed. All these operations must be synchronized from the primary cluster.The
PURGE RECYCLEBINoperation can be executed for a standby cluster. However, it will not delete tenants that belong to this cluster in the recycle bin.
View objects in the recycle bin
Execute the SHOW RECYCLEBIN statement in the sys tenant to view all objects in the recycle bin.
Background information
When the sys tenant executes the DROP TENANT statement on another tenant:
If the recycle bin is enabled, the tenant will be moved to the recycle bin and can be queried in the recycle bin.
If the recycle bin is disabled, the tenant will not be moved to the recycle bin and cannot be queried in the recycle bin.
Procedure
Log on to the
systenant as therootuser.Execute the following statement to view the objects in the recycle bin.
Example:
obclient> SHOW RECYCLEBIN; +--------------------------------+----------------+----------+----------------------------+ | OBJECT_NAME | ORIGINAL_NAME | TYPE | CREATETIME | +--------------------------------+----------------+----------+----------------------------+ | __recycle_$_1_1600136460199936 | wendo_table | TABLE | 2020-09-15 10:21:00.207886 | | __recycle_$_1_1600136479664128 | wendo_database | DATABASE | 2020-09-15 10:21:19.664534 | | __recycle_$_1_1600135793000960 | mysql | TENANT | 2020-09-15 10:23:25.773877 | +--------------------------------+----------------+----------+----------------------------+ 3 rows in setwhere:
OBJECT_NAMEindicates the name of the object in the recycle bin.ORIGINAL_NAMEindicates the original name of the object.TYPEindicates the type of the object in the recycle bin. Supported object types areINDEX,TABLE,DATABASE, andTENANT. In this example,mysqlis a tenant object in the recycle bin.CREATETIMEindicates the time when the object was placed in the recycle bin.
Enable or disable the recycle bin
The recycle bin is disabled for the sys tenant by default. If the recycle bin is enabled for the sys tenant, when you execute the DROP TENANT statement on a specific tenant, that tenant will be moved to the recycle bin.
The procedure for enabling or disabling the recycle bin is as follows:
Log on to the
systenant as therootuser.Execute the following statement to view the state of the recycle bin:
obclient> SHOW VARIABLES LIKE 'recyclebin'; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | recyclebin | OFF | +---------------+-------+ 1 row in setExecute the following statements to enable and disable the recycle bin feature.
The
recyclebinvariable is Boolean and can be set to one of the following values:on,1, ortrue: indicates that the recycle bin is enabled for the tenant.off,0, orfalse: indicates that the recycle bin is disabled for the tenant.
Syntax:
obclient> SET GLOBAL recyclebin = on; obclient> SET GLOBAL recyclebin = off;or
obclient> SET GLOBAL recyclebin = 1; obclient> SET GLOBAL recyclebin = 0;or
obclient> SET GLOBAL recyclebin = true; obclient> SET GLOBAL recyclebin = false;After the recycle bin is enabled or disabled, log on again and create a new session to make the setting take effect.
Purge the recycle bin
In the sys tenant, the PURGE statement can be used to purge the tenants or all objects in the recycle bin.
Log on to the
systenant as therootuser.Execute an appropriate statement as needed to purge the recycle bin.
Purge tenants from the recycle bin
obclient> PURGE TENANT tenant_name;where
tenant_namecan be set to the original tenant name or the tenant name in the recycle bin. If multiple tenants have the same original name, the first tenant that entered the recycle bin first will be deleted.If you purge a tenant from the recycle bin, all objects in the tenant will be purged.
Note
The objects discussed in this topic are tenants. For details about purging other types of objects from the recycle bin, see Recycle bin for databases, tables, and indexes.
Purge all objects from the recycle bin
obclient> PURGE RECYCLEBIN;
(Optional) Execute the following statement to check whether the objects that meet the specified conditions have been purged from the recycle bin:
obclient> SHOW RECYCLEBIN;