pg_show_plans
pg_show_plans
pg_show_plans : show query plans of all currently running SQL statements
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 6210 | pg_show_plans | pg_show_plans | 2.1.7 | STAT | PostgreSQL | C |
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
--sLd-r | No | Yes | Yes | Yes | yes | no |
| Relationships | |
|---|---|
| See Also | pg_store_plans explain_ui auto_explain pg_stat_statements pg_hint_plan pg_stat_monitor pg_qualstats pre_prepare |
Packages
| Type | Repo | Version | PG Major Compatibility | Package Pattern | Dependencies |
|---|---|---|---|---|---|
| EXT | PGDG | 2.1.7 | 18 17 16 15 14 | pg_show_plans | - |
| RPM | PGDG | 2.1.6 | 18 17 16 15 14 | pg_show_plans_$v | - |
| DEB | PGDG | 2.1.7 | 18 17 16 15 14 | postgresql-$v-show-plans | - |
| Linux / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
el8.x86_64 | PGDG 2.1.6 | PGDG 2.1.6 | PGDG 2.1.6 | PGDG 2.1.6 | PGDG 2.1.6 |
el8.aarch64 | PGDG 2.1.6 | PGDG 2.1.6 | PGDG 2.1.6 | PGDG 2.1.6 | PGDG 2.1.6 |
el9.x86_64 | PGDG 2.1.6 | PGDG 2.1.6 | PGDG 2.1.6 | PGDG 2.1.6 | PGDG 2.1.6 |
el9.aarch64 | PGDG 2.1.6 | PGDG 2.1.6 | PGDG 2.1.6 | PGDG 2.1.6 | PGDG 2.1.6 |
el10.x86_64 | PGDG 2.1.6 | PGDG 2.1.6 | PGDG 2.1.6 | PGDG 2.1.6 | PGDG 2.1.6 |
el10.aarch64 | PGDG 2.1.6 | PGDG 2.1.6 | PGDG 2.1.6 | PGDG 2.1.6 | PGDG 2.1.6 |
d12.x86_64 | PGDG 2.1.7 | PGDG 2.1.7 | PGDG 2.1.7 | PGDG 2.1.7 | PGDG 2.1.7 |
d12.aarch64 | PGDG 2.1.7 | PGDG 2.1.7 | PGDG 2.1.7 | PGDG 2.1.7 | PGDG 2.1.7 |
d13.x86_64 | PGDG 2.1.7 | PGDG 2.1.7 | PGDG 2.1.7 | PGDG 2.1.7 | PGDG 2.1.7 |
d13.aarch64 | PGDG 2.1.7 | PGDG 2.1.7 | PGDG 2.1.7 | PGDG 2.1.7 | PGDG 2.1.7 |
u22.x86_64 | PGDG 2.1.7 | PGDG 2.1.7 | PGDG 2.1.7 | PGDG 2.1.7 | PGDG 2.1.7 |
u22.aarch64 | PGDG 2.1.7 | PGDG 2.1.7 | PGDG 2.1.7 | PGDG 2.1.7 | PGDG 2.1.7 |
u24.x86_64 | PGDG 2.1.7 | PGDG 2.1.7 | PGDG 2.1.7 | PGDG 2.1.7 | PGDG 2.1.7 |
u24.aarch64 | PGDG 2.1.7 | PGDG 2.1.7 | PGDG 2.1.7 | PGDG 2.1.7 | PGDG 2.1.7 |
Source
Install
Make sure PGDG repo available:
pig repo add pgdg -u # add pgdg repo and update cacheInstall this extension with pig:
pig install pg_show_plans; # install via package name, for the active PG version
pig install pg_show_plans -v 18; # install for PG 18
pig install pg_show_plans -v 17; # install for PG 17
pig install pg_show_plans -v 16; # install for PG 16
pig install pg_show_plans -v 15; # install for PG 15
pig install pg_show_plans -v 14; # install for PG 14Config this extension to shared_preload_libraries:
shared_preload_libraries = 'pg_show_plans';Create this extension with:
CREATE EXTENSION pg_show_plans;Usage
pg_show_plans displays the execution plans of all currently running SQL statements in real time. Plans are stored in a shared memory hash table.
Viewing Running Plans
-- Show plans of all currently running queries
SELECT * FROM pg_show_plans;
-- Show plans along with their query text
SELECT * FROM pg_show_plans_q;The views return:
| Column | Type | Description |
|---|---|---|
pid | integer | Server process ID |
level | integer | Query nest level (0 = top level) |
userid | oid | User OID |
dbid | oid | Database OID |
plan | text | Query plan text |
query | text | Query string (only in pg_show_plans_q) |
Nested Queries
When a function invokes SQL statements, they appear at deeper nesting levels:
SELECT * FROM pg_show_plans;
pid | level | userid | dbid | plan
-------+-------+--------+-------+-----------------------------------------------
11504 | 0 | 10 | 16384 | Function Scan on print_item (cost=...)
11504 | 1 | 10 | 16384 | Result (cost=0.00..0.01 rows=1 width=4)GUC Parameters
| Parameter | Default | Description |
|---|---|---|
pg_show_plans.plan_format | text | Output format: text, json, yaml, xml |
pg_show_plans.max_plan_length | 16384 | Max plan length in bytes (affects shared memory) |
pg_show_plans.is_enabled | true | Enable or disable the extension at runtime |
Last updated on