The dynamic partitioning feature in Hologres automatically creates and manages child partitioned tables based on the rules you configure. You do not need to pre-configure all partition information. This feature also supports migrating data from eligible partitions to cold storage, which reduces storage costs while maintaining query performance.
Function introduction
Different versions support the dynamic partitioning feature as follows:
Starting from Hologres V1.3, you can configure dynamic partitioning rules. The system periodically runs scheduled tasks based on the configured rules to pre-create child partitioned tables and delete expired ones.
Starting from Hologres V1.3.37, you can dynamically manage tiered storage for hot and cold data. This feature automatically moves data to cold storage to reduce storage costs. For more information, see Tiered Storage of Hot and Cold Data.
Starting from Hologres V2.1.11, dynamic partitioning supports using the Date data type for partition keys.
Starting from Hologres V2.2, you can use the
schd_start_timeproperty in the dynamic partitioning configuration table to customize the partition scheduling time. This lets you set custom times for creating and deleting partitions, or moving them to cold storage.Starting from Hologres V3.0.12, the new
auto_partitioning_time_formatparameter lets you specify the date and time format of the partition key. This lets you create partitions with names in formats such as YYYY-MM-DD.
Usage notes
Hologres allows you to import data to a child table rather than a parent table.
NoteRealtime Compute for Apache Flink allows you to import data to a parent table in Hologres in real time. For more information, see Write data to a partitioned result table in Hologres in real time.
Each partitioning rule can be used to create only one partitioned table.
The
PARTITION BYclause supports onlylist partitioning. The partition key must be a single column.If a partitioned table has a primary key, the partition key must be a subset of the primary key.
You can set the scheduling time (
schd_start_time) only for parent partitioned tables, not for child partitioned tables.The
auto_partitioning_time_formatparameter can be configured only once and cannot be modified. For a new table, you can configure this parameter in the CREATE TABLE statement. You cannot add or modify this parameter for an existing table.After you specify a time format using the
auto_partitioning_time_formatparameter, the names of child partitioned tables match that format. When you query a child partitioned table, you must enclose its name in double quotation marks. For example:SELECT xxx FROM "tbl_2024_11_22".
Configure dynamic partitioning
Syntax
You can configure dynamic partitioning properties when you create a partitioned table or modify the properties of an existing one. The following syntax is used.
Examples with the WITH clause
Create a partitioned table and configure its dynamic partitioning properties.
-- Configure dynamic partitioning properties when creating a partitioned table CREATE TABLE [IF NOT EXISTS] [<schema_name>.]<table_name> ([ { <column_name> <column_type> [ <column_constraints>, [...]] | <table_constraints> [, ...] } ]) PARTITION BY LIST(<column_name>) WITH ( auto_partitioning_enable = 'xxx', auto_partitioning_time_unit = 'xxx', auto_partitioning_time_zone = 'xxx', auto_partitioning_num_precreate = 'xxx', auto_partitioning_num_retention = 'xxx', auto_partitioning_num_hot='xxx', -- Note: The schd_start_time parameter is supported in Hologres V2.2 and later. auto_partitioning_schd_start_time = 'xxx', -- Note: The time_format parameter is supported in Hologres V3.0.12 and later. auto_partitioning_time_format = 'xxx' );Modify the dynamic partitioning properties of an existing partitioned table.
-- Modify dynamic partitioning properties ALTER TABLE [<schema_name>.]<table_name> SET ( auto_partitioning_enable = 'xxx', auto_partitioning_time_unit = 'xxx', auto_partitioning_time_zone = 'xxx', auto_partitioning_num_precreate = 'xxx', auto_partitioning_num_retention = 'xxx', auto_partitioning_num_hot='xxx', -- Note: The schd_start_time parameter is supported in Hologres V2.2 and later. auto_partitioning_schd_start_time = 'xxx', -- Note: The time_format parameter is supported in Hologres V3.0.12 and later. auto_partitioning_time_format = 'xxx' );
Examples with the CALL command
Create a partitioned table and configure its dynamic partitioning properties.
-- Configure dynamic partitioning properties when creating a partitioned table BEGIN; CREATE TABLE [IF NOT EXISTS] [<schema_name>.]<table_name> ([ { <column_name> <column_type> [ <column_constraints>, [...]] | <table_constraints> [, ...] } ]) PARTITION BY LIST(<column_name>); CALL set_table_property('[<schema_name>.]<table_name>', 'auto_partitioning.enable', 'xxx'); CALL set_table_property('[<schema_name>.]<table_name>', 'auto_partitioning.time_unit', 'xxx'); CALL set_table_property('[<schema_name>.]<table_name>', 'auto_partitioning.time_zone', 'xxx'); CALL set_table_property('[<schema_name>.]<table_name>', 'auto_partitioning.num_precreate', 'xxx'); CALL set_table_property('[<schema_name>.]<table_name>', 'auto_partitioning.num_retention', 'xxx'); CALL set_table_property('[<schema_name>.]<table_name>', 'auto_partitioning.num_retention', 'xxx'); CALL set_table_property('[<schema_name>.]<table_name>', 'auto_partitioning.num_hot', 'xxx'); -- Note: The schd_start_time parameter is supported in Hologres V2.2 and later. CALL set_table_property ('[<schema_name>.]<table_name>', 'auto_partitioning.schd_start_time', 'xxx'); -- Note: The time_format parameter is supported in Hologres V3.0.12 and later. CALL set_table_property ('[<schema_name>.]<table_name>', 'auto_partitioning.time_format', 'xxx'); COMMIT;Modify the dynamic partitioning properties of an existing partitioned table.
-- Modify dynamic partitioning properties CALL set_table_property('[<schema_name>.]<table_name>', 'auto_partitioning.enable', 'xxx'); CALL set_table_property('[<schema_name>.]<table_name>', 'auto_partitioning.num_precreate', 'xxx'); CALL set_table_property('[<schema_name>.]<table_name>', 'auto_partitioning.num_retention', 'xxx'); -- Note: The time_format parameter is supported in Hologres V3.0.12 and later. CALL set_table_property('[<schema_name>.]<table_name>', 'auto_partitioning.time_format', 'xxx');
Parameters
When you use the CREATE TABLE WITH statement to configure dynamic partitioning, replace the periods (.) in parameter names with underscores (_). For example, change auto_partitioning.enable to auto_partitioning_enable.
Parameter Name | Required | Description | Updatable | Version requirements |
| No | Specifies whether to enable dynamic partitioning. Valid values:
| Yes | Hologres V1.3 and later |
| Yes | The time unit for dynamic partitioning. Valid values:
For example, if you set this parameter to DAY, partitions are pre-created and deleted by day. | No | |
| No | The time zone for dynamic partitioning. The default value is the time zone of the current connection. After configuration, partitions are dynamically managed based on the specified time zone. Run the following SQL statement to view available time zones and their offsets. The values in the name column are valid timezone values, such as Asia/Shanghai. | No | |
| No | The number of partitions to pre-create. Valid values:
Note For example, if the current date is 2022-01-10, and you set Important Pre-creating partitions affects the behavior of the MAX_PT function. Before you configure this parameter, check whether your workload depends on the MAX_PT function. | Yes | |
| No | The number of historical partitions to retain. Valid values:
Run Note For example, if the current date is 2022-01-10, and you set | Yes | |
| No | The number of hot partitions to retain. Valid values:
| Hologres V1.3.37 and later | |
| No | The custom scheduled time for partitioning. If Use this parameter to change the scheduled time. For more information about supported date and time formats, see Date/Time Types. If you set a future time, the configuration takes effect at that time. | Hologres V2.2 and later | |
| No | Specifies the date and time format of the partition key when creating a table.
| No | Hologres V3.0.12 and later |
Naming conventions for child partitioned tables
The auto_partitioning.time_unit parameter for a dynamically partitioned table can be set to HOUR, DAY, MONTH, QUARTER, or YEAR. The name of a newly created child partition consists of the parent table name and a time suffix, in the format {parent_table}_{time_suffix}. The time suffix is generated based on the scheduled time and the format template that corresponds to the specified time unit. The following table describes these relationships.
Time unit | Time suffix format | Example | Running time |
HOUR | YYYYMMDDHH24 | 2024112221. | The task runs at the beginning of each hour, for example, at 21:00:01 on November 22, 2024. |
YYYY-MM-DD-HH24 | 2024-11-22-21. | ||
DAY | YYYYMMDD | 20241122. | Starts at 00:00:01 every day, for example, at 00:00:01 on November 22, 2024. |
YYYY-MM-DD | 2024-11-22. | ||
MONTH | YYYYMM | 202411. | Starts at 00:00:01 on the first day of each month, for example, at 00:00:01 on November 1, 2024. |
YYYY-MM | 2024-11. | ||
QUARTER | YYYYQ | 20241, 20242, 20243, and 20244 represent the four quarters of 2024. | Starts at 00:00:01 on the first day of each quarter, for example, at 00:00:01 on January 1, 2024. |
YYYY-Q | 2024-1, 2024-2, 2024-3, and 2024-4 represent the four quarters of 2024. | ||
YEAR | YYYY | 2023 and 2024 represent the partitions for the years 2023 and 2024. | Starts at 00:00:01 on the first day of each year, for example, at 00:00:01 on January 1, 2023. |
Examples
The following examples show how to pre-create partitions for the next three days, retain partitions for the last two days, and set the time zone to Asia/Shanghai. The time unit is DAY.
Example with the WITH clause
Create a partitioned table named
tbl1.-- Create a partitioned table and configure dynamic partitioning in Hologres V2.1 or later: CREATE TABLE tbl1 ( c1 TEXT NOT NULL, c2 TEXT ) PARTITION BY LIST (c2) WITH ( auto_partitioning_enable = 'true', auto_partitioning_time_unit = 'DAY', auto_partitioning_time_zone = 'Asia/Shanghai', auto_partitioning_num_precreate = '3', auto_partitioning_num_retention = '2' );Insert data after the child partitions are generated.
INSERT INTO tbl1 (c1, c2) VALUES ('Data 1', '20231212'); INSERT INTO tbl1 (c1, c2) VALUES ('Data 2', '20231213'); INSERT INTO tbl1 (c1, c2) VALUES ('Data 3', '20231214');Query data.
SELECT * FROM tbl1 WHERE c2='20231212';The following result is returned:
c1 c2 Data 1 20231212
Example with the CALL command
Create a partitioned table named
tbl1.-- Create a partitioned table and configure dynamic partitioning: BEGIN; CREATE TABLE tbl1 ( c1 TEXT NOT NULL, c2 TEXT ) PARTITION BY LIST (c2); CALL set_table_property ('tbl1', 'auto_partitioning.enable', 'true'); CALL set_table_property ('tbl1', 'auto_partitioning.time_unit', 'DAY'); CALL set_table_property ('tbl1', 'auto_partitioning.time_zone', 'Asia/Shanghai'); CALL set_table_property ('tbl1', 'auto_partitioning.num_precreate', '3'); CALL set_table_property ('tbl1', 'auto_partitioning.num_retention', '2'); COMMIT;Insert data after the child partitions are generated.
INSERT INTO tbl1 (c1, c2) VALUES ('Data 1', '20231212'); INSERT INTO tbl1 (c1, c2) VALUES ('Data 2', '20231213'); INSERT INTO tbl1 (c1, c2) VALUES ('Data 3', '20231214');Query data.
SELECT * FROM tbl1 WHERE c2='20231212';The following result is returned:
c1 c2 Data 1 20231212
The logic for adding and deleting partitions is as follows:
Time | Event | Result |
2023-12-12 09:00:00 | Run the preceding SQL statements to create the partitioned table. |
|
2023-12-13 00:00:00 | The system automatically creates a child partitioned table. |
|
2023-12-14 00:00:00 | The system automatically creates a child partitioned table. |
|
2023-12-15 00:00:00 | The system automatically creates a child partitioned table and purges an expired one. |
|
2023-12-16 00:00:00 | The system automatically creates a child partitioned table and purges an expired one. |
|
Common scenarios
Retain a specific child partitioned table
By default, the system automatically creates and deletes child partitioned tables based on the configured dynamic partitioning rules. Child partitioned tables that are outside the retention range are automatically deleted. In some scenarios, you may need to retain data in important partitions. For example, in an E-commerce scenario, you may need to retain data from previous Double 11 shopping festivals for year-over-year and month-over-month analysis. To retain a specific child partitioned table, you can add the keep_alive property to it. The following syntax is used.
Syntax supported in Hologres V2.1 and later:
-- Retain a partition ALTER TABLE [<schema_name>.]<table_name> SET (keep_alive = 'true'); -- Stop retaining a partition. After the property is removed, dynamic partitioning immediately triggers a cleanup of expired data. ALTER TABLE [<schema_name>.]<table_name> SET (keep_alive = 'false');Syntax supported in all Hologres versions:
-- Retain a partition CALL set_table_property('[<schema_name>.]<table_name>', 'keep_alive', 'true'); -- Stop retaining a partition. After the property is removed, dynamic partitioning immediately triggers a cleanup of expired data. CALL set_table_property('[<schema_name>.]<table_name>', 'keep_alive', 'false');
Dynamically manage the storage medium for partitioned tables
When you work with partitioned tables, using tiered storage for hot and cold data can effectively balance cost and performance. For example, you can dynamically retain the last N historical partitions in hot storage to handle frequent queries. The M partitions before those can be stored in the cold layer to save costs. By combining this with the dynamic partitioning feature, you can also delete data that is older than all retained partitions.
Create a dynamic partitioned table
Example: Create one partition per day. Dynamically retain the last 7 historical partitions in hot storage and the 23 partitions before them in cold storage. Delete any partitions that are older than this range. The following sample code shows how to do this.
BEGIN;
CREATE TABLE tbl2(
c1 text not null,
c2 text
)
PARTITION BY LIST(c2);
CALL set_table_property('tbl2', 'auto_partitioning.enable', 'true');
CALL set_table_property('tbl2', 'auto_partitioning.time_unit', 'DAY');
CALL set_table_property('tbl2', 'auto_partitioning.num_precreate', '3');
CALL set_table_property('tbl2', 'auto_partitioning.num_hot', '7');
CALL set_table_property('tbl2', 'auto_partitioning.num_retention', '30');
COMMIT;The following figure shows the result.

