plan_filter
Overview
| Package | Version | Category | License | Language |
|---|---|---|---|---|
pg_plan_filter | 0.0.1 | FEAT | PostgreSQL | C |
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 2810 | plan_filter | No | Yes | Yes | No | No | No | - |
| Related | pg_hint_plan pg_kpart pg_command_fw hypopg index_advisor pg_qualstats online_advisor block_copy_command pg_stat_plans pg_readonly |
|---|
Version
| Type | Repo | Version | PG Ver | Package | Deps |
|---|---|---|---|---|---|
| EXT | PIGSTY | 0.0.1 | 1817161514 | pg_plan_filter | - |
| RPM | PIGSTY | 0.0.1 | 1817161514 | pg_plan_filter_$v | - |
| DEB | PIGSTY | 0.0.1 | 1817161514 | postgresql-$v-pg-plan-filter | - |
Build
You can build the RPM / DEB packages for pg_plan_filter using pig build:
Install
You can install pg_plan_filter directly. First, make sure the PGDG and PIGSTY repositories are added and enabled:
Install the extension using pig or apt/yum/dnf:
Preload:
Usage
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:
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:
Limit filtering to SELECT statements only (note: SELECT != READONLY, since SELECT can also modify data):
When the module is running with a non-zero statement_cost_limit, it will also prevent EXPLAIN on expensive queries. Temporarily bypass the filter:
Override the limit per user:
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.
Was this page helpful?
Thanks—your feedback helps us improve this page.
What got in the way? (optional)