In OceanBase Database, you can modify the dynamic partition management attributes of a table by updating DYNAMIC_PARTITION_POLICY.
This topic describes how to modify a dynamic partitioned table by using SQL statements.
Note
For OceanBase Database V4.3.5, the DYNAMIC_PARTITION_POLICY parameter is supported for creating dynamic partitioned tables starting from V4.3.5 BP2.
Limitations and considerations
After modifying the dynamic partition management parameters, the actions of pre-creating partitions and deleting expired partitions will not take effect immediately. You need to wait for the next automatic scheduling of the dynamic partition management task, or manually trigger the dynamic partition management task. For more information about how to schedule a dynamic partition management task, see Dynamic partition management task.
Privilege requirements
To modify a dynamic partitioned table, you need the ALTER privilege. For more information about privileges in OceanBase Database, see Privilege types in MySQL-compatible mode.
Syntax
The SQL statement format for creating a dynamic 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}
| PRECREATE_TIME = {'-1' | '0' | 'n {hour | day | week | month | year}'}
| EXPIRE_TIME = {'-1' | '0' | 'n {hour | day | week | month | year}'}
Dynamic partition management attributes
| Attribute | Description | Required? | Modifiable? |
|---|---|---|---|
| ENABLE | Specifies whether to enable dynamic partition management. Valid values:
|
No | Yes |
| PRECREATE_TIME | Specifies the precreation time. Partitions are precreated in an scheduling task of dynamic partition management so that max_partition_upper_bound > now() + precreate_time. Valid values:
Note
|
No | Yes |
| EXPIRE_TIME | Specifies the partition expiration time. Partitions are deleted in an scheduling task of dynamic partition management so that partition_upper_bound < now() - expire_time. Valid values:
|
No | Yes |
For more information about how to modify the syntax of a table, see ALTER TABLE.
Examples
Query the dynamic partitioning information about 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 partitioning settings for the
test_tbl1table as follows:- Precreate partitions for one day starting from the current time.
- Partitions never expire.
ALTER TABLE test_tbl1 DYNAMIC_PARTITION_POLICY( ENABLE = true, PRECREATE_TIME = '1 day', EXPIRE_TIME = '-1' );Query the dynamic partitioning information about 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 the dynamic partition management parameters, the actions of pre-creating partitions and deleting expired partitions will not take effect immediately. You need to wait for the next automatic scheduling of the dynamic partition management task, or manually trigger the dynamic partition management task. For more information, see Dynamic partition management task.