pg_store_plans
pg_store_plans : track plan statistics of all SQL statements executed
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 6250 | pg_store_plans
|
pg_store_plans
|
1.10 |
STAT
|
BSD 3-Clause
|
C
|
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
--sLd-r
|
No
|
Yes
|
Yes
|
Yes
|
yes
|
no
|
| Relationships | |
|---|---|
| See Also | pg_show_plans
auto_explain
pg_stat_statements
pg_hint_plan
pre_prepare
pg_stat_monitor
explain_ui
plprofiler
|
Packages
| Type | Repo | Version | PG Major Compatibility | Package Pattern | Dependencies |
|---|---|---|---|---|---|
| EXT | MIXED
|
1.10 |
18
17
16
15
14
|
pg_store_plans |
- |
| RPM | PIGSTY
|
1.10 |
18
17
16
15
14
|
pg_store_plans_$v |
- |
| DEB | PIGSTY
|
1.10 |
18
17
16
15
14
|
postgresql-$v-pg-store-plan |
- |
| Linux / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
el8.x86_64
|
PIGSTY 1.10
|
PIGSTY 1.10
|
PIGSTY 1.10
|
PIGSTY 1.10
|
PIGSTY 1.10
|
el8.aarch64
|
PIGSTY 1.10
|
PIGSTY 1.10
|
PIGSTY 1.10
|
PIGSTY 1.10
|
PIGSTY 1.10
|
el9.x86_64
|
PIGSTY 1.10
|
PIGSTY 1.10
|
PIGSTY 1.10
|
PIGSTY 1.10
|
PIGSTY 1.10
|
el9.aarch64
|
PIGSTY 1.10
|
PIGSTY 1.10
|
PIGSTY 1.10
|
PIGSTY 1.10
|
PIGSTY 1.10
|
el10.x86_64
|
PIGSTY 1.10
|
PIGSTY 1.10
|
PIGSTY 1.10
|
PIGSTY 1.10
|
PIGSTY 1.10
|
el10.aarch64
|
PIGSTY 1.10
|
PIGSTY 1.10
|
PIGSTY 1.10
|
PIGSTY 1.10
|
PIGSTY 1.10
|
d12.x86_64
|
PIGSTY 1.10
|
PIGSTY 1.10
|
PIGSTY 1.10
|
PIGSTY 1.10
|
PIGSTY 1.10
|
d12.aarch64
|
PIGSTY 1.10
|
PIGSTY 1.10
|
PIGSTY 1.10
|
PIGSTY 1.10
|
PIGSTY 1.10
|
d13.x86_64
|
PIGSTY 1.10
|
PIGSTY 1.10
|
PIGSTY 1.10
|
PIGSTY 1.10
|
PIGSTY 1.10
|
d13.aarch64
|
PIGSTY 1.10
|
PIGSTY 1.10
|
PIGSTY 1.10
|
PIGSTY 1.10
|
PIGSTY 1.10
|
u22.x86_64
|
PIGSTY 1.10
|
PIGSTY 1.10
|
PIGSTY 1.10
|
PIGSTY 1.10
|
PIGSTY 1.10
|
u22.aarch64
|
PIGSTY 1.10
|
PIGSTY 1.10
|
PIGSTY 1.10
|
PIGSTY 1.10
|
PIGSTY 1.10
|
u24.x86_64
|
PIGSTY 1.10
|
PIGSTY 1.10
|
PIGSTY 1.10
|
PIGSTY 1.10
|
PIGSTY 1.10
|
u24.aarch64
|
PIGSTY 1.10
|
PIGSTY 1.10
|
PIGSTY 1.10
|
PIGSTY 1.10
|
PIGSTY 1.10
|
Source
pig build pkg pg_store_plans; # build rpm/debInstall
Make sure PGDG and PIGSTY repo available:
pig repo add pgsql -u # add both repo and update cacheInstall this extension with pig:
pig install pg_store_plans; # install via package name, for the active PG version
pig install pg_store_plans -v 18; # install for PG 18
pig install pg_store_plans -v 17; # install for PG 17
pig install pg_store_plans -v 16; # install for PG 16
pig install pg_store_plans -v 15; # install for PG 15
pig install pg_store_plans -v 14; # install for PG 14Config this extension to shared_preload_libraries:
shared_preload_libraries = 'pg_store_plans';Create this extension with:
CREATE EXTENSION pg_store_plans;Usage
Syntax:
SELECT * FROM pg_store_plans ORDER BY total_time DESC; SELECT * FROM pg_store_plans_info;Sources: Project page, Bundled docs
pg_store_plans tracks execution plan statistics for SQL statements, similar in spirit to how pg_stat_statements tracks statements. It records plan text, plan hash, timing, row counts, and buffer statistics, and its docs note that queryid can be used to join with pg_stat_statements.
Configuration
The upstream documentation requires:
shared_preload_libraries = 'pg_store_plans'
compute_query_id = 'on'pg_store_plans needs shared memory, so adding or removing it requires a server restart. If compute_query_id is set to no, the module is silently disabled.
Viewing Plan Statistics
The statistics are exposed through the pg_store_plans view:
SELECT queryid, planid, plan, calls, total_time, rows
FROM pg_store_plans
ORDER BY total_time DESC;
SELECT * FROM pg_store_plans_info;Important columns documented upstream include:
queryid, the core-generated query IDplanid, a normalized plan hashplan, in the format chosen bypg_store_plans.plan_formatcalls,total_time, androws- buffer statistics such as
shared_blks_hitandshared_blks_read - timestamps such as
first_callandlast_call
Helper Functions
SELECT pg_store_plans_reset();
SELECT pg_store_plans_textplan(plan);
SELECT pg_store_plans_jsonplan(plan);
SELECT pg_store_plans_xmlplan(plan);
SELECT pg_store_plans_yamlplan(plan);
SELECT pg_store_hash_query('SELECT 1');These functions reset statistics, convert stored plans to different output formats, and compute query hashes.
GUCs
The extension documentation describes settings such as:
pg_store_plans.maxpg_store_plans.trackpg_store_plans.plan_formatpg_store_plans.min_durationpg_store_plans.log_analyzepg_store_plans.log_bufferspg_store_plans.log_timingpg_store_plans.plan_storagepg_store_plans.max_plan_lengthpg_store_plans.save
Together these control collection scope, plan representation, persistence, and storage behavior.