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. Forgetting to unlock a tenant may result in the inability to establish new connections.
Lock a tenant
Log in to the
systenant of the cluster using therootuser.obclient -h172.30.xx.xx -P2883 -uroot@sys#cluster -p**** -AAccess the database named
oceanbase.USE oceanbase;Query the tenant information through the
DBA_OB_TENANTSview. For example, to query the locking status of themq_t1tenant: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. For example, to lock themq_t1tenant: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 check whether the tenant has been 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 in to the
systenant of the cluster using therootuser.obclient -h172.30.xx.xx -P2883 -uroot@sys#cluster -p**** -AAccess the database named
oceanbase.obclient [(none)]> USE oceanbase;Query the tenant information through the
DBA_OB_TENANTSview. For example, to query the locking status of themq_t1tenant: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. For example, to unlock themq_t1tenant: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 check whether the tenant has been successfully unlocked.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