This section describes the application of table group weight balancing in daily business through several typical scenarios.
Scenario 1: Automatic aggregation of tables created in the same database
Scenario description
You need to create a batch of user tables for your business and manage these tables by database to avoid distributed reads and writes within the database.
Procedure
You can first enable automatic aggregation for user tables in new databases (set the value of the parameter enable_database_sharding_none to True), and then create the databases and tables. The specific procedure is as follows:
Connect to the database as the tenant administrator of the user tenant.
Note that you must specify the corresponding options in the following sample code based on your actual database configurations.
obclient -h10.xx.xx.xx -P2883 -uroot@mysql_tenant#obdemo -p***** -ASet the value of the tenant-level parameter
enable_database_sharding_nonetoTrue.obclient(root@mysql001)[(none)]> ALTER SYSTEM SET enable_database_sharding_none = True;Create multiple databases as needed.
After a database is created, it is bound to a new table group with
Sharding = 'NONE'by default.For more information about how to create a database, see Create a database.
Create user tables in batches by database. User tables in the same database are automatically bound to the same log stream.
Scenario 2: Aggregation of tables created in multiple databases
Scenario description
You need to create a batch of user tables for your business. These tables are closely associated with the user tables in another database A (assume that database A was bound to a table group with Sharding = 'NONE' when it was created). Now, you need to aggregate the new tables with those in database A to avoid distributed reads and writes across databases.
Procedure
You can create a database B and bind it to the same table group with Sharding = 'NONE' as database A, and then create the tables. The specific procedure is as follows:
Connect to the database as the tenant administrator of the user tenant.
Note that you must specify the corresponding options in the following sample code based on your actual database configurations.
obclient -h10.xx.xx.xx -P2883 -uroot@mysql_tenant#obdemo -p***** -ARetrieve the table group information bound to database A.
obclient(root@mysql001)[(none)]> SELECT * FROM oceanbase.DBA_OB_DATABASES WHERE DATABASE_NAME = 'databse_name';Use the following statement to create a new database B and specify its table group as the one bound to database A.
CREATE DATABASE databae_name DEFAULT tablegroup = tablegroup_name;For more information about the
CREATE DATABASEstatement, see CREATE DATABASE.Create a user table in the new database B. The new table is automatically bound to the same log stream as the user table in database A.
Scenario 3: Re-aggregation of multiple databases
Scenario description
You need to re-aggregate the user tables in multiple associated databases to avoid distributed reads and writes across databases.
Procedure
Connect to the database as the tenant administrator of the user tenant.
Note that you must specify the corresponding options in the following sample code based on your actual database configurations.
obclient -h10.xx.xx.xx -P2883 -uroot@mysql_tenant#obdemo -p***** -AUse the following statement to create a table group with
Sharding = 'NONE'.CREATE TABLEGROUP tablegroup_name Sharding = 'NONE';Use the following statement to bind multiple databases to the newly created table group.
ALTER DATABASE database_name tablegroup [=] tablegroup_name;For more information about the
ALTER DATABASEstatement, see ALTER DATABASE.Manually trigger partition balancing.
obclient(root@mysql001)[(none)]> CALL DBMS_BALANCE.TRIGGER_PARTITION_BALANCE();For more information about how to manually trigger partition balancing, see Manually trigger partition balancing.
Wait for the partition balancing task to complete to finish aggregating the user tables from multiple databases.
During the partition balancing process, you can view the progress of the balancing task using the following statement:
obclient(root@mysql001)[(none)]> SELECT * FROM oceanbase.DBA_OB_BALANCE_JOBS WHERE JOB_TYPE = 'PARTITION_BALANCE';For more information about how to view the progress of a partition balancing task, see View background partition balancing tasks.
Scenario 4: Exclusive log stream for hotspot table groups
Scenario description
After enabling automatic aggregation for user tables in new databases (by setting the parameter enable_database_sharding_none to True), a table group with Sharding = 'NONE' is created by default for each new database (the weight of a table group created this way is 1 by default). Now, based on business requirements, you want to ensure that hotspot table groups exclusively use a log stream.
Procedure
Assume the current tenant has nine table groups with Sharding = 'NONE', named TG_DB_1 through TG_DB_9. Among them, TG_DB_1 becomes a hotspot table group because it aggregates user tables from multiple databases and is expected to exclusively occupy one log stream.
Currently, the weight distribution of these table groups is as follows.

