pg_kpart
Overview
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 7450 | pg_kpart | No | Yes | Yes | No | No | Yes | - |
| Related | plan_filter pg_partman safeupdate block_copy_command pg_strict prioritize qos pg_readonly pgextwlist timescaledb |
|---|
Planner hook must be loaded through shared_preload_libraries or session_preload_libraries; CREATE EXTENSION is optional.
Version
| Type | Repo | Version | PG Ver | Package | Deps |
|---|---|---|---|---|---|
| EXT | PIGSTY | 1.0 | 1817161514 | pg_kpart | - |
| RPM | PIGSTY | 1.0 | 1817161514 | pg_kpart_$v | - |
| DEB | PIGSTY | 1.0 | 1817161514 | postgresql-$v-pg-kpart | - |
Build
You can build the RPM / DEB packages for pg_kpart using pig build:
Install
You can install pg_kpart directly. First, make sure the PGDG and PIGSTY repositories are added and enabled:
Install the extension using pig or apt/yum/dnf:
Preload:
Usage
Sources:
pg_kpart prevents accidental queries that would scan every leaf partition of a partitioned table without effective partition pruning. Its planner hook can raise, warn, or log before execution. The functional unit is the preloaded library; there are no SQL objects to create, and upstream describes CREATE EXTENSION only as optional catalog registration.
Enable and Roll Out
For cluster-wide enforcement, preload the library and restart PostgreSQL:
It can also be loaded for selected sessions or databases without a server restart:
Start in audit mode before enforcing errors:
Once the observed queries are understood, set pg_kpart.message_level = 'error'.
Scope and Behavior
Violations use SQLSTATE FS001, which applications can trap when message_level is error.
Configuration Index and Caveats
pg_kpart.enabled: master switch; defaulton.pg_kpart.message_level:error,warning,notice,log, and other PostgreSQL message levels.pg_kpart.min_partitions: minimum leaf-partition count to check; default2.pg_kpart.check_superuser: superusers bypass checks by default.pg_kpart.blacklisted: when nonempty, only named hierarchies are checked andwhitelistedis ignored.pg_kpart.whitelisted: hierarchies exempt from checking when no blacklist is set.- A predicate whose range still includes every partition is treated as a full scan and rejected, even if it mentions the partition key.
- The hook also applies to
UPDATE,DELETE, andEXPLAINwithoutANALYZE. It relies on PostgreSQL’s planned pruning result, not textual inspection ofWHEREclauses. - Upstream v1.0 is tested on PostgreSQL 14 and newer.
Was this page helpful?
Thanks—your feedback helps us improve this page.
What got in the way? (optional)