-
We're running pg_partman on our Zabbix installation with the history tables partitioned daily and the trends tables partitioned monthly. For some reason, a host tried to insert data from 1/12/2029 on 1/12/2024. We don't have that many partitions created so it went into the default partitions for some of these tables. The background worker ran and it failed which seems to have broke partitioning. I'm new to the partitioning/pg_partman world so not totally confident in the ins/outs but I assume this failed because it didn't have the trends_p2029_01 partition already created. We had the next 4 days (premake is 4 for the dailies) created (13-16th) and data was inserted as normal but the Jan 17th partition wasn't created on the 13th and so on which led to millions and even billions of records to be left in the default partition. I've since removed the 2029 data and started moving the data with partition_data_proc() but this takes a lot of time. Looking for prevention measures. My questions:
Error:
Table (post fix):
part_config for public.trends:
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Yes, this is the normal behavior when a default partition exists
If you want to have a default partition to avoid losing data, then any data outside the window of available children will get that data inserted to the default. There is no way to prevent it if the available child does not exist.
New partitions are made when the
The default partition is the standard behavior for pg_partman since I wanted its standard behavior to not be to lose data. Whether it is necessary or not is entirely up to you and if you'd rather PostgreSQL throw an error when data outside of the available children is inserted, you are free to drop it. partman will only create the default table when initially setting up the partition set and in versions 5.x and later there is now an option whether to create the default as a parameter to the Hopefully that answered all you're questions! Please let me know if you need further assistance. |
Beta Was this translation helpful? Give feedback.
-
Also for reference, versions 4.x and earlier did take into account data in the default partition when creating future partitions. This is why you were missing the partitions you needed and it was trying to make partitions in 2029. For version 5.x and later, data in the default partition is ignored for normal child table creation and if a new child table tries to be made that would match data in the default, that is when an error will be thrown. So hopefully if you're able to upgrade to 5.0, data going into the default will be less of a problem if you'd like to keep the default partition around. |
Beta Was this translation helpful? Give feedback.
Yes, this is the normal behavior when a default partition exists
If you want to have a default partition to avoid losing data, then any data outside the window of available children will get that data inserted to the default. There is no way to prevent it if the available child does not exist.
New partitions are made when the
run_maintenance()
orrun_maintenance_proc()
function is called via some scheduler app (cron, etc). Or the background w…