Modify a storage policy
You can modify the hot storage policy by changing the value of the auto_partitioning.num_hot parameter. Note that if you modify this policy, child partitioned tables that are already in cold storage are not automatically moved back to hot storage. Assume that the current date is July 1, 2022, and you create the following partitioned table.
BEGIN;
CREATE TABLE tbl_p(
c1 text not null,
c2 text
)
PARTITION BY LIST(c2);
CALL set_table_property('tbl_p', 'auto_partitioning.enable', 'true');
CALL set_table_property('tbl_p', 'auto_partitioning.time_unit', 'DAY');
CALL set_table_property('tbl_p', 'auto_partitioning.num_precreate', '3');
CALL set_table_property('tbl_p', 'auto_partitioning.num_hot', '3');
CALL set_table_property('tbl_p', 'auto_partitioning.num_retention', '10');
COMMIT;The data distribution can change in the following two scenarios:
Scenario 1: Expanding a partition policy based on a hot storage cutoff
To change the number of hot partitions in the dynamic management policy to 4, run the following code:
CALL set_table_property('tbl_p', 'auto_partitioning.num_hot', '4');Because child partitioned tables that are already in cold storage are not automatically moved back to hot storage, the result is shown in the following figure:

Scenario 2: Decrease the number of partitions in hot storage
To set the number of hot partitions in the dynamic management policy to 2, run the following code:
CALL set_table_property('tbl_p', 'auto_partitioning.num_hot', '2');Child partitioned tables that are already in cold storage are not automatically moved to hot storage. However, data is still migrated from hot storage to cold storage. The effect of this change is shown in the following figure:

