pg_stat_query_plans
pg_stat_query_plans · Track SQL statement and execution-plan statistics in shared memory
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 102002 | pg_stat_query_plans | pg_stat_query_plans | 1.0 | STAT | Apache-2.0 | C |
Usage
Sources:
pg_stat_query_plans 1.0 tracks statements and their execution plans in shared memory. Use its separate query and plan views to identify changes in execution behavior; it is an independent module, not an additional view installed by pg_stat_statements.
Enablement and Core Workflow
Add the module to the existing preload list, restart PostgreSQL, and create the extension in each database where the views are needed:
Objects and Configuration
pg_stat_query_plans_sqlgroups measurements by database, user, query identifier, and top-level status.pg_stat_query_plansfurther separates plan identifiers and includes representative query text, normalized plans, and example plans.pg_stat_query_plans_infoexposes allocation, text storage, eviction, and reset information.pg_stat_query_plans.trackselects which statements to collect;pg_stat_query_plans.track_planningenables planning-time measurement and is off by default.pg_stat_query_plans_reset(userid, dbid, queryid)resets matching statistics; zero arguments select all entries.pg_stat_query_plans_reset_minmax()clears extrema. The installation SQL revokes public execution of both reset functions.
Operational Boundaries
Installation requires administrative privileges and a restart for preload changes. The views are selectable by ordinary roles, but the C readers apply caller checks; do not assume every role sees identical rows. Representative query text and plans may retain literals, so review access before exposing them to monitoring users. Storage is bounded and entries can be evicted; these counters are not an audit log. The pinned source does not declare a complete PostgreSQL-major support matrix; validate the intended server version separately.