OceanBase Database allows you to lock a tenant. New connections cannot be created on a locked tenant, but existing connections are not affected. This topic describes how to lock and unlock a tenant.
Background
You can execute the ALTER TENANT statement to lock or unlock a tenant for emergency responses to exceptions or for O&M changes.
Emergency responses to exceptions: If a tenant is recovering from an exception, you can lock this tenant to prevent business traffic from affecting the recovery procedure with the consent of the customer. If you lock a tenant as an emergency action, you must kill the session after you lock the tenant.
O&M changes: If a tenant must be removed, make sure that phased removal and data rollback are supported. In this case, you can lock the tenant to observe the impact on the business system.
Notice
Locking and unlocking operations must be performed in pairs. If you forget to unlock a tenant, new connections cannot be established.
Lock a tenant
Log on to the sys tenant of the cluster as the root user.
obclient -h172.30.xx.xx -P2883 -uroot@sys#cluster -p**** -AExecute the following statement to go to the database named
oceanbase:obclient [(none)]> USE oceanbase;Query the
DBA_OB_TENANTSview for information about a tenant.To query the locking status of the
mq_t1tenant, execute the following statement:obclient [oceanbase]> SELECT TENANT_ID,TENANT_NAME,LOCKED FROM DBA_OB_TENANTS WHERE TENANT_NAME = 'mq_t1'; +-----------+-------------+--------+ | TENANT_ID | TENANT_NAME | LOCKED | +-----------+-------------+--------+ | 1036 | mq_t1 | NO | +-----------+-------------+--------+ 1 row in setFor more information about the
DBA_OB_TENANTSview, see oceanbase.DBA_OB_TENANTS.Execute the
ALTER TENANTstatement to lock the tenant.To lock the
mq_t1tenant, execute the following statement.obclient [oceanbase]> ALTER TENANT mq_t1 LOCK; Query OK, 0 rows affectedFor more information about the
ALTER TENANTstatement, see ALTER TENANT.Query the
DBA_OB_TENANTSview to verify whether the tenant is successfully locked.obclient [oceanbase]> SELECT TENANT_ID,TENANT_NAME,LOCKED FROM DBA_OB_TENANTS WHERE TENANT_NAME = 'mq_t1'; +-----------+-------------+--------+ | TENANT_ID | TENANT_NAME | LOCKED | +-----------+-------------+--------+ | 1036 | mq_t1 | YES | +-----------+-------------+--------+ 1 row in set
Unlock a tenant
Log on to the sys tenant of the cluster as the root user.
obclient -h172.30.xx.xx -P2883 -uroot@sys#cluster -p**** -AExecute the following statement to go to the database named
oceanbase:obclient [(none)]> USE oceanbase;Query the
DBA_OB_TENANTSview for information about a tenant.To query the locking status of the
mq_t1tenant, execute the following statement:obclient [oceanbase]> SELECT TENANT_ID,TENANT_NAME,LOCKED FROM DBA_OB_TENANTS WHERE TENANT_NAME = 'mq_t1'; +-----------+-------------+--------+ | TENANT_ID | TENANT_NAME | LOCKED | +-----------+-------------+--------+ | 1036 | mq_t1 | YES | +-----------+-------------+--------+ 1 row in setFor more information about the
DBA_OB_TENANTSview, see oceanbase.DBA_OB_TENANTS.Execute the
ALTER TENANTstatement to unlock the tenant.To unlock the
mq_t1tenant, execute the following statement:obclient [oceanbase]> ALTER TENANT mq_t1 UNLOCK; Query OK, 0 rows affectedFor more information about the
ALTER TENANTstatement, see ALTER TENANT.Query the
DBA_OB_TENANTSview to verify whether the tenant is successfully locked.obclient [oceanbase]> SELECT TENANT_ID,TENANT_NAME,LOCKED FROM DBA_OB_TENANTS WHERE TENANT_NAME = 'mq_t1'; +-----------+-------------+--------+ | TENANT_ID | TENANT_NAME | LOCKED | +-----------+-------------+--------+ | 1036 | mq_t1 | NO | +-----------+-------------+--------+ 1 row in set