plan_filter

plan_filter

pg_plan_filter : filter statements by their execution plans.

Overview

ID Extension Package Version Category License Language
2810
plan_filter
pg_plan_filter
0.0.1
FEAT
PostgreSQL
C
Attribute Has Binary Has Library Need Load Has DDL Relocatable Trusted
--sL---
No
Yes
Yes
No
no
no
Relationships
See Also
age
hll
rum
pg_graphql
pg_jsonschema
jsquery
pg_hint_plan
hypopg

Packages

Type Repo Version PG Major Compatibility Package Pattern Dependencies
EXT
PIGSTY
0.0.1
18
17
16
15
14
pg_plan_filter -
RPM
PIGSTY
0.0.1
18
17
16
15
14
pg_plan_filter_$v -
DEB
PIGSTY
0.0.1
18
17
16
15
14
postgresql-$v-pg-plan-filter -
Linux / PG PG18 PG17 PG16 PG15 PG14
el8.x86_64
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
el8.aarch64
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
el9.x86_64
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
el9.aarch64
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
el10.x86_64
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
el10.aarch64
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
d12.x86_64
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
d12.aarch64
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
d13.x86_64
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
d13.aarch64
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
u22.x86_64
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
u22.aarch64
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
u24.x86_64
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
u24.aarch64
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
PIGSTY 0.0.1
Package Version OS ORG SIZE File URL
pg_plan_filter_18 0.0.1 el8.x86_64 pigsty 10.8 KiB pg_plan_filter_18-0.0.1-1PIGSTY.el8.x86_64.rpm
pg_plan_filter_18 0.0.1 el8.aarch64 pigsty 11.0 KiB pg_plan_filter_18-0.0.1-1PIGSTY.el8.aarch64.rpm
pg_plan_filter_18 0.0.1 el9.x86_64 pigsty 10.5 KiB pg_plan_filter_18-0.0.1-1PIGSTY.el9.x86_64.rpm
pg_plan_filter_18 0.0.1 el9.aarch64 pigsty 10.5 KiB pg_plan_filter_18-0.0.1-1PIGSTY.el9.aarch64.rpm
pg_plan_filter_18 0.0.1 el10.x86_64 pigsty 10.4 KiB pg_plan_filter_18-0.0.1-1PIGSTY.el10.x86_64.rpm
pg_plan_filter_18 0.0.1 el10.aarch64 pigsty 10.6 KiB pg_plan_filter_18-0.0.1-1PIGSTY.el10.aarch64.rpm
postgresql-18-pg-plan-filter 0.0.1 d12.x86_64 pigsty 9.9 KiB postgresql-18-pg-plan-filter_0.0.1-1PIGSTY~bookworm_amd64.deb
postgresql-18-pg-plan-filter 0.0.1 d12.aarch64 pigsty 10.1 KiB postgresql-18-pg-plan-filter_0.0.1-1PIGSTY~bookworm_arm64.deb
postgresql-18-pg-plan-filter 0.0.1 d13.x86_64 pigsty 9.9 KiB postgresql-18-pg-plan-filter_0.0.1-1PIGSTY~trixie_amd64.deb
postgresql-18-pg-plan-filter 0.0.1 d13.aarch64 pigsty 10.1 KiB postgresql-18-pg-plan-filter_0.0.1-1PIGSTY~trixie_arm64.deb
postgresql-18-pg-plan-filter 0.0.1 u22.x86_64 pigsty 10.1 KiB postgresql-18-pg-plan-filter_0.0.1-1PIGSTY~jammy_amd64.deb
postgresql-18-pg-plan-filter 0.0.1 u22.aarch64 pigsty 10.1 KiB postgresql-18-pg-plan-filter_0.0.1-1PIGSTY~jammy_arm64.deb
postgresql-18-pg-plan-filter 0.0.1 u24.x86_64 pigsty 10.1 KiB postgresql-18-pg-plan-filter_0.0.1-1PIGSTY~noble_amd64.deb
postgresql-18-pg-plan-filter 0.0.1 u24.aarch64 pigsty 10.2 KiB postgresql-18-pg-plan-filter_0.0.1-1PIGSTY~noble_arm64.deb
Package Version OS ORG SIZE File URL
pg_plan_filter_17 0.0.1 el8.x86_64 pigsty 10.8 KiB pg_plan_filter_17-0.0.1-1PIGSTY.el8.x86_64.rpm
pg_plan_filter_17 0.0.1 el8.aarch64 pigsty 11.0 KiB pg_plan_filter_17-0.0.1-1PIGSTY.el8.aarch64.rpm
pg_plan_filter_17 0.0.1 el9.x86_64 pigsty 10.5 KiB pg_plan_filter_17-0.0.1-1PIGSTY.el9.x86_64.rpm
pg_plan_filter_17 0.0.1 el9.aarch64 pigsty 10.5 KiB pg_plan_filter_17-0.0.1-1PIGSTY.el9.aarch64.rpm
pg_plan_filter_17 0.0.1 el10.x86_64 pigsty 10.5 KiB pg_plan_filter_17-0.0.1-1PIGSTY.el10.x86_64.rpm
pg_plan_filter_17 0.0.1 el10.aarch64 pigsty 10.7 KiB pg_plan_filter_17-0.0.1-1PIGSTY.el10.aarch64.rpm
postgresql-17-pg-plan-filter 0.0.1 d12.x86_64 pigsty 9.9 KiB postgresql-17-pg-plan-filter_0.0.1-1PIGSTY~bookworm_amd64.deb
postgresql-17-pg-plan-filter 0.0.1 d12.aarch64 pigsty 10.1 KiB postgresql-17-pg-plan-filter_0.0.1-1PIGSTY~bookworm_arm64.deb
postgresql-17-pg-plan-filter 0.0.1 d13.x86_64 pigsty 9.9 KiB postgresql-17-pg-plan-filter_0.0.1-1PIGSTY~trixie_amd64.deb
postgresql-17-pg-plan-filter 0.0.1 d13.aarch64 pigsty 10.1 KiB postgresql-17-pg-plan-filter_0.0.1-1PIGSTY~trixie_arm64.deb
postgresql-17-pg-plan-filter 0.0.1 u22.x86_64 pigsty 10.6 KiB postgresql-17-pg-plan-filter_0.0.1-1PIGSTY~jammy_amd64.deb
postgresql-17-pg-plan-filter 0.0.1 u22.aarch64 pigsty 10.6 KiB postgresql-17-pg-plan-filter_0.0.1-1PIGSTY~jammy_arm64.deb
postgresql-17-pg-plan-filter 0.0.1 u24.x86_64 pigsty 10.2 KiB postgresql-17-pg-plan-filter_0.0.1-1PIGSTY~noble_amd64.deb
postgresql-17-pg-plan-filter 0.0.1 u24.aarch64 pigsty 10.3 KiB postgresql-17-pg-plan-filter_0.0.1-1PIGSTY~noble_arm64.deb
Package Version OS ORG SIZE File URL
pg_plan_filter_16 0.0.1 el8.x86_64 pigsty 10.8 KiB pg_plan_filter_16-0.0.1-1PIGSTY.el8.x86_64.rpm
pg_plan_filter_16 0.0.1 el8.aarch64 pigsty 11.0 KiB pg_plan_filter_16-0.0.1-1PIGSTY.el8.aarch64.rpm
pg_plan_filter_16 0.0.1 el9.x86_64 pigsty 10.5 KiB pg_plan_filter_16-0.0.1-1PIGSTY.el9.x86_64.rpm
pg_plan_filter_16 0.0.1 el9.aarch64 pigsty 10.5 KiB pg_plan_filter_16-0.0.1-1PIGSTY.el9.aarch64.rpm
pg_plan_filter_16 0.0.1 el10.x86_64 pigsty 10.5 KiB pg_plan_filter_16-0.0.1-1PIGSTY.el10.x86_64.rpm
pg_plan_filter_16 0.0.1 el10.aarch64 pigsty 10.7 KiB pg_plan_filter_16-0.0.1-1PIGSTY.el10.aarch64.rpm
postgresql-16-pg-plan-filter 0.0.1 d12.x86_64 pigsty 9.9 KiB postgresql-16-pg-plan-filter_0.0.1-1PIGSTY~bookworm_amd64.deb
postgresql-16-pg-plan-filter 0.0.1 d12.aarch64 pigsty 10.0 KiB postgresql-16-pg-plan-filter_0.0.1-1PIGSTY~bookworm_arm64.deb
postgresql-16-pg-plan-filter 0.0.1 d13.x86_64 pigsty 9.9 KiB postgresql-16-pg-plan-filter_0.0.1-1PIGSTY~trixie_amd64.deb
postgresql-16-pg-plan-filter 0.0.1 d13.aarch64 pigsty 10.1 KiB postgresql-16-pg-plan-filter_0.0.1-1PIGSTY~trixie_arm64.deb
postgresql-16-pg-plan-filter 0.0.1 u22.x86_64 pigsty 10.6 KiB postgresql-16-pg-plan-filter_0.0.1-1PIGSTY~jammy_amd64.deb
postgresql-16-pg-plan-filter 0.0.1 u22.aarch64 pigsty 10.6 KiB postgresql-16-pg-plan-filter_0.0.1-1PIGSTY~jammy_arm64.deb
postgresql-16-pg-plan-filter 0.0.1 u24.x86_64 pigsty 10.2 KiB postgresql-16-pg-plan-filter_0.0.1-1PIGSTY~noble_amd64.deb
postgresql-16-pg-plan-filter 0.0.1 u24.aarch64 pigsty 10.3 KiB postgresql-16-pg-plan-filter_0.0.1-1PIGSTY~noble_arm64.deb
Package Version OS ORG SIZE File URL
pg_plan_filter_15 0.0.1 el8.x86_64 pigsty 10.8 KiB pg_plan_filter_15-0.0.1-1PIGSTY.el8.x86_64.rpm
pg_plan_filter_15 0.0.1 el8.aarch64 pigsty 11.0 KiB pg_plan_filter_15-0.0.1-1PIGSTY.el8.aarch64.rpm
pg_plan_filter_15 0.0.1 el9.x86_64 pigsty 10.5 KiB pg_plan_filter_15-0.0.1-1PIGSTY.el9.x86_64.rpm
pg_plan_filter_15 0.0.1 el9.aarch64 pigsty 10.5 KiB pg_plan_filter_15-0.0.1-1PIGSTY.el9.aarch64.rpm
pg_plan_filter_15 0.0.1 el10.x86_64 pigsty 10.5 KiB pg_plan_filter_15-0.0.1-1PIGSTY.el10.x86_64.rpm
pg_plan_filter_15 0.0.1 el10.aarch64 pigsty 10.7 KiB pg_plan_filter_15-0.0.1-1PIGSTY.el10.aarch64.rpm
postgresql-15-pg-plan-filter 0.0.1 d12.x86_64 pigsty 9.9 KiB postgresql-15-pg-plan-filter_0.0.1-1PIGSTY~bookworm_amd64.deb
postgresql-15-pg-plan-filter 0.0.1 d12.aarch64 pigsty 10.1 KiB postgresql-15-pg-plan-filter_0.0.1-1PIGSTY~bookworm_arm64.deb
postgresql-15-pg-plan-filter 0.0.1 d13.x86_64 pigsty 9.9 KiB postgresql-15-pg-plan-filter_0.0.1-1PIGSTY~trixie_amd64.deb
postgresql-15-pg-plan-filter 0.0.1 d13.aarch64 pigsty 10.1 KiB postgresql-15-pg-plan-filter_0.0.1-1PIGSTY~trixie_arm64.deb
postgresql-15-pg-plan-filter 0.0.1 u22.x86_64 pigsty 10.5 KiB postgresql-15-pg-plan-filter_0.0.1-1PIGSTY~jammy_amd64.deb
postgresql-15-pg-plan-filter 0.0.1 u22.aarch64 pigsty 10.6 KiB postgresql-15-pg-plan-filter_0.0.1-1PIGSTY~jammy_arm64.deb
postgresql-15-pg-plan-filter 0.0.1 u24.x86_64 pigsty 10.2 KiB postgresql-15-pg-plan-filter_0.0.1-1PIGSTY~noble_amd64.deb
postgresql-15-pg-plan-filter 0.0.1 u24.aarch64 pigsty 10.3 KiB postgresql-15-pg-plan-filter_0.0.1-1PIGSTY~noble_arm64.deb
Package Version OS ORG SIZE File URL
pg_plan_filter_14 0.0.1 el8.x86_64 pigsty 10.8 KiB pg_plan_filter_14-0.0.1-1PIGSTY.el8.x86_64.rpm
pg_plan_filter_14 0.0.1 el8.aarch64 pigsty 11.0 KiB pg_plan_filter_14-0.0.1-1PIGSTY.el8.aarch64.rpm
pg_plan_filter_14 0.0.1 el9.x86_64 pigsty 10.5 KiB pg_plan_filter_14-0.0.1-1PIGSTY.el9.x86_64.rpm
pg_plan_filter_14 0.0.1 el9.aarch64 pigsty 10.5 KiB pg_plan_filter_14-0.0.1-1PIGSTY.el9.aarch64.rpm
pg_plan_filter_14 0.0.1 el10.x86_64 pigsty 10.5 KiB pg_plan_filter_14-0.0.1-1PIGSTY.el10.x86_64.rpm
pg_plan_filter_14 0.0.1 el10.aarch64 pigsty 10.7 KiB pg_plan_filter_14-0.0.1-1PIGSTY.el10.aarch64.rpm
postgresql-14-pg-plan-filter 0.0.1 d12.x86_64 pigsty 9.9 KiB postgresql-14-pg-plan-filter_0.0.1-1PIGSTY~bookworm_amd64.deb
postgresql-14-pg-plan-filter 0.0.1 d12.aarch64 pigsty 10.0 KiB postgresql-14-pg-plan-filter_0.0.1-1PIGSTY~bookworm_arm64.deb
postgresql-14-pg-plan-filter 0.0.1 d13.x86_64 pigsty 9.8 KiB postgresql-14-pg-plan-filter_0.0.1-1PIGSTY~trixie_amd64.deb
postgresql-14-pg-plan-filter 0.0.1 d13.aarch64 pigsty 10.1 KiB postgresql-14-pg-plan-filter_0.0.1-1PIGSTY~trixie_arm64.deb
postgresql-14-pg-plan-filter 0.0.1 u22.x86_64 pigsty 10.5 KiB postgresql-14-pg-plan-filter_0.0.1-1PIGSTY~jammy_amd64.deb
postgresql-14-pg-plan-filter 0.0.1 u22.aarch64 pigsty 10.6 KiB postgresql-14-pg-plan-filter_0.0.1-1PIGSTY~jammy_arm64.deb
postgresql-14-pg-plan-filter 0.0.1 u24.x86_64 pigsty 10.1 KiB postgresql-14-pg-plan-filter_0.0.1-1PIGSTY~noble_amd64.deb
postgresql-14-pg-plan-filter 0.0.1 u24.aarch64 pigsty 10.2 KiB postgresql-14-pg-plan-filter_0.0.1-1PIGSTY~noble_arm64.deb

