OceanBase AI Database supports locking tenants. After a tenant is locked, new connections cannot be created to the tenant, but existing connections remain unchanged. This topic describes how to lock and unlock a tenant.
Background information
You can lock and unlock a tenant by using the ALTER TENANT statement. This applies to fault emergency scenarios and O&M change scenarios:
Fault emergency: If a tenant is abnormal and being repaired, you can lock the tenant to prevent business traffic from affecting the repair process. You must obtain the consent of the business party before performing this operation. If you lock the tenant in an emergency scenario, you must proactively kill the sessions after locking the tenant.
O&M change: For example, when a tenant needs to be taken offline, the offline process must follow principles such as canary release and rollback. Locking the tenant can be one of the steps to observe the impact on the business system.
Notice
Locking and unlocking must be performed in pairs. If you forget to unlock a tenant, new connections cannot be established.
Lock a tenant
Log in 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 lock 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 in 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 lock 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 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