pg_store_plans

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.9
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

pg18 breaks, fixed by Vonng

Packages

Type Repo Version PG Major Compatibility Package Pattern Dependencies
EXT
MIXED
1.9
18
17
16
15
14
pg_store_plans -
RPM
PIGSTY
1.9
18
17
16
15
14
pg_store_plans_$v -
DEB
PIGSTY
1.9
18
17
16
15
14
postgresql-$v-pg-store-plan -
Linux / PG PG18 PG17 PG16 PG15 PG14
el8.x86_64
PIGSTY 1.9
PIGSTY 1.8
PIGSTY 1.8
PIGSTY 1.8
PIGSTY 1.8
el8.aarch64
PIGSTY 1.9
PIGSTY 1.8
PIGSTY 1.8
PIGSTY 1.8
PIGSTY 1.8
el9.x86_64
PIGSTY 1.9
PIGSTY 1.8
PIGSTY 1.8
PIGSTY 1.8
PIGSTY 1.8
el9.aarch64
PIGSTY 1.9
PIGSTY 1.8
PIGSTY 1.8
PIGSTY 1.8
PIGSTY 1.8
el10.x86_64
PIGSTY 1.9
PIGSTY 1.9
PGDG 1.8
PGDG 1.8
MISS
el10.aarch64
PIGSTY 1.9
PIGSTY 1.9
PGDG 1.8
PGDG 1.8
MISS
d12.x86_64
PIGSTY 1.9
PIGSTY 1.9
PIGSTY 1.9
PIGSTY 1.9
PIGSTY 1.9
d12.aarch64
PIGSTY 1.9
PIGSTY 1.9
PIGSTY 1.9
PIGSTY 1.9
PIGSTY 1.9
d13.x86_64
PIGSTY 1.9
PIGSTY 1.9
PIGSTY 1.9
PIGSTY 1.9
PIGSTY 1.9
d13.aarch64
PIGSTY 1.9
PIGSTY 1.9
PIGSTY 1.9
PIGSTY 1.9
PIGSTY 1.9
u22.x86_64
PIGSTY 1.9
PIGSTY 1.9
PIGSTY 1.9
PIGSTY 1.9
PIGSTY 1.9
u22.aarch64
PIGSTY 1.9
PIGSTY 1.9
PIGSTY 1.9
PIGSTY 1.9
PIGSTY 1.9
u24.x86_64
PIGSTY 1.9
PIGSTY 1.9
PIGSTY 1.9
PIGSTY 1.9
PIGSTY 1.9
u24.aarch64
PIGSTY 1.9
PIGSTY 1.9
PIGSTY 1.9
PIGSTY 1.9
PIGSTY 1.9
Package Version OS ORG SIZE File URL
pg_store_plans_18 1.9 el8.x86_64 pigsty 44.5 KiB pg_store_plans_18-1.9-1PIGSTY.el8.x86_64.rpm
pg_store_plans_18 1.9 el8.aarch64 pigsty 43.2 KiB pg_store_plans_18-1.9-1PIGSTY.el8.aarch64.rpm
pg_store_plans_18 1.9 el9.x86_64 pigsty 43.5 KiB pg_store_plans_18-1.9-1PIGSTY.el9.x86_64.rpm
pg_store_plans_18 1.9 el9.aarch64 pigsty 42.9 KiB pg_store_plans_18-1.9-1PIGSTY.el9.aarch64.rpm
pg_store_plans_18 1.9 el10.x86_64 pigsty 44.7 KiB pg_store_plans_18-1.9-1PIGSTY.el10.x86_64.rpm
pg_store_plans_18 1.9 el10.aarch64 pigsty 43.6 KiB pg_store_plans_18-1.9-1PIGSTY.el10.aarch64.rpm
postgresql-18-pg-store-plan 1.9 d12.x86_64 pigsty 108.1 KiB postgresql-18-pg-store-plan_1.9-1PIGSTY~bookworm_amd64.deb
postgresql-18-pg-store-plan 1.9 d12.aarch64 pigsty 105.0 KiB postgresql-18-pg-store-plan_1.9-1PIGSTY~bookworm_arm64.deb
postgresql-18-pg-store-plan 1.9 d13.x86_64 pigsty 108.5 KiB postgresql-18-pg-store-plan_1.9-1PIGSTY~trixie_amd64.deb
postgresql-18-pg-store-plan 1.9 d13.aarch64 pigsty 105.5 KiB postgresql-18-pg-store-plan_1.9-1PIGSTY~trixie_arm64.deb
postgresql-18-pg-store-plan 1.9 u22.x86_64 pigsty 118.0 KiB postgresql-18-pg-store-plan_1.9-1PIGSTY~jammy_amd64.deb
postgresql-18-pg-store-plan 1.9 u22.aarch64 pigsty 116.3 KiB postgresql-18-pg-store-plan_1.9-1PIGSTY~jammy_arm64.deb
postgresql-18-pg-store-plan 1.9 u24.x86_64 pigsty 113.7 KiB postgresql-18-pg-store-plan_1.9-1PIGSTY~noble_amd64.deb
postgresql-18-pg-store-plan 1.9 u24.aarch64 pigsty 112.8 KiB postgresql-18-pg-store-plan_1.9-1PIGSTY~noble_arm64.deb
Package Version OS ORG SIZE File URL
pg_store_plans_17 1.8 el8.x86_64 pigsty 40.7 KiB pg_store_plans_17-1.8-2PIGSTY.el8.x86_64.rpm
pg_store_plans_17 1.8 el8.aarch64 pigsty 39.4 KiB pg_store_plans_17-1.8-2PIGSTY.el8.aarch64.rpm
pg_store_plans_17 1.8 el9.x86_64 pigsty 42.4 KiB pg_store_plans_17-1.8-2PIGSTY.el9.x86_64.rpm
pg_store_plans_17 1.8 el9.aarch64 pigsty 41.5 KiB pg_store_plans_17-1.8-2PIGSTY.el9.aarch64.rpm
pg_store_plans_17 1.9 el10.x86_64 pigsty 43.2 KiB pg_store_plans_17-1.9-1PIGSTY.el10.x86_64.rpm
pg_store_plans_17 1.9 el10.aarch64 pigsty 42.2 KiB pg_store_plans_17-1.9-1PIGSTY.el10.aarch64.rpm
postgresql-17-pg-store-plan 1.9 d12.x86_64 pigsty 107.8 KiB postgresql-17-pg-store-plan_1.9-1PIGSTY~bookworm_amd64.deb
postgresql-17-pg-store-plan 1.9 d12.aarch64 pigsty 105.0 KiB postgresql-17-pg-store-plan_1.9-1PIGSTY~bookworm_arm64.deb
postgresql-17-pg-store-plan 1.9 d13.x86_64 pigsty 108.4 KiB postgresql-17-pg-store-plan_1.9-1PIGSTY~trixie_amd64.deb
postgresql-17-pg-store-plan 1.9 d13.aarch64 pigsty 105.5 KiB postgresql-17-pg-store-plan_1.9-1PIGSTY~trixie_arm64.deb
postgresql-17-pg-store-plan 1.9 u22.x86_64 pigsty 129.4 KiB postgresql-17-pg-store-plan_1.9-1PIGSTY~jammy_amd64.deb
postgresql-17-pg-store-plan 1.9 u22.aarch64 pigsty 127.8 KiB postgresql-17-pg-store-plan_1.9-1PIGSTY~jammy_arm64.deb
postgresql-17-pg-store-plan 1.9 u24.x86_64 pigsty 113.8 KiB postgresql-17-pg-store-plan_1.9-1PIGSTY~noble_amd64.deb
postgresql-17-pg-store-plan 1.9 u24.aarch64 pigsty 112.8 KiB postgresql-17-pg-store-plan_1.9-1PIGSTY~noble_arm64.deb
Package Version OS ORG SIZE File URL
pg_store_plans_16 1.8 el8.x86_64 pigsty 40.7 KiB pg_store_plans_16-1.8-2PIGSTY.el8.x86_64.rpm
pg_store_plans_16 1.8 el8.x86_64 pgdg 45.4 KiB pg_store_plans_16-1.8-1PGDG.rhel8.x86_64.rpm
pg_store_plans_16 1.8 el8.aarch64 pigsty 39.4 KiB pg_store_plans_16-1.8-2PIGSTY.el8.aarch64.rpm
pg_store_plans_16 1.8 el8.aarch64 pgdg 44.1 KiB pg_store_plans_16-1.8-1PGDG.rhel8.aarch64.rpm
pg_store_plans_16 1.8 el9.x86_64 pigsty 42.3 KiB pg_store_plans_16-1.8-2PIGSTY.el9.x86_64.rpm
pg_store_plans_16 1.8 el9.x86_64 pgdg 46.1 KiB pg_store_plans_16-1.8-1PGDG.rhel9.x86_64.rpm
pg_store_plans_16 1.8 el9.aarch64 pigsty 41.4 KiB pg_store_plans_16-1.8-2PIGSTY.el9.aarch64.rpm
pg_store_plans_16 1.8 el9.aarch64 pgdg 45.1 KiB pg_store_plans_16-1.8-1PGDG.rhel9.aarch64.rpm
pg_store_plans_16 1.8 el10.x86_64 pgdg 47.1 KiB pg_store_plans_16-1.8-3PGDG.rhel10.x86_64.rpm
pg_store_plans_16 1.8 el10.aarch64 pgdg 46.0 KiB pg_store_plans_16-1.8-3PGDG.rhel10.aarch64.rpm
postgresql-16-pg-store-plan 1.9 d12.x86_64 pigsty 108.1 KiB postgresql-16-pg-store-plan_1.9-1PIGSTY~bookworm_amd64.deb
postgresql-16-pg-store-plan 1.9 d12.aarch64 pigsty 105.3 KiB postgresql-16-pg-store-plan_1.9-1PIGSTY~bookworm_arm64.deb
postgresql-16-pg-store-plan 1.9 d13.x86_64 pigsty 108.8 KiB postgresql-16-pg-store-plan_1.9-1PIGSTY~trixie_amd64.deb
postgresql-16-pg-store-plan 1.9 d13.aarch64 pigsty 105.8 KiB postgresql-16-pg-store-plan_1.9-1PIGSTY~trixie_arm64.deb
postgresql-16-pg-store-plan 1.9 u22.x86_64 pigsty 129.1 KiB postgresql-16-pg-store-plan_1.9-1PIGSTY~jammy_amd64.deb
postgresql-16-pg-store-plan 1.9 u22.aarch64 pigsty 127.5 KiB postgresql-16-pg-store-plan_1.9-1PIGSTY~jammy_arm64.deb
postgresql-16-pg-store-plan 1.9 u24.x86_64 pigsty 113.9 KiB postgresql-16-pg-store-plan_1.9-1PIGSTY~noble_amd64.deb
postgresql-16-pg-store-plan 1.9 u24.aarch64 pigsty 112.7 KiB postgresql-16-pg-store-plan_1.9-1PIGSTY~noble_arm64.deb
Package Version OS ORG SIZE File URL
pg_store_plans_15 1.8 el8.x86_64 pigsty 41.7 KiB pg_store_plans_15-1.8-2PIGSTY.el8.x86_64.rpm
pg_store_plans_15 1.8 el8.x86_64 pgdg 46.3 KiB pg_store_plans_15-1.8-1PGDG.rhel8.x86_64.rpm
pg_store_plans_15 1.7 el8.x86_64 pgdg 46.3 KiB pg_store_plans_15-1.7-1PGDG.rhel8.x86_64.rpm
pg_store_plans_15 1.8 el8.aarch64 pigsty 40.3 KiB pg_store_plans_15-1.8-2PIGSTY.el8.aarch64.rpm
pg_store_plans_15 1.8 el8.aarch64 pgdg 45.0 KiB pg_store_plans_15-1.8-1PGDG.rhel8.aarch64.rpm
pg_store_plans_15 1.7 el8.aarch64 pgdg 44.8 KiB pg_store_plans_15-1.7-1PGDG.rhel8.aarch64.rpm
pg_store_plans_15 1.8 el9.x86_64 pigsty 43.9 KiB pg_store_plans_15-1.8-2PIGSTY.el9.x86_64.rpm
pg_store_plans_15 1.8 el9.x86_64 pgdg 47.2 KiB pg_store_plans_15-1.8-1PGDG.rhel9.x86_64.rpm
pg_store_plans_15 1.7 el9.x86_64 pgdg 47.3 KiB pg_store_plans_15-1.7-1PGDG.rhel9.x86_64.rpm
pg_store_plans_15 1.8 el9.aarch64 pigsty 43.1 KiB pg_store_plans_15-1.8-2PIGSTY.el9.aarch64.rpm
pg_store_plans_15 1.8 el9.aarch64 pgdg 46.1 KiB pg_store_plans_15-1.8-1PGDG.rhel9.aarch64.rpm
pg_store_plans_15 1.7 el9.aarch64 pgdg 45.9 KiB pg_store_plans_15-1.7-1PGDG.rhel9.aarch64.rpm
pg_store_plans_15 1.8 el10.x86_64 pgdg 48.3 KiB pg_store_plans_15-1.8-3PGDG.rhel10.x86_64.rpm
pg_store_plans_15 1.8 el10.aarch64 pgdg 47.2 KiB pg_store_plans_15-1.8-3PGDG.rhel10.aarch64.rpm
postgresql-15-pg-store-plan 1.9 d12.x86_64 pigsty 109.6 KiB postgresql-15-pg-store-plan_1.9-1PIGSTY~bookworm_amd64.deb
postgresql-15-pg-store-plan 1.9 d12.aarch64 pigsty 106.6 KiB postgresql-15-pg-store-plan_1.9-1PIGSTY~bookworm_arm64.deb
postgresql-15-pg-store-plan 1.9 d13.x86_64 pigsty 110.1 KiB postgresql-15-pg-store-plan_1.9-1PIGSTY~trixie_amd64.deb
postgresql-15-pg-store-plan 1.9 d13.aarch64 pigsty 106.9 KiB postgresql-15-pg-store-plan_1.9-1PIGSTY~trixie_arm64.deb
postgresql-15-pg-store-plan 1.9 u22.x86_64 pigsty 131.1 KiB postgresql-15-pg-store-plan_1.9-1PIGSTY~jammy_amd64.deb
postgresql-15-pg-store-plan 1.9 u22.aarch64 pigsty 129.3 KiB postgresql-15-pg-store-plan_1.9-1PIGSTY~jammy_arm64.deb
postgresql-15-pg-store-plan 1.9 u24.x86_64 pigsty 116.4 KiB postgresql-15-pg-store-plan_1.9-1PIGSTY~noble_amd64.deb
postgresql-15-pg-store-plan 1.9 u24.aarch64 pigsty 114.6 KiB postgresql-15-pg-store-plan_1.9-1PIGSTY~noble_arm64.deb
Package Version OS ORG SIZE File URL
pg_store_plans_14 1.8 el8.x86_64 pigsty 41.6 KiB pg_store_plans_14-1.8-2PIGSTY.el8.x86_64.rpm
pg_store_plans_14 1.8 el8.aarch64 pigsty 40.2 KiB pg_store_plans_14-1.8-2PIGSTY.el8.aarch64.rpm
pg_store_plans_14 1.8 el9.x86_64 pigsty 43.6 KiB pg_store_plans_14-1.8-2PIGSTY.el9.x86_64.rpm
pg_store_plans_14 1.8 el9.aarch64 pigsty 43.0 KiB pg_store_plans_14-1.8-2PIGSTY.el9.aarch64.rpm
postgresql-14-pg-store-plan 1.9 d12.x86_64 pigsty 109.5 KiB postgresql-14-pg-store-plan_1.9-1PIGSTY~bookworm_amd64.deb
postgresql-14-pg-store-plan 1.9 d12.aarch64 pigsty 106.3 KiB postgresql-14-pg-store-plan_1.9-1PIGSTY~bookworm_arm64.deb
postgresql-14-pg-store-plan 1.9 d13.x86_64 pigsty 109.9 KiB postgresql-14-pg-store-plan_1.9-1PIGSTY~trixie_amd64.deb
postgresql-14-pg-store-plan 1.9 d13.aarch64 pigsty 106.6 KiB postgresql-14-pg-store-plan_1.9-1PIGSTY~trixie_arm64.deb
postgresql-14-pg-store-plan 1.9 u22.x86_64 pigsty 130.5 KiB postgresql-14-pg-store-plan_1.9-1PIGSTY~jammy_amd64.deb
postgresql-14-pg-store-plan 1.9 u22.aarch64 pigsty 128.7 KiB postgresql-14-pg-store-plan_1.9-1PIGSTY~jammy_arm64.deb
postgresql-14-pg-store-plan 1.9 u24.x86_64 pigsty 115.9 KiB postgresql-14-pg-store-plan_1.9-1PIGSTY~noble_amd64.deb
postgresql-14-pg-store-plan 1.9 u24.aarch64 pigsty 114.1 KiB postgresql-14-pg-store-plan_1.9-1PIGSTY~noble_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

