OceanBase Database supports locking tenants. When a tenant is locked, new connections cannot be created on that tenant, but existing connections remain unchanged. This topic describes how to lock and unlock a tenant.
Background information
Tenants can be locked and unlocked using the ALTER TENANT statement. It is applicable in emergency handling scenarios and operational change scenarios.
Emergency handling scenarios: If a tenant is experiencing issues and being recovered, you can lock the tenant to prevent business traffic from affecting the recovery process, with the consent of the customer. After locking the tenant, you must kill the corresponding sessions.
Operational change scenarios: For example, if a tenant needs to be taken offline, the offline process must follow principles such as gray-scale release and rollback. Locking the tenant can be one of the steps 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
systenant of the cluster as therootuser.obclient -h172.30.xx.xx -P2883 -uroot@sys#cluster -p**** -AAccess the database named
oceanbase.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 oceanbase.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 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
systenant of the cluster as therootuser.obclient -h172.30.xx.xx -P2883 -uroot@sys#cluster -p**** -AAccess 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 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 oceanbase.DBA_OB_TENANTS WHERE TENANT_NAME = 'mq_t1'; +-----------+-------------+--------+ | TENANT_ID | TENANT_NAME | LOCKED | +-----------+-------------+--------+ | 1036 | mq_t1 | NO | +-----------+-------------+--------+ 1 row in set