Convert a cold storage partitioned table to a dynamic partitioned table
For example, to convert a partitioned table with the cold storage property into a dynamically partitioned table and set the partitions from the last 7 days to hot storage, follow these steps.
Prepare the data.
-- Specify the cold storage medium when creating the table BEGIN; CREATE TABLE tbl2( c1 TEXT NOT NULL, c2 TEXT ) PARTITION BY LIST(c2); CALL set_table_property('tbl2', 'storage_mode', 'cold'); CREATE TABLE tbl2_20230808 PARTITION OF tbl2 FOR VALUES IN('20230808'); CREATE TABLE tbl2_20230809 PARTITION OF tbl2 FOR VALUES IN('20230809'); CREATE TABLE tbl2_20230810 PARTITION OF tbl2 FOR VALUES IN('20230810'); CREATE TABLE tbl2_20230817 PARTITION OF tbl2 FOR VALUES IN('20230817'); COMMIT;Modify the table to be a dynamically partitioned table and set the partitions from the last 7 days to hot storage.
BEGIN; CALL set_table_property('tbl2', 'storage_mode', 'hot'); --Set the parent table to hot CALL set_table_property('tbl2_20230810', 'storage_mode', 'cold'); --Set partitions that do not need to be moved to hot storage to cold CALL set_table_property('tbl2_20230809', 'storage_mode', 'cold'); CALL set_table_property('tbl2_20230808', 'storage_mode', 'cold'); CALL set_table_property('tbl2', 'auto_partitioning.enable', 'true'); CALL set_table_property('tbl2', 'auto_partitioning.time_unit', 'DAY'); CALL set_table_property('tbl2', 'auto_partitioning.num_precreate', '3'); CALL set_table_property('tbl2', 'auto_partitioning.num_hot', '7'); CALL set_table_property('tbl2', 'auto_partitioning.num_retention', '10'); COMMIT;
View dynamic partitioning configuration and scheduling status
You can run the following SQL statement to query information about dynamically partitioned tables and their configurations in the current database.
SELECT
nsp_name AS schema_name,
tbl_name AS table_name,
ENABLE,
time_unit,
time_zone,
num_precreate,
num_retention,
b.usename AS create_user,
cret_time,
schd_start_time,
options
FROM
hologres.hg_partitioning_config AS a
LEFT JOIN pg_user AS b ON a.cret_user = b.usesysid;The following describes the fields.
Field name | Description |
schema_name | The schema name. |
table_name | The table name. |
ENABLE | Indicates whether dynamic partitioning is enabled. |
time_unit | The time unit for dynamic partitioning. |
time_zone | The time zone setting for dynamic partitioning. |
num_precreate | The number of pre-created partitions. |
num_retention | The number of retained historical partitions. |
create_user | The user who created the table. |
cret_time | The creation time. |
schd_start_time | The most recent scheduled time. |
The following are the query results.

