To balance the resource distribution among multiple OBServer nodes in a zone, you can adjust the resource distribution among tenants to balance the resource usage in the cluster.
This topic describes how to use SQL statements to migrate resource units.
Applicability
The ALTER SYSTEM MIGRATE UNIT statement can be executed only in the sys tenant.
Syntax
ALTER SYSTEM MIGRATE UNIT [=] unit_id
DESTINATION [=] ip_port;
The following table describes the parameters.
| Parameter | Description |
|---|---|
| unit_id | The ID of the resource unit. |
| ip_port | The address of the target server to which the resource unit is to be migrated. |
Examples
Query resource unit distribution.
Execute the following statement to query the distribution of resource units of the
mysql001tenant in each zone:SELECT t.TENANT_NAME,u.ZONE,u.UNIT_ID,u.SVR_IP FROM oceanbase.DBA_OB_TENANTS t,oceanbase.DBA_OB_UNITS u WHERE t.TENANT_ID=u.TENANT_ID AND t.TENANT_NAME='mysql001';The return result is as follows:
+-------------+-------+---------+------------+ | TENANT_NAME | ZONE | UNIT_ID | SVR_IP | +-------------+-------+---------+------------+ | mysql001 | zone1 | 1002 | 10.10.10.1 | | mysql001 | zone2 | 1004 | 10.10.10.2 | | mysql001 | zone3 | 1006 | 10.10.10.3 | +-------------+-------+---------+------------+ 3 rows in setStart resource unit migration.
Execute the following statement to migrate the resource unit of the
mysql001tenant in zone 3 from10.10.10.3:2882to10.10.10.4:2882:ALTER SYSTEM MIGRATE UNIT = 1006 DESTINATION = '10.10.10.4:2882';Query the migration status.
Execute the following statement to query the distribution of resource units of the
mysql001tenant in each zone after the migration:SELECT t.TENANT_NAME,u.ZONE,u.UNIT_ID,u.SVR_IP FROM oceanbase.DBA_OB_TENANTS t,oceanbase.DBA_OB_UNITS u WHERE t.TENANT_ID=u.TENANT_ID AND t.TENANT_NAME='mysql001';The return result is as follows:
+-------------+-------+---------+------------+ | TENANT_NAME | ZONE | UNIT_ID | SVR_IP | +-------------+-------+---------+------------+ | mysql001 | zone1 | 1002 | 10.10.10.1 | | mysql001 | zone2 | 1004 | 10.10.10.2 | | mysql001 | zone3 | 1006 | 10.10.10.4 | +-------------+-------+---------+------------+ 3 rows in set
References
For more information about the syntax for resource unit migration, see MIGRATE UNIT.
For more information about how to cancel resource unit migration, see CANCEL MIGRATE UNIT.
For more information about resource unit migration, see Migrate replicas.