Source

pig build pkg pg_plan_filter;		# build rpm/deb

Install

Make sure PGDG and PIGSTY repo available:

pig repo add pgsql -u   # add both repo and update cache

Install this extension with pig:

pig install pg_plan_filter;		# install via package name, for the active PG version
pig install plan_filter;		# install by extension name, for the current active PG version

pig install plan_filter -v 18;   # install for PG 18
pig install plan_filter -v 17;   # install for PG 17
pig install plan_filter -v 16;   # install for PG 16
pig install plan_filter -v 15;   # install for PG 15
pig install plan_filter -v 14;   # install for PG 14

Config this extension to shared_preload_libraries:

shared_preload_libraries = 'plan_filter';

This extension does not need CREATE EXTENSION DDL command

Usage

plan_filter: filter statements by their execution plans

The pg_plan_filter module tests statements against specific configured criteria before execution, raising an error if the criteria are violated. This allows administrators to prevent execution of certain queries on production databases.

The only criterion currently supported is the maximum allowed estimated cost of the statement plan.

Configuration

Add to postgresql.conf:

shared_preload_libraries = 'plan_filter'
plan_filter.statement_cost_limit = 100000.0

The statement_cost_limit must be set to a non-zero value to enable filtering. The default is 0 (no filtering).

GUC Parameters

Parameter Type Default Description
plan_filter.statement_cost_limit float 0 Maximum allowed estimated plan cost. 0 disables filtering
plan_filter.limit_select_only bool false When true, only filter SELECT statements

Examples

Prevent expensive queries globally:

plan_filter.statement_cost_limit = 100000.0

Limit filtering to SELECT statements only (note: SELECT != READONLY, since SELECT can also modify data):

plan_filter.limit_select_only = true

When the module is running with a non-zero statement_cost_limit, it will also prevent EXPLAIN on expensive queries. Temporarily bypass the filter:

BEGIN;
SET LOCAL plan_filter.statement_cost_limit = 0;
EXPLAIN SELECT ...;
COMMIT;

Override the limit per user:

ALTER USER can_run_expensive SET plan_filter.statement_cost_limit = 0;
ALTER USER only_cheap_queries SET plan_filter.statement_cost_limit = 10000;

Caveats

The statement_cost_limit cancels plans based on their estimated cost. The PostgreSQL planner can return cost estimates unrelated to actual query execution time. Be prepared for false positive cancellations and set the limit generously.

Last updated on