View logs for creating and purging child partitioned tables
Query Log does not record logs for creating and purging child partitioned tables. You can run the following SQL statement to query these logs.
SELECT
relname,
relowner,
schdtime,
trigtime,
status,
message,
precreate,
discard
FROM
hologres.hg_partitioning_log The following describes the fields.
Field name | Description |
relname | schema.table |
relowner | The owner of the partitioned table. |
schdtime | The scheduled time. |
trigtime | The actual trigger time. |
status | The status. |
message | The remarks. |
precreate | The name of the created child partitioned table. |
discard | The name of the purged child partitioned table. |
The query returns the following results.

FAQ
How do I enable dynamic partitioning for an existing partitioned table?
You can run the following SQL statements to enable dynamic partitioning for an existing partitioned table.
-- SQL example for Hologres V2.1 and later
ALTER TABLE auto_part_old SET (
auto_partitioning_enable = 'true',
auto_partitioning_time_unit = 'HOUR',
auto_partitioning_time_zone = 'PRC',
auto_partitioning_num_precreate = '4',
auto_partitioning_num_retention = '-1',
auto_partitioning_num_hot = '-1'
);
-- SQL example for all Hologres versions
BEGIN;
CALL set_table_property('auto_part_old', 'auto_partitioning.enable', 'true');
CALL set_table_property('auto_part_old', 'auto_partitioning.time_unit', 'HOUR');
CALL set_table_property('auto_part_old', 'auto_partitioning.time_zone', 'PRC');
CALL set_table_property('auto_part_old', 'auto_partitioning.num_precreate', '4');
CALL set_table_property('auto_part_old', 'auto_partitioning.num_retention', '-1');
CALL set_table_property('auto_part_old', 'auto_partitioning.num_hot', '-1');
COMMIT;The auto_partitioning.time_unit and auto_partitioning.time_zone parameters are core configurations for the dynamic partitioning feature. You can set these parameters only once, and they cannot be changed after they are set.
After I enable dynamic partitioning for an existing partitioned table, are the existing child partitioned tables affected by the automatic cleanup logic?
Yes, they are. The system purges child partitioned tables based on their names. If a child partitioned table's name follows the {parent_table}_{time_suffix} naming convention, it is purged. Otherwise, it is not.
I created a dynamic partitioned table and set num_precreate to 3. The parent table was created successfully, but the three child partitioned tables were not. Why?
For a newly created dynamic partitioning task, the system checks for the task every 10 minutes by default. Therefore, the child partitioned tables are created within 10 minutes. You can check for the tables again after this period.