In OceanBase Database, you can modify the dynamic partition management attributes of a table by altering the DYNAMIC_PARTITION_POLICY clause.
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 partition 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_UNITand cannot specify it in the modification statement (doing so will cause 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 Oracle-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 partition 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 | Indicates whether to enable dynamic partition management. Valid values:
|
No | Yes |
| TIME_UNIT | The time unit for indicating partitions, that is, the interval for automatically creating partition boundaries. Valid values:
Note
|
No | No |
| PRECREATE_TIME | Represents 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 table modification syntax, see ALTER TABLE.
Examples
Create a table.
-- Create table: TIME_UNIT='hour' CREATE TABLE test_tbl1 (col1 INT, col2 TIMESTAMP) 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 (col2)( PARTITION P0 VALUES LESS THAN (TIMESTAMP '2024-11-11 13:30:00') );View the dynamic partition information of the
test_tbl1table.SELECT * FROM sys.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 | +---------------+------------+----------+----------------------------------------+--------+-----------+----------------+-------------+-----------+------------------+ | SYS | TEST_TBL1 | 507940 | Timestamp '2024-11-11 13:30:00.000000' | TRUE | HOUR | 3HOUR | 1DAY | +8:00 | NONE | +---------------+------------+----------+----------------------------------------+--------+-----------+----------------+-------------+-----------+------------------+ 1 row in setModify the dynamic partition table
test_tbl1and set its dynamic partition attributes to:- Pre-create partitions within 1 day after 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 the
test_tbl1table again.SELECT * FROM sys.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 | +---------------+------------+----------+----------------------------------------+--------+-----------+----------------+-------------+-----------+------------------+ | SYS | TEST_TBL1 | 507940 | Timestamp '2024-11-11 13:30:00.000000' | 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 automatic scheduling of a dynamic partition management task or manually schedule one. For more details, see Dynamic partition management tasks.
Add a dynamic partition strategy to a regular RANGE-partitioned table that has not yet enabled dynamic partition management.
Create a regular RANGE-partitioned table named
test_tbl3.CREATE TABLE test_tbl3 (col1 INT, col2 TIMESTAMP) PARTITION BY RANGE (col2)( PARTITION P0 VALUES LESS THAN (TIMESTAMP '2026-09-14 00:00:00') );Add a dynamic partition strategy to
test_tbl3and set its dynamic partition attributes to:- Partition boundaries are divided by day.
- Pre-create partitions within 3 days after the current time.
- Delete partitions whose upper bound 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 yet 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, HIGH_VALUE FROM SYS.USER_TAB_PARTITIONS WHERE TABLE_NAME = 'TEST_TBL3' ORDER BY PARTITION_POSITION;In the query result, you can see the three pre-created daily partitions.
