I have a partitioned table that have a partition named tablename_default and also a pool of partitions created the first time. Now tablename_default has records that go beyond the monthly partition parameter and when i run pg_partman.run_maintenance() the upcoming error its
SQL Error [P0001]: ERROR: updated partition constraint for default partition would be violated by some row
CONTEXT: SQL statement "ALTER TABLE raw.bupa_trace_resultados ATTACH PARTITION raw.bupa_trace_resultados_p2023_11 FOR VALUES FROM ('2023-11-01 00:00:00-03') TO ('2023-12-01 00:00:00-03')"
PL/pgSQL function create_partition_time(text,timestamp with time zone[],boolean,boolean) line 222 at EXECUTE
PL/pgSQL function partman.run_maintenance(text,boolean,boolean,boolean) line 280 at assignment
DETAIL:
HINT:
CONTEXT: PL/pgSQL function create_partition_time(text,timestamp with time zone[],boolean,boolean) line 442 at RAISE
PL/pgSQL function partman.run_maintenance(text,boolean,boolean,boolean) line 280 at assignment
DETAIL:
HINT:
Where: PL/pgSQL function partman.run_maintenance(text,boolean,boolean,boolean) line 398 at RAISE
I think it may be because the default_table has records that are going to fall into the partitions that are about to be created, so the constraint is triggered.
Can you please help me?
I tried running partman.run_maintenance() with the verbosity parameters to get more details, but I only referred to the create_partition_time function where I couldn't get any more answers.
What I am looking for is that as the additional partitions are created when running run_maintenance, the records that exist in the default_table are emptied in the new partitions created
As far as I understand that is not possible. I am no expert but if you have data in your default partition you can run:
to move it out and to the partitioned tables. I think you will have to make sure you are calling
partman.run_maintenance
before data gets inserted into the default partition.