pg_store_plans: execution plan storage and statistics

pg_store_plans tracks execution plan statistics for all SQL statements, complementing pg_stat_statements with plan-level detail. Joinable via queryid on PostgreSQL 14+.

Viewing Plan Statistics

-- View tracked plans with statistics
SELECT queryid, planid, plan, calls, total_time, rows
FROM pg_store_plans
ORDER BY total_time DESC;

-- Check module status
SELECT * FROM pg_store_plans_info;

Key View Columns

Column Type Description
queryid bigint Query ID (joinable with pg_stat_statements)
planid bigint Plan hash code
plan text Representative plan text
calls bigint Execution count
total_time double precision Total execution time (ms)
rows bigint Total rows retrieved/affected
shared_blks_hit bigint Shared buffer hits
shared_blks_read bigint Shared blocks read
first_call timestamptz First execution time
last_call timestamptz Last execution time

Functions

-- Reset all statistics (superuser only)
SELECT pg_store_plans_reset();

-- Convert plan formats
SELECT pg_store_plans_textplan(plan);   -- to text
SELECT pg_store_plans_jsonplan(plan);   -- to JSON
SELECT pg_store_plans_xmlplan(plan);    -- to XML
SELECT pg_store_plans_yamlplan(plan);   -- to YAML

-- Calculate query hash
SELECT pg_store_hash_query('SELECT 1');

Configuration

Parameter Default Description
pg_store_plans.max 1000 Maximum tracked plans (server start only)
pg_store_plans.track top top, all, verbose, none
pg_store_plans.plan_format text text, json, xml, yaml, raw
pg_store_plans.min_duration 0 Minimum execution time to track (ms)
pg_store_plans.log_analyze off Include EXPLAIN ANALYZE output
pg_store_plans.log_buffers off Include buffer statistics
pg_store_plans.log_timing true Record actual timings
pg_store_plans.plan_storage file Storage: file or shmem
pg_store_plans.max_plan_length 5000 Max bytes for plan text
pg_store_plans.save on Persist stats across restarts
Last updated on