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 parameters are described as follows:
| Parameter | Description |
|---|---|
| unit_id | The unit ID. |
| ip_port | The address of the destination server to which the resource unit is migrated. |
Examples
View resource unit distribution.
Execute the following SQL statement to view 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 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 SQL statement to migrate the resource units of the
mysql001tenant in zone3 from10.10.10.3:2882to10.10.10.4:2882:ALTER SYSTEM MIGRATE UNIT = 1006 DESTINATION = '10.10.10.4:2882';View the migration status.
Execute the following SQL statement to view the distribution of resource units for the
mysql001tenant after migration 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 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.