pg_kpart is a PostgreSQL extension that prevents accidental full-partition scans by rejecting queries that lack a usable predicate on the partition key. It installs a planner hook that inspects Append/MergeAppend nodes and raises a configurable error (SQLSTATE FS001) when no partition pruning occurs. The extension supports audit mode (warning level), blacklist/whitelist scoping to target specific tables, a superuser bypass toggle, and a minimum partition count threshold. It works on SELECT, UPDATE, DELETE, and EXPLAIN without ANALYZE, and has been tested on PostgreSQL 13+. The performance difference it prevents can be four orders of magnitude in I/O and latency on large partitioned tables.

9m read timeFrom postgr.es
Post cover image
Table of contents
What pg_kpart doesHow it worksA quick illustrationWhy this matters: the I/O differenceBuilding and enabling the extensionConfigurationNotes and limitationsConclusion
281 Impressions