You can set the weight of the hotspot table group TG_DB_1 to 100% (100% * the total number of table groups with Sharding = 'NONE') to achieve exclusive occupation. The specific procedure is as follows:
Connect to the database as the tenant administrator of the user tenant.
Note that you must specify the corresponding options in the following sample code based on your actual database configurations.
obclient -h10.xx.xx.xx -P2883 -uroot@mysql_tenant#obdemo -p***** -ADetermine the total number of table groups with
Sharding = 'NONE'and weights under the tenant.obclient(root@mysql001)[(none)]> SELECT * FROM oceanbase.DBA_OB_OBJECT_BALANCE_WEIGHT;Set the weight for the hotspot table group.
Assuming the query returns a total of 9 table groups with
Sharding = 'NONE'and weights, the statement to set the weight of the hotspot table group to 9 is as follows:obclient(root@mysql001)[(none)]> CALL DBMS_BALANCE.SET_TABLEGROUP_BALANCE_WEIGHT(9,'TG_DB_1');Manually trigger partition balancing.
obclient(root@mysql001)[(none)]> CALL DBMS_BALANCE.TRIGGER_PARTITION_BALANCE();For more information about how to manually trigger partition balancing, see Manually trigger partition balancing.
Wait for the partition balancing task to complete to aggregate user tables from multiple databases.
During the partition balancing process, you can view the progress of the balancing task using the following statement:
obclient(root@mysql001)[(none)]> SELECT * FROM oceanbase.DBA_OB_BALANCE_JOBS WHERE JOB_TYPE = 'PARTITION_BALANCE';For more information about how to view the progress of a partition balancing task, see View background partition balancing tasks.
After balancing is completed, the weight distribution of these table groups is as follows:

Scenario 5: Distribute table groups by weight
Scenario description
After enabling automatic aggregation for user tables in a new database (by setting the parameter enable_database_sharding_none to True), a table group with Sharding = 'NONE' is created by default for each database. The weight of such a table group is initially 1. Now, based on business requirements, you want to disperse table groups that contain many user tables, have large data volumes, or receive high access traffic.
Procedure
Assume the current tenant has nine Sharding = 'NONE' table groups named TG_DB_1 through TG_DB_9. Among them, the tables in TG_DB_1, TG_DB_2, and TG_DB_4 have large data volumes but do not warrant occupying a dedicated log stream.
The current weight distribution of these table groups is as follows.

You can set the weights of TG_DB_1, TG_DB_2, and TG_DB_4 to 50% of the total number of Sharding = 'NONE' table groups. The specific steps are as follows:
Connect to the database as the tenant administrator of the user tenant.
Note that you must specify the corresponding options in the following sample code based on your actual database configurations.
obclient -h10.xx.xx.xx -P2883 -uroot@mysql_tenant#obdemo -p***** -ADetermine the total number of weighted
Sharding = 'NONE'table groups in the tenant.obclient(root@mysql001)[(none)]> SELECT * FROM oceanbase.DBA_OB_OBJECT_BALANCE_WEIGHT;Set the weights for the table groups
TG_DB_1,TG_DB_2, andTG_DB_4.Assuming the query returns a total of 9 weighted
Sharding = 'NONE'table groups, the statements to set their weights to 4 (the result of50% * 9rounded down) are as follows:obclient(root@mysql001)[(none)]> CALL DBMS_BALANCE.SET_TABLEGROUP_BALANCE_WEIGHT(4,'TG_DB_1');obclient(root@mysql001)[(none)]> CALL DBMS_BALANCE.SET_TABLEGROUP_BALANCE_WEIGHT(4,'TG_DB_2');obclient(root@mysql001)[(none)]> CALL DBMS_BALANCE.SET_TABLEGROUP_BALANCE_WEIGHT(4,'TG_DB_4');Manually trigger partition balancing.
obclient(root@mysql001)[(none)]> CALL DBMS_BALANCE.TRIGGER_PARTITION_BALANCE();For more information about how to manually trigger partition balancing, see Manually trigger partition balancing.
Wait for the partition balancing task to complete to finalize the aggregation of user tables across multiple databases.
During partition balancing, you can view the progress of the balancing task using the following statement:
obclient(root@mysql001)[(none)]> SELECT * FROM oceanbase.DBA_OB_BALANCE_JOBS WHERE JOB_TYPE = 'PARTITION_BALANCE';For more information about how to view the progress of a partition balancing task, see View background partition balancing tasks.
After the balancing is complete, the weight distribution of these table groups is as follows:
