This topic describes how to delete a tenant replica from a zone. After a replica is deleted, its data cannot be restored. Proceed with caution.
Prerequisites
Before you alter replicas by deleting some of them, make sure that the target replicas are normal. To change the number of replicas from 5 to 4, make sure that the four OBServer nodes where the target replicas reside are all online.
Notice
Assume that the SYS tenant of an OceanBase cluster has five zones, with one replica distributed on each of them. If two of the zones are malfunctioning, do not delete any of the replicas. Even if you delete only one replica, the remaining replicas cannot form a majority. However, you can delete the two replicas in the malfunctioning zones at a time.
You can use the following SQL syntaxes to delete replicas:
-- Modify the locality to delete a replica from a zone.
ALTER TENANT tenant_name [SET] LOCALITY [=] 'locality_description';
-- Cancel the reference relationship between a tenant and a resource pool.
ALTER TENANT tenant_name [SET] RESOURCE_POOL_LIST [=](pool_name [, pool_name...]) ;
-- Drop a resource pool.
DROP RESOURCE POOL pool_name;
-- Drop a resource unit.
DROP RESOURCE UNIT unit_name;
Note
Based on the locality change rule, you can delete the locality of only one zone at a time.
This statement can delete only one resource pool specified by
RESOURCE_POOL_LISTat a time.
Examples
Assume that the tenant1 tenant has one replica in each zone from zone1 to zone5, and you need to delete replicas in zone4 and zone5. You can execute the following SQL statement to delete the replicas by modifying the locality of tenant1:
-- Modify the locality to delete replicas in zone4 and zone5.
obclient> ALTER TENANT tenant1 LOCALITY = 'F@zone1,F@zone2,F@zone3,F@zone4';
obclient> ALTER TENANT tenant1 LOCALITY = 'F@zone1,F@zone2,F@zone3';
-- Cancel the reference relationship between a tenant and a resource pool.
obclient> ALTER TENANT tenant1 RESOURCE_POOL_LIST = ('pool1','pool2','pool3','pool4');
obclient> ALTER TENANT tenant1 RESOURCE_POOL_LIST = ('pool1','pool2','pool3');
-- Drop a resource pool.
obclient> DROP RESOURCE POOL pool4;
obclient> DROP RESOURCE POOL pool5;
-- Drop a resource unit.
obclient> DROP RESOURCE UNIT unit4;
obclient> DROP RESOURCE UNIT unit5;