Partition pruning excludes partitions that cannot contain matching rows. PostgreSQL can do this when a query predicates on the partition key, reducing the data it must scan. section 4.2
Time-partitioned payments
Partition a payments table by RANGE on tstamp into monthly partitions. A query for one timestamp scans only payments_p_2022_3 instead of the entire table; the demonstrated runtime falls from about 62 seconds to 2.5 seconds.
Use the query plan to verify pruning:
- Include the partition key in the predicate; otherwise the planner cannot exclude partitions based on that condition. section 4.2
- Treat pruning as a complement to partitioning: smaller scans help performance, while dropping a whole old partition simplifies maintenance. section 4.2


