Skip to content
pg_store_plans

pg_store_plans

pg_store_plans : track plan statistics of all SQL statements executed

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
6250
pg_store_plans
pg_store_plans
1.10
STAT
BSD 3-Clause
C
AttributeHas BinaryHas LibraryNeed LoadHas DDLRelocatableTrusted
--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

TypeRepoVersionPG Major CompatibilityPackage PatternDependencies
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 / PGPG18PG17PG16PG15PG14
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
u26.x86_64
PIGSTY 1.10
PIGSTY 1.10
PIGSTY 1.10
PIGSTY 1.10
PIGSTY 1.10
u26.aarch64
PIGSTY 1.10
PIGSTY 1.10
PIGSTY 1.10
PIGSTY 1.10
PIGSTY 1.10
PackageVersionOSORGSIZEFile URL
pg_store_plans_181.10el8.x86_64pigsty44.6 KiBpg_store_plans_18-1.10-1PIGSTY.el8.x86_64.rpm
pg_store_plans_181.10el8.x86_64pgdg45.9 KiBpg_store_plans_18-1.10-1PGDG.rhel8.10.x86_64.rpm
pg_store_plans_181.10el8.aarch64pigsty43.4 KiBpg_store_plans_18-1.10-1PIGSTY.el8.aarch64.rpm
pg_store_plans_181.10el8.aarch64pgdg44.6 KiBpg_store_plans_18-1.10-1PGDG.rhel8.10.aarch64.rpm
pg_store_plans_181.10el9.x86_64pigsty43.5 KiBpg_store_plans_18-1.10-1PIGSTY.el9.x86_64.rpm
pg_store_plans_181.10el9.x86_64pgdg46.1 KiBpg_store_plans_18-1.10-1PGDG.rhel9.7.x86_64.rpm
pg_store_plans_181.10el9.aarch64pigsty43.1 KiBpg_store_plans_18-1.10-1PIGSTY.el9.aarch64.rpm
pg_store_plans_181.10el9.aarch64pgdg45.1 KiBpg_store_plans_18-1.10-1PGDG.rhel9.7.aarch64.rpm
pg_store_plans_181.10el10.x86_64pigsty44.2 KiBpg_store_plans_18-1.10-1PIGSTY.el10.x86_64.rpm
pg_store_plans_181.10el10.x86_64pgdg46.9 KiBpg_store_plans_18-1.10-1PGDG.rhel10.1.x86_64.rpm
pg_store_plans_181.10el10.aarch64pigsty43.8 KiBpg_store_plans_18-1.10-1PIGSTY.el10.aarch64.rpm
pg_store_plans_181.10el10.aarch64pgdg45.8 KiBpg_store_plans_18-1.10-1PGDG.rhel10.1.aarch64.rpm
postgresql-18-pg-store-plan1.10d12.x86_64pigsty108.2 KiBpostgresql-18-pg-store-plan_1.10-1PIGSTY~bookworm_amd64.deb
postgresql-18-pg-store-plan1.10d12.aarch64pigsty105.2 KiBpostgresql-18-pg-store-plan_1.10-1PIGSTY~bookworm_arm64.deb
postgresql-18-pg-store-plan1.10d13.x86_64pigsty108.8 KiBpostgresql-18-pg-store-plan_1.10-1PIGSTY~trixie_amd64.deb
postgresql-18-pg-store-plan1.10d13.aarch64pigsty105.4 KiBpostgresql-18-pg-store-plan_1.10-1PIGSTY~trixie_arm64.deb
postgresql-18-pg-store-plan1.10u22.x86_64pigsty118.0 KiBpostgresql-18-pg-store-plan_1.10-1PIGSTY~jammy_amd64.deb
postgresql-18-pg-store-plan1.10u22.aarch64pigsty116.5 KiBpostgresql-18-pg-store-plan_1.10-1PIGSTY~jammy_arm64.deb
postgresql-18-pg-store-plan1.10u24.x86_64pigsty113.8 KiBpostgresql-18-pg-store-plan_1.10-1PIGSTY~noble_amd64.deb
postgresql-18-pg-store-plan1.10u24.aarch64pigsty112.5 KiBpostgresql-18-pg-store-plan_1.10-1PIGSTY~noble_arm64.deb
postgresql-18-pg-store-plan1.10u26.x86_64pigsty115.2 KiBpostgresql-18-pg-store-plan_1.10-1PIGSTY~resolute_amd64.deb
postgresql-18-pg-store-plan1.10u26.aarch64pigsty113.2 KiBpostgresql-18-pg-store-plan_1.10-1PIGSTY~resolute_arm64.deb

Source

pig build pkg pg_store_plans;		# build rpm/deb

Install

Make sure PGDG and PIGSTY repo available:

pig repo add pgsql -u   # add both repo and update cache

Install 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 14

Config this extension to shared_preload_libraries:

shared_preload_libraries = 'pg_store_plans';

Create this extension with:

CREATE EXTENSION pg_store_plans;

Usage

Sources: official docs, repo, 1.10 release notes

pg_store_plans tracks execution plan statistics for SQL statements, similar to how pg_stat_statements tracks statement statistics. The upstream 1.10 release note says this version adds PostgreSQL 18 support; the documented SQL surface is otherwise the same as current docs.

Required server settings

shared_preload_libraries = 'pg_store_plans'
compute_query_id = 'on'

pg_store_plans requires shared memory, so adding or removing it needs a server restart. The docs say it is silently disabled if compute_query_id is no.

Inspect stored plans

SELECT queryid, planid, plan, calls, total_time, rows
FROM pg_store_plans
ORDER BY total_time DESC;

SELECT * FROM pg_store_plans_info;

The docs describe queryid as the join key for pg_stat_statements, and pg_store_plans_info as a one-row view that exposes module-level stats such as dealloc and stats_reset.

Helper functions

SELECT pg_store_plans_reset();
SELECT pg_store_hash_query('SELECT 1');
SELECT pg_store_plans_textplan(plan);
SELECT pg_store_plans_jsonplan(plan);
SELECT pg_store_plans_xmlplan(plan);
SELECT pg_store_plans_yamlplan(plan);

pg_store_plans_*plan() is useful when pg_store_plans.plan_format = 'raw'.

Key GUCs

  • pg_store_plans.max
  • pg_store_plans.track
  • pg_store_plans.max_plan_length
  • pg_store_plans.plan_storage
  • pg_store_plans.plan_format
  • pg_store_plans.min_duration
  • pg_store_plans.log_analyze
  • pg_store_plans.log_buffers
  • pg_store_plans.log_timing
  • pg_store_plans.save

The docs describe plan_storage as file or shmem, and plan_format as text, json, xml, yaml, or raw.

Caveats

  • Non-superusers cannot see plan, queryid, or planid for statements executed by other users.
  • pg_store_plans and pg_stat_statements maintain entries independently, so low-frequency rows may not always have a matching peer.
Last updated on