All Products
Search
Document Center

Hologres:Dynamic partitioning

Last Updated:Dec 25, 2025

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_time property 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_format parameter 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.

    Note

    Realtime 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 BY clause supports only list 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_format parameter 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_format parameter, 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

Important

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

auto_partitioning_enable/auto_partitioning.enable

No

Specifies whether to enable dynamic partitioning. Valid values:

  • true: enables dynamic partitioning.

  • false (default): disables dynamic partitioning.

Yes

Hologres V1.3 and later

auto_partitioning_time_unit/auto_partitioning.time_unit

Yes

The time unit for dynamic partitioning. Valid values:

  • HOUR

  • DAY

  • MONTH

  • QUARTER

  • YEAR

For example, if you set this parameter to DAY, partitions are pre-created and deleted by day.

No

auto_partitioning_time_zone/auto_partitioning.time_zone

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.

SELECT * FROM pg_timezone_names;

No

auto_partitioning_num_precreate/auto_partitioning.num_precreate

No

The number of partitions to pre-create. Valid values:

  • 0: No partitions are pre-created.

  • [1, 512]: Creates partitions based on the current time. Set this value to 2 or greater. The default value is 4.

Note

For example, if the current date is 2022-01-10, and you set time_unit = DAY, num_precreate = 3, partitions for 2022-01-10, 2022-01-11, and 2022-01-12 are created.

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

auto_partitioning_num_retention/auto_partitioning.num_retention

No

The number of historical partitions to retain. Valid values:

  • 0: No historical partitions are retained.

  • -1 (default): All historical partitions are retained.

  • A positive integer: Retains N historical partitions. The maximum value is 512.

Run set hg_experimental_auto_part_max_maintained_partitions=<value>; to adjust the number of retained partitions. The maximum value is 8760.

Note

For example, if the current date is 2022-01-10, and you set <time_unit = DAY, num_retention = 3>, partitions for 2022-01-09, 2022-01-08, and 2022-01-07 are retained. Historical partitions older than 2022-01-07 are deleted.

Yes

auto_partitioning_num_hot/auto_partitioning.num_hot

No

The number of hot partitions to retain. Valid values:

  • 0: No hot partitions are retained.

  • -1 (default): All hot partitions are retained.

  • A positive integer: Retains N hot partitions. The maximum value is 512.

Hologres V1.3.37 and later

auto_partitioning_schd_start_time/auto_partitioning.schd_start_time

No

The custom scheduled time for partitioning. If auto_partitioning.time_unit is set to HOUR, the default scheduled time is at the top of every hour. For other values, the default is 00:00:01 of the day.

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

auto_partitioning_time_format/auto_partitioning.time_format

No

Specifies the date and time format of the partition key when creating a table.

  • Default formats: YYYYMMDDHH24 (HOUR), YYYYMMDD (DAY), YYYYMM (MONTH), YYYYQ (QUARTER), and YYYY (YEAR).

  • Optional formats: YYYY-MM-DD-HH24 (HOUR), YYYY-MM-DD (DAY), YYYY-MM (MONTH), and YYYY-Q (QUARTER).

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

  1. 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'
    );
    
  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');
  3. Query data.

    SELECT * FROM tbl1 WHERE c2='20231212';

    The following result is returned:

    c1	     c2
    Data 1   20231212

Example with the CALL command

  1. 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;
  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');
  3. 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.

  • Parent partitioned table created: tbl1

  • Child partitioned tables created: tbl1_20231212, tbl1_20231213, tbl1_20231214

2023-12-13 00:00:00

The system automatically creates a child partitioned table.

  • Child partitioned table created: tbl1_20231215

2023-12-14 00:00:00

The system automatically creates a child partitioned table.

  • Child partitioned table created: tbl1_20231216

2023-12-15 00:00:00

The system automatically creates a child partitioned table and purges an expired one.

  • Child partitioned table created: tbl1_20231217

  • Child partitioned table purged: tbl1_20231212

2023-12-16 00:00:00

The system automatically creates a child partitioned table and purges an expired one.

  • Child partitioned table created: tbl1_20231218

  • Child partitioned table purged: tbl1_20231213

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.

  1. 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;
  2. 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.

image

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.

image

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;
Important

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.