A partitioning method defines how PostgreSQL assigns table rows to partitions. For a large payments table, choosing RANGE on the timestamp separates data into time intervals, making maintenance easier than scanning or deleting from one enormous table. section 4.2
The method works with a partition key and partition boundaries. Here, tstamp is the key, while monthly FROM and TO values determine each partition’s interval. section 4.2
Monthly payment partitions
CREATE TABLE erp.payments_p (...) PARTITION BY RANGE (tstamp); CREATE TABLE erp.payments_p_2021_9 PARTITION OF erp.payments_p FOR VALUES FROM (<first day of month>) TO (<last day of month>); Dropping an old monthly partition takes about 43 milliseconds, compared with deleting historical rows from the unpartitioned table for about 66 seconds.
