pg_stat_sql_plans
pg_stat_sql_plans · Track execution statistics by normalized SQL query and plan ID.
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 100488 | pg_stat_sql_plans | pg_stat_sql_plans | 0.2 | STAT | PostgreSQL | C |
PostgreSQL · 14, 15, 16, 17, 18
Usage
Sources:
pg_stat_sql_plans 0.2 is an alpha fork of pg_stat_statements that tracks statistics by normalized query ID and plan ID. It can distinguish plan changes for the same SQL shape and retain planning, execution, extension, failure, first-call, and last-call information; upstream explicitly says not to use it in production.
Core Workflow
For the reviewed branch, use PostgreSQL 14 or later, preload the module, disable core query-ID computation, restart, and create the extension.
pg_stat_sql_plans stores one row per query-and-plan pair. pg_stat_sql_plans_agg rolls rows up by query. pgssp_backend_qpid(pid) exposes the most recent query-plan identifier for a backend, pgssp_normalize_query(text) normalizes SQL text, and pg_stat_sql_plans_reset() clears collected entries.
Settings and Caveats
Important settings include pg_stat_sql_plans.max, pg_stat_sql_plans.plan_type, pg_stat_sql_plans.track, pg_stat_sql_plans.track_errors, pg_stat_sql_plans.track_pid, pg_stat_sql_plans.track_utility, pg_stat_sql_plans.save, and pg_stat_sql_plans.explain. Plan hashing and optional plan logging add planning, memory, and log overhead; stored query text can contain literals. Restrict access, measure overhead, and treat IDs as implementation-derived diagnostics rather than portable identities.