pg_plan_guard
pg_plan_guard · Detect drift from captured PostgreSQL query plan baselines
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 6100 | pg_plan_guard | pg_plan_guard | 1.1.12 | STAT | Apache-2.0 | PLpgSQL |
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
| ----d-- | No | No | No | Yes | no | no |
| Relationships | |
|---|---|
| Schemas | plan_guard |
| See Also | pg_hint_plan plan_filter pg_qualstats auto_explain pg_show_plans pg_overexplain pg_plan_advice pg_stash_advice pg_living_assertions |
Packages
| Linux / PG | PG19 | PG18 | PG17 | PG16 | PG15 |
|---|---|---|---|---|---|
| el8.x86_64 | N/A | N/A | N/A | N/A | N/A |
| el8.aarch64 | N/A | N/A | N/A | N/A | N/A |
| el9.x86_64 | PIGSTY 1.1.12 | N/A | N/A | N/A | N/A |
| el9.aarch64 | PIGSTY 1.1.12 | N/A | N/A | N/A | N/A |
| el10.x86_64 | PIGSTY 1.1.12 | N/A | N/A | N/A | N/A |
| el10.aarch64 | PIGSTY 1.1.12 | N/A | N/A | N/A | N/A |
| d12.x86_64 | PIGSTY 1.1.12 | N/A | N/A | N/A | N/A |
| d12.aarch64 | PIGSTY 1.1.12 | N/A | N/A | N/A | N/A |
| d13.x86_64 | PIGSTY 1.1.12 | N/A | N/A | N/A | N/A |
| d13.aarch64 | PIGSTY 1.1.12 | N/A | N/A | N/A | N/A |
| u22.x86_64 | PIGSTY 1.1.12 | N/A | N/A | N/A | N/A |
| u22.aarch64 | PIGSTY 1.1.12 | N/A | N/A | N/A | N/A |
| u24.x86_64 | PIGSTY 1.1.12 | N/A | N/A | N/A | N/A |
| u24.aarch64 | PIGSTY 1.1.12 | N/A | N/A | N/A | N/A |
| u26.x86_64 | PIGSTY 1.1.12 | N/A | N/A | N/A | N/A |
| u26.aarch64 | PIGSTY 1.1.12 | N/A | N/A | N/A | N/A |
Source
github.com/Manuelreyesbravo/pg_plan_guard
pg_plan_guard-1.1.12.tar.gz
Install
Make sure PGDG and PIGSTY repo available:
Install this extension with pig:
Create this extension with:
Usage
Sources:
- README.md
- pg_plan_guard.control
- CHANGELOG.md
- pg_plan_guard–1.1.10–1.1.11.sql
- pg_plan_guard–1.1.11–1.1.12.sql
pg_plan_guard 1.1.12 records approved PostgreSQL 19 plan-advice text and detects changes when stored queries are replanned. Plan capture loads the PostgreSQL 19 contrib library pg_plan_advice. For monitoring roles without superuser privileges, preload the library in shared_preload_libraries.
Core Workflow
Operational Boundaries
plan_guard.capture() records a query, its advice, author and search path. plan_guard.verify() replans it, and plan_guard.status exposes state; plan_guard.drift_log records transitions and rejects modification. Planning happens read-only in a rolled-back subtransaction as the captured author, so the checking role must be allowed to assume that role. A baseline from before 1.1.7 has no author and must be captured again; otherwise it returns an error. The installer rejects a pre-created schema owned by an unrelated unprivileged role. Planning can invoke functions, so stored SQL must still be trusted and the baseline reviewed. plan_guard.watch() optionally uses pg_living_assertions 0.5.6 or later; ordinary capture/verification do not require it. plan_guard.sync_stash() additionally needs pg_stash_advice preload, restart and a configured stash. Current Apache-2.0 licensing starts at 1.1.3.
Role Isolation in 1.1.9
Version 1.1.9 plans stored SQL inside a temporary author-owned SECURITY DEFINER function when role isolation is needed. A function evaluated by the planner can no longer regain the runner’s identity by resetting role or session authorization. The function is created and rolled back inside the read-only planning subtransaction. The author needs database TEMP permission when this frame is required; the runner needs authority to act as the author. Missing privileges produce a baseline error. This fixes the role-reset escape in 1.1.7/1.1.8 without turning stored SQL into untrusted input.
1.1.11 Compatibility and Dependencies
Version 1.1.11 refuses CREATE EXTENSION on PostgreSQL 18 and earlier because pg_plan_advice is available only on PostgreSQL 19. The PGXN META metadata treats pg_plan_advice as required and pg_living_assertions as optional for watch(). sync_stash() resolves pg_stash_advice in the installation schema, and reports a failed action when that companion extension is absent. The current SQL version is 1.1.12; use the supplied upgrade path and reconnect after replacing files.
1.1.10 Watch Privileges
Version 1.1.10 revokes PUBLIC execution of plan_guard.watch(). Grant it explicitly only to trusted operators that may register monitoring work. This does not remove the captured-author isolation, database TEMP or role-assumption requirements of 1.1.9.
Current Compatibility
Version 1.1.12 updates documentation and tested compatibility without changing SQL objects. Upstream records PostgreSQL 19.0 coverage. The supplied 1.1.11-to-1.1.12 SQL update advances the extension version only; keep the earlier role and dependency requirements above.