In OceanBase Database, you can modify the dynamic partition management attributes of a table by altering the DYNAMIC_PARTITION_POLICY block.
This topic describes how to use SQL statements to modify a dynamically partitioned table.
Limitations and considerations
Changes to dynamic partition management parameters do not take effect immediately for pre-created partitions or deleted expired partitions. You must wait for the next automatically scheduled dynamic partition management task or manually schedule one. For more information about scheduling dynamic partition management tasks, see Dynamic partition management tasks.
The
TIME_UNIT,TIME_ZONE, andBIGINT_PRECISIONparameters are specified when creating a dynamically partitioned table and cannot be modified afterward.Whether to specify
TIME_UNITwhen modifying the dynamic partitioning strategy depends on whether dynamic partition management is enabled for the table:- For tables with dynamic partition management enabled, you do not need to specify
TIME_UNITand cannot specify it in the modification statement (doing so will cause an error). - For tables without dynamic partition management enabled (for example, regular partitioned tables), you need to specify
TIME_UNITin the modification statement.
- For tables with dynamic partition management enabled, you do not need to specify
Privilege requirements
To modify a dynamically partitioned table, you must have the ALTER privilege. For more information about privileges in OceanBase Database, see Privilege types in MySQL-compatible mode.
Syntax
The SQL statement format for modifying a dynamically partitioned table is as follows:
ALTER TABLE table_name [SET] DYNAMIC_PARTITION_POLICY [=] (dynamic_partition_policy_list);
dynamic_partition_policy_list:
dynamic_partition_policy_option [, dynamic_partition_policy_option ...]
dynamic_partition_policy_option:
ENABLE = {true | false}
| TIME_UNIT = {'hour' | 'day' | 'week' | 'month' | 'year'}
| PRECREATE_TIME = {'-1' | '0' | 'n {hour | day | week | month | year}'}
| EXPIRE_TIME = {'-1' | '0' | 'n {hour | day | week | month | year}'}
Note
TIME_UNIT is specified when creating the table and cannot be modified afterward: when modifying a table with dynamic partition management enabled, you cannot specify TIME_UNIT; when adding a dynamic partitioning strategy to a table without dynamic partition management enabled, you need to specify TIME_UNIT.
Description of dynamic partition management attribute parameters
Attribute name |
Description |
Required |
Modifiable |
|---|---|---|---|
| ENABLE | Specifies whether to enable dynamic partition management. Valid values:
|
No | Yes |
| TIME_UNIT | The time unit for indicating partitions, that is, the interval at which partition boundaries are automatically created. Valid values:
Note
|
No | No |
| PRECREATE_TIME | Specifies the pre-create time. When scheduling a dynamic partition management task, partitions are pre-created so that max_partition_upper_bound > now() + precreate_time. Valid values:
Note
|
No | Yes |
| EXPIRE_TIME | Indicates the partition expiration time. When dynamic partition management is scheduled, all partitions whose upper_bound < now() - expire_time are deleted. Valid values:
|
No | Yes |
For more detailed parameter descriptions related to modifying table syntax, see ALTER TABLE.
Examples
Create a table:
CREATE TABLE test_tbl1 (col1 INT, col2 DATETIME) DYNAMIC_PARTITION_POLICY( ENABLE = true, TIME_UNIT = 'hour', PRECREATE_TIME = '3 hour', EXPIRE_TIME = '1 day', TIME_ZONE = '+8:00', BIGINT_PRECISION = 'none' ) PARTITION BY RANGE COLUMNS (col2)( PARTITION P0 VALUES LESS THAN ('2025-04-15 13:30:00') );View the dynamic partition information of the
test_tbl1table.SELECT * FROM oceanbase.DBA_OB_DYNAMIC_PARTITION_TABLES WHERE TABLE_NAME = 'test_tbl1';The query result is as follows:
+---------------+------------+----------+-----------------------+--------+-----------+----------------+-------------+-----------+------------------+ | DATABASE_NAME | TABLE_NAME | TABLE_ID | MAX_HIGH_BOUND_VAL | ENABLE | TIME_UNIT | PRECREATE_TIME | EXPIRE_TIME | TIME_ZONE | BIGINT_PRECISION | +---------------+------------+----------+-----------------------+--------+-----------+----------------+-------------+-----------+------------------+ | db_test | test_tbl1 | 511335 | '2025-04-15 13:30:00' | TRUE | HOUR | 3HOUR | 1DAY | +8:00 | NONE | +---------------+------------+----------+-----------------------+--------+-----------+----------------+-------------+-----------+------------------+ 1 row in setModify the dynamic partition table
test_tbl1and set its dynamic partition attributes to be:- Pre-create partitions within 1 day after the current time.
- Partitions are never expired.
ALTER TABLE test_tbl1 DYNAMIC_PARTITION_POLICY( ENABLE = true, PRECREATE_TIME = '1 day', EXPIRE_TIME = '-1' );View the dynamic partition information of the
test_tbl1table again.SELECT * FROM oceanbase.DBA_OB_DYNAMIC_PARTITION_TABLES WHERE TABLE_NAME = 'test_tbl1';The query result is as follows:
+---------------+------------+----------+-----------------------+--------+-----------+----------------+-------------+-----------+------------------+ | DATABASE_NAME | TABLE_NAME | TABLE_ID | MAX_HIGH_BOUND_VAL | ENABLE | TIME_UNIT | PRECREATE_TIME | EXPIRE_TIME | TIME_ZONE | BIGINT_PRECISION | +---------------+------------+----------+-----------------------+--------+-----------+----------------+-------------+-----------+------------------+ | db_test | test_tbl1 | 511335 | '2025-04-15 13:30:00' | TRUE | HOUR | 1DAY | -1 | +8:00 | NONE | +---------------+------------+----------+-----------------------+--------+-----------+----------------+-------------+-----------+------------------+ 1 row in setNote
After modifying dynamic partition management parameters, pre-created partitions and deleted expired partitions do not take effect immediately. You need to wait for the next automatically scheduled dynamic partition management task or manually schedule one. For details, see Dynamic partition management task.
Add a dynamic partition strategy to a regular RANGE COLUMNS partitioned table that has not enabled dynamic partition management.
Create a regular RANGE COLUMNS partitioned table named
test_tbl3.CREATE TABLE test_tbl3 (col1 INT, col2 DATETIME) PARTITION BY RANGE COLUMNS (col2)( PARTITION P0 VALUES LESS THAN ('2026-09-14 00:00:00') );Add a dynamic partition strategy to
test_tbl3and set its dynamic partition attributes to be:- Partition boundaries are divided by day.
- Pre-create partitions within 3 days after the current time.
- Delete partitions whose upper boundary is earlier than 30 days before the current time.
ALTER TABLE test_tbl3 DYNAMIC_PARTITION_POLICY( ENABLE = true, TIME_UNIT = 'day', PRECREATE_TIME = '3 day', EXPIRE_TIME = '30 day' );Note
- When adding a dynamic partition strategy to a table that has not enabled dynamic partition management, you must specify
TIME_UNIT. - When the partitioning key is of the time type, the default value of
TIME_ZONEisdefault, and the default value ofBIGINT_PRECISIONisnone. These can be omitted.
Manually trigger a dynamic partition management task to view the pre-created partitions.
CALL DBMS_PARTITION.MANAGE_DYNAMIC_PARTITION();View the partition information of the
test_tbl3table:SELECT TABLE_NAME, PARTITION_NAME, PARTITION_DESCRIPTION FROM information_schema.PARTITIONS WHERE TABLE_NAME = 'test_tbl3' ORDER BY PARTITION_ORDINAL_POSITION;In the query result, you can see the three pre-created daily partitions.
