user3118602
user3118602

Reputation: 583

Clarification needed for pg_partman premake

I have read and did my own testing and hence why I would appreciate for someone to clarify the question I have.

Now assume I created a table with partition by date range, and I used the following to create the parent table in pg_partman:

SELECT partman.create_parent(
    p_parent_table := 'test.table_abc',
    p_control := 'timestamp',
    p_type := 'range',
    p_interval := '1 month',
    p_premake := 4,  -- Set premake to 0
);

The month I run this query is November 2024. By running this, I understand that pg_partman will premake 4 partitions by month.

What I am expecting from pg_partman partition tables after running the above query is:

table_abc_default
table_abc_20241101
table_abc_20241201
table_abc_20250101
table_abc_20250201
table_abc_20250301

However, when I do this practise/test in my PostgreSQL, it gives me:

table_abc_default
table_abc_20240701
table_abc_20240801
table_abc_20240901
table_abc_20241001
table_abc_20241101
table_abc_20241201
table_abc_20250101
table_abc_20250201
table_abc_20250301

Notice that it created 8 partition tables, before and after from the month I run the query (which is Nov).

Shouldn't pg_partman just premake the future partitions, which are Dec-2024 to Mar-2025?

Now if I declare p_start_partition := '2024-01-01' in create parent, it will create from this start month + the future partition of 4 which is correct.

My question is - without declaring a p_start_partition, is it right to say that pg_partman premake will create before and after partitions?

Edit:

Heads up I did consult GenAI... and this is what it told me:

If you do not set p_start_partition, pg_partman will create partitions starting from the current date (or interval) based on the p_interval you specify (e.g., monthly).

It will not create partitions for historical data automatically, so data older than the current range will be inserted into the default partition.

However in my test, this is not true and therefore I need some clarification.

Upvotes: 0

Views: 178

Answers (0)

Related Questions