pg_kpart
pg_kpart : Reject full partition scans that omit the partition key
Overview
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
| --sL--r | No | Yes | Yes | No | yes | no |
| Relationships | |
|---|---|
| See Also | plan_filter pg_partman safeupdate block_copy_command pg_strict prioritize qos pg_readonly pgextwlist timescaledb |
Packages
| Type | Repo | Version | PG Major Compatibility | Package Pattern | Dependencies |
|---|---|---|---|---|---|
| EXT | PIGSTY | 1.0 |
18 17 16 15 14 | pg_kpart |
- |
| RPM | PIGSTY | 1.0 |
18 17 16 15 14 | pg_kpart_$v |
- |
| DEB | PIGSTY | 1.0 |
18 17 16 15 14 | postgresql-$v-pg-kpart |
- |
| Linux / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
| el8.x86_64 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 |
| el8.aarch64 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 |
| el9.x86_64 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 |
| el9.aarch64 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 |
| el10.x86_64 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 |
| el10.aarch64 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 |
| d12.x86_64 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 |
| d12.aarch64 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 |
| d13.x86_64 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 |
| d13.aarch64 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 |
| u22.x86_64 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 |
| u22.aarch64 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 |
| u24.x86_64 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 |
| u24.aarch64 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 |
| u26.x86_64 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 |
| u26.aarch64 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 |
Source
github.com/hexacluster/pg_kpart
pg_kpart-1.0.tar.gz
Install
Make sure PGDG and PIGSTY repo available:
Install this extension with pig:
Config this extension to shared_preload_libraries:
This extension does not need CREATE EXTENSION DDL command
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.