When you create a user tenant in OceanBase Database, the system has a built-in scheduled partition balancing task named SCHEDULED_TRIGGER_PARTITION_BALANCE, which is triggered at 00:00 every day by default. You can use the subprograms of the DBMS_SCHEDULER system package to configure the parameters of the scheduled partition balancing task.
Limitations
You cannot configure a scheduled partition balancing task in the sys tenant.
Enable the scheduled partition balancing task
For a user tenant created in the current version, the scheduled partition balancing task is enabled by default, and you do not need to enable it again. In V4.4.x, for a user tenant upgraded to the current version from a version earlier than V4.4.1, the scheduled partition balancing task is disabled by default. You can enable it by performing the following steps.
Log in to the MySQL-compatible or Oracle-compatible tenant of the cluster as the tenant administrator.
The following example shows how to connect to the database. Please adjust the connection details according to your actual environment.
obclient -h10.xx.xx.xx -P2883 -uroot@mysql_tenant#obdemo -p***** -ACheck whether the value of the
partition_balance_schedule_intervalparameter at the tenant level is0s.Before you enable the scheduled partition balancing task
SCHEDULED_TRIGGER_PARTITION_BALANCE, make sure that automatic partition balancing is not enabled. That is, the value of thepartition_balance_schedule_intervalparameter at the tenant level must be0.Check whether the value of the
partition_balance_schedule_intervalparameter at the tenant level is0s. If not, set it to0sby executing the following statements:obclient> SHOW PARAMETERS LIKE '%partition_balance_schedule_interval%';obclient> ALTER SYSTEM SET partition_balance_schedule_interval='0s';Call the
ENABLEsubprogram of theDBMS_SCHEDULERsystem package to enable the scheduled partition balancing taskSCHEDULED_TRIGGER_PARTITION_BALANCE.MySQL-compatible modeOracle-compatible modeThe following example shows how to enable the scheduled partition balancing task in a MySQL-compatible tenant:
obclient [oceanbase]> CALL DBMS_SCHEDULER.ENABLE('SCHEDULED_TRIGGER_PARTITION_BALANCE');The following example shows how to enable the scheduled partition balancing task in an Oracle-compatible tenant:
obclient [SYS]> DELIMITER //obclient [SYS]> BEGIN DBMS_SCHEDULER.ENABLE('SCHEDULED_TRIGGER_PARTITION_BALANCE'); END;//obclient [SYS]> DELIMITER ;For more information about the
ENABLEsubprogram, see ENABLE.
Disable the scheduled partition balancing task
For user tenants created in the current version, the scheduled partition balancing task is enabled by default. You can disable the task based on your business needs. After you disable the task, you can still trigger partition balancing automatically (by setting the partition_balance_schedule_interval parameter to a value greater than 0s).
Log in to the MySQL-compatible or Oracle-compatible tenant of the cluster as the tenant administrator.
The following example shows how to connect to the database. Please adjust the connection details according to your actual environment.
obclient -h10.xx.xx.xx -P2883 -uroot@mysql_tenant#obdemo -p***** -ACall the
DISABLEsubprogram of theDBMS_SCHEDULERsystem package to disable theSCHEDULED_TRIGGER_PARTITION_BALANCEtask.MySQL-compatible modeOracle-compatible modeThe following example shows how to disable the scheduled partition balancing task in a MySQL-compatible tenant:
obclient [oceanbase]> CALL DBMS_SCHEDULER.DISABLE('SCHEDULED_TRIGGER_PARTITION_BALANCE');The following example shows how to disable the scheduled partition balancing task in an Oracle-compatible tenant:
obclient [SYS]> DELIMITER //obclient [SYS]> BEGIN DBMS_SCHEDULER.DISABLE('SCHEDULED_TRIGGER_PARTITION_BALANCE'); END;//obclient [SYS]> DELIMITER ;For more information about the
DISABLEsubprogram, see DISABLE.
Adjust the scheduling time of the scheduled partition balancing task
After you enable the scheduled partition balancing task, the system triggers partition balancing at 00:00 every day by default. You can change the scheduling time as needed.
Log in to the MySQL-compatible or Oracle-compatible tenant of the cluster as the tenant administrator.
The following example shows how to connect to the database. Please adjust the connection details according to your actual environment.
obclient -h10.xx.xx.xx -P2883 -uroot@mysql_tenant#obdemo -p***** -ACall the
SET_ATTRIBUTEsubprogram of theDBMS_SCHEDULERsystem package to change the next scheduling time of the partition balancing task. For example, you can set the next trigger time to 01:00.MySQL-compatible modeOracle-compatible modeThe following example shows how to change the execution time of the scheduled partition balancing task to
2024-06-12 01:00:00in a MySQL-compatible tenant:obclient [oceanbase]> CALL DBMS_SCHEDULER.SET_ATTRIBUTE('SCHEDULED_TRIGGER_PARTITION_BALANCE', 'NEXT_DATE', '2024-06-12 01:00:00');The following example shows how to change the execution time of the scheduled partition balancing task to
12-Jun-2024 01:00:00in an Oracle-compatible tenant:obclient [SYS]> DELIMITER //obclient [SYS]> BEGIN DBMS_SCHEDULER.SET_ATTRIBUTE('SCHEDULED_TRIGGER_PARTITION_BALANCE', 'NEXT_DATE', '12-Jun-2024 01:00:00'); END;//obclient [SYS]> DELIMITER ;For more information about the
SET_ATTRIBUTEsubprogram, see SET_ATTRIBUTE.
Adjust the scheduling frequency of the scheduled partition balancing task
By default, the scheduling frequency of the scheduled partition balancing task is once a day. You can change it as needed.
Log in to the MySQL-compatible or Oracle-compatible tenant of the cluster as the tenant administrator.
The following example shows how to connect to the database. Please adjust the connection details according to your actual environment.
obclient -h10.xx.xx.xx -P2883 -uroot@mysql_tenant#obdemo -p***** -ACall the
SET_ATTRIBUTEsubprogram of theDBMS_SCHEDULERsystem package to change the scheduling frequency of the partition balancing task. For example, you can set the task to be triggered every two days.MySQL-compatible modeOracle-compatible modeThe statement is as follows:
CALL DBMS_SCHEDULER.SET_ATTRIBUTE('SCHEDULED_TRIGGER_PARTITION_BALANCE', 'REPEAT_INTERVAL', 'FREQ=str_value; INTERVAL=int_value');Where:
FREQ: specifies the time unit for the scheduling frequency. Valid values:MINUTELY(minutes),HOURLY(hours),DAILY(days), andWEEKLY(weeks).INTERVAL: specifies the specific value, that is, how often the task is triggered. For example,FREQ=DAILY; INTERVAL=2indicates that the task is triggered every two days.
The following example shows how to change the execution frequency of the scheduled partition balancing task to every two days in a MySQL-compatible tenant:
obclient [oceanbase]> CALL DBMS_SCHEDULER.SET_ATTRIBUTE('SCHEDULED_TRIGGER_PARTITION_BALANCE', 'REPEAT_INTERVAL', 'FREQ=DAILY; INTERVAL=2');The statement is as follows:
BEGIN DBMS_SCHEDULER.SET_ATTRIBUTE('SCHEDULED_TRIGGER_PARTITION_BALANCE', 'REPEAT_INTERVAL', 'FREQ=str_value; INTERVAL=int_value'); END;Where:
FREQ: specifies the time unit for the scheduling frequency. Valid values:MINUTELY(minutes),HOURLY(hours),DAILY(days), andWEEKLY(weeks).INTERVAL: specifies the specific value, that is, how often the task is triggered. For example,FREQ=DAILY; INTERVAL=2indicates that the task is triggered every two days.
The following example shows how to change the execution frequency of the scheduled partition balancing task to every two days in an Oracle-compatible tenant:
obclient [SYS]> DELIMITER //obclient [SYS]> BEGIN DBMS_SCHEDULER.SET_ATTRIBUTE('SCHEDULED_TRIGGER_PARTITION_BALANCE', 'REPEAT_INTERVAL', 'FREQ=DAILY; INTERVAL=2'); END;//obclient [SYS]> DELIMITER ;For more information about the
SET_ATTRIBUTEsubprogram, see SET_ATTRIBUTE.
Adjust the timeout for a single scheduled partition balancing task execution
By default, there is no timeout for a single execution of the scheduled partition balancing task. You can change this based on your actual business requirements.
Adjusting the timeout for a single execution of the scheduled partition balancing task actually adjusts the execution timeout for all background partition balancing tasks triggered by the TRIGGER_PARTITION_BALANCE procedure. Therefore, this adjustment also affects manually triggered partition balancing tasks. For more information about how to manually trigger partition balancing, see Manually trigger partition balancing.
Log in to the MySQL-compatible or Oracle-compatible tenant of the cluster as the tenant administrator.
The following example shows how to connect to the database. Please adjust the connection details according to your actual environment.
obclient -h10.xx.xx.xx -P2883 -uroot@mysql_tenant#obdemo -p***** -ACall the
SET_ATTRIBUTEsubprogram of theDBMS_SCHEDULERsystem package to adjust the timeout for a single task execution.MySQL-compatible modeOracle-compatible modeThe statement is as follows:
CALL DBMS_SCHEDULER.SET_ATTRIBUTE('SCHEDULED_TRIGGER_PARTITION_BALANCE', 'JOB_ACTION', 'DBMS_BALANCE.TRIGGER_PARTITION_BALANCE(balance_timeout)');The
balance_timeoutparameter specifies the timeout for a single task execution, in seconds. If this parameter is empty, the background balancing task has no timeout.The following example shows how to set the timeout for a single task execution to 7200 seconds in a MySQL-compatible tenant:
obclient [oceanbase]> CALL DBMS_SCHEDULER.SET_ATTRIBUTE('SCHEDULED_TRIGGER_PARTITION_BALANCE', 'JOB_ACTION', 'DBMS_BALANCE.TRIGGER_PARTITION_BALANCE(7200)');The statement is as follows:
BEGIN DBMS_SCHEDULER.SET_ATTRIBUTE('SCHEDULED_TRIGGER_PARTITION_BALANCE', 'JOB_ACTION', 'DBMS_BALANCE.TRIGGER_PARTITION_BALANCE(balance_timeout)'); END;The
balance_timeoutparameter specifies the timeout for a single task execution, in seconds. If this parameter is empty, the background balancing task has no timeout.The following example shows how to set the timeout for a single task execution to 7200 seconds in an Oracle-compatible tenant:
obclient [SYS]> DELIMITER //obclient [SYS]> BEGIN DBMS_SCHEDULER.SET_ATTRIBUTE('SCHEDULED_TRIGGER_PARTITION_BALANCE', 'JOB_ACTION', 'DBMS_BALANCE.TRIGGER_PARTITION_BALANCE(7200)'); END;//obclient [SYS]> DELIMITER ;For more information about the
SET_ATTRIBUTEsubprogram, see SET_ATTRIBUTE.
Adjust the maximum execution time for the partition balancing trigger statement
The default maximum execution time for the partition balancing trigger statement is 7200 seconds (2 hours). We recommend that you do not change this value.
Log in to the MySQL-compatible or Oracle-compatible tenant of the cluster as the tenant administrator.
The following example shows how to connect to the database. Please adjust the connection details according to your actual environment.
obclient -h10.xx.xx.xx -P2883 -uroot@mysql_tenant#obdemo -p***** -ACall the
SET_ATTRIBUTEsubprogram of theDBMS_SCHEDULERsystem package to adjust the maximum execution time for the partition balancing trigger statement.MySQL-compatible modeOracle-compatible modeThe statement is as follows:
CALL DBMS_SCHEDULER.SET_ATTRIBUTE('SCHEDULED_TRIGGER_PARTITION_BALANCE', 'MAX_RUN_DURATION', 'max_time');The
max_timeparameter specifies the maximum execution time for the partition balancing trigger statement, in seconds.The following example shows how to adjust the maximum execution time for the partition balancing trigger statement to 3600 seconds (1 hour) in a MySQL-compatible tenant:
obclient [oceanbase]> CALL DBMS_SCHEDULER.SET_ATTRIBUTE('SCHEDULED_TRIGGER_PARTITION_BALANCE', 'MAX_RUN_DURATION', '3600');The statement is as follows:
BEGIN DBMS_SCHEDULER.SET_ATTRIBUTE('SCHEDULED_TRIGGER_PARTITION_BALANCE', 'MAX_RUN_DURATION', 'max_time'); END;The
max_timeparameter specifies the maximum execution time for the partition balancing trigger statement, in seconds.The following example shows how to adjust the maximum execution time for the partition balancing trigger statement to 3600 seconds (1 hour) in an Oracle-compatible tenant:
obclient [SYS]> DELIMITER //obclient [SYS]> BEGIN DBMS_SCHEDULER.SET_ATTRIBUTE('SCHEDULED_TRIGGER_PARTITION_BALANCE', 'MAX_RUN_DURATION', '3600'); END;//obclient [SYS]> DELIMITER ;For more information about the
SET_ATTRIBUTEsubprogram, see SET_ATTRIBUTE.
What to do next
The scheduled task is used only to trigger the partition balancing task. When the trigger conditions are met, the system automatically triggers the partition balancing task. After the partition balancing task is triggered:
You can view the trigger history of the scheduled partition balancing task in a view. For more information, see View the trigger history of the scheduled partition balancing task.
The actual partition transfer is performed asynchronously by the background balancing task. You can view the execution process of the partition balancing task in a view. For more information, see View the partition balancing tasks in the background.
Note
After the partition balancing task is triggered, if the values of the tenant-level parameters
enable_rebalanceandenable_transferare not bothTrue, the scheduled task fails.