In OceanBase Database, you can modify the dynamic partition management attributes of a table by modifying the DYNAMIC_PARTITION_POLICY block.
This topic describes how to use SQL statements to modify a dynamically partitioned table.
Limitations and considerations
After modifying dynamic partition management parameters, pre-created partitions and deleted expired partitions will not take effect immediately. You must wait for the next automatic scheduling of a 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 after specification.Whether to specify
TIME_UNITwhen modifying the dynamic partitioning strategy depends on whether dynamic partition management is enabled for the table:- For a table with dynamic partition management enabled, you do not need to specify
TIME_UNIT, nor can it be specified in the modification statement (specification will result in an error). - For a table without dynamic partition management enabled (for example, a regular partitioned table), you need to specify
TIME_UNITin the modification statement.
- For a table 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 partitioning, which is the interval at which partition boundaries are automatically created. Valid values:
Note
|
No | No |
| PRECREATE_TIME | Indicates 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 that meet the condition upper_bound < now() - expire_time are deleted. Valid values:
|
No | Yes |
For more information about the parameters for modifying a table, 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 | +---------------+------------+----------+-----------------------+--------+-----------+----------------+-------------+-----------+------------------+ | test | test_tbl1 | 500004 | '2025-04-15 13:30:00' | TRUE | HOUR | 3HOUR | 1DAY | +8:00 | NONE | +---------------+------------+----------+-----------------------+--------+-----------+----------------+-------------+-----------+------------------+ 1 row in setModify the dynamic partitioned table
test_tbl1and set its dynamic partition properties as follows:- Pre-create partitions for the next 1 day from the current time.
- Partitions never expire.
ALTER TABLE test_tbl1 DYNAMIC_PARTITION_POLICY( ENABLE = true, PRECREATE_TIME = '1 day', EXPIRE_TIME = '-1' );View the dynamic partition information of table
test_tbl1again.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 | +---------------+------------+----------+-----------------------+--------+-----------+----------------+-------------+-----------+------------------+ | test | test_tbl1 | 500004 | '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 more details, see Dynamic partition management task.
Add a dynamic partitioning 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 partitioning strategy to
test_tbl3and set its dynamic partition properties as follows:- Partition boundaries are divided by day.
- Pre-create partitions for the next 3 days from 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 partitioning strategy to a table that has not enabled dynamic partition management, you must specify
TIME_UNIT. - When the partitioning key is of a 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 table
test_tbl3:SELECT TABLE_NAME, PARTITION_NAME, PARTITION_DESCRIPTION FROM information_schema.PARTITIONS WHERE TABLE_NAME = 'test_tbl3' ORDER BY PARTITION_ORDINAL_POSITION;The query result shows the three pre-created daily partitions.