11# pg_show_plans
22
33PostgreSQL extension that shows query plans of all the currently running SQL
4- statements.
4+ statements. Query plans can be shown in several formats, like ` JSON ` .
55
6- Plan output format can be plain TEXT (default), JSON, YAML, or XML.
7-
8- PostgreSQL versions 12 and later are supported.
9-
10- ### NOTE
11-
12- This extension creates a hash table within shared memory. The hash table is not
13- resizable, thus, no new plans can be added once it has been filled up.
6+ * This extension creates a hash table within shared memory. The hash table is
7+ not resizable, thus, no new plans can be added once it has been filled up.*
148
159# INSTALL
1610
17- There are several ways of doing it...
11+ Either use PGXS infrastructure (recommended), or compile within the source
12+ tree. PostgreSQL versions 12 and newer are supported.
1813
19- ## Using ` pg_config ` (recommended):
14+ ## PGXS
2015
21- ```
16+ Install PostgreSQL before proceeding. Make sure to have ` pg_config ` binary,
17+ these are typically included in ` -dev ` and ` -devel ` packages.
18+
19+ ``` bash
2220git clone https://github.com/cybertec-postgresql/pg_show_plans.git
2321cd pg_show_plans
24- make # `pg_config` binary must be in your $PATH (install Postgres).
25- sudo make install
22+ make
23+ make install
2624```
2725
28- ## Within PostgreSQL source tree :
26+ ## Within Source Tree :
2927
30- ```
31- PG_VER='15.1 ' # Set the required PostgreSQL version.
28+ ``` bash
29+ PG_VER=' 15.3 ' # Set the required PostgreSQL version.
3230curl -O " https://download.postgresql.org/pub/source/v${PG_VER} /postgresql-${PG_VER} .tar.bz2"
3331tar xvfj " postgresql-${PG_VER} .tar.bz2"
3432cd postgresql-${PG_VER}
@@ -37,27 +35,29 @@ cd postgresql-${PG_VER}
3735cd contrib
3836git clone https://github.com/cybertec-postgresql/pg_show_plans.git
3937cd pg_show_plans
40- make
41- sudo make install
38+ make USE_PGXS=
39+ make USE_PGXS= install
4240```
4341
44- # USAGE
42+ ## Configure
4543
4644Add ` pg_show_plans ` to ` shared_preload_libraries ` within ` postgresql.conf ` :
4745
4846```
49- shared_preload_libraries = 'pg_show_plans' # Like that.
47+ shared_preload_libraries = 'pg_show_plans'
5048```
5149
52- Start the server, and invoke ` CREATE EXTENSION pg_show_plans; ` :
50+ Restart the server, and invoke ` CREATE EXTENSION pg_show_plans; ` :
5351
5452```
55- postgresql=# CREATE EXTENSION pg_show_plans; # Like that.
53+ postgresql=# CREATE EXTENSION pg_show_plans;
5654CREATE EXTENSION
5755postgresql=#
5856```
5957
60- To get the query plans along with relevant information:
58+ # USAGE
59+
60+ To see the query plans:
6161
6262```
6363testdb=# SELECT * FROM pg_show_plans;
@@ -69,7 +69,7 @@ testdb=# SELECT * FROM pg_show_plans;
6969(3 rows)
7070```
7171
72- To get the plans and see the corresponding query expression:
72+ To get query plans and see the corresponding query expression:
7373
7474```
7575testdb=# \x
@@ -105,36 +105,38 @@ query |
105105
106106```
107107
108- # pg_show_plans VIEW
109- - * pid* : the pid of the process which the query is running.
110- - * level* : the level of the query which runs the query. Top level is ` 0 ` . For
111- example, if you execute a simple select query, the level of this query's
112- plan is 0. If you execute a function that invokes a select query, level 0 is
113- the plan of the function and level 1 is the plan of the select query invoked
114- by the function.
115- - * userid* : the userid of the user which runs the query.
116- - * dbid* : the database id of the database which the query is running.
117- - * plan* : the query plan of the running query.
118-
119- # FUNCTIONs
120- - * pg_show_plans_disable()* disables the feature. Only superuser can execute
121- it.
122- - * pg_show_plans_enable()* enables the feature. Only superuser can execute it.
123- - * pgsp_format_text()* changes the output format to ` text ` . Note that the
124- format of the plans that are stored in the memory before executing this
125- function cannot be changed.
126- - * pgsp_format_json()* changes the output format to ` json ` .
127- - * pgsp_format_yaml()* changes the output format to ` yaml ` .
128- - * pgsp_format_xml()* changes the output format to ` xml ` .
129-
130- # CONFIGURATION
131- - * pg_show_plans.plan_format* : It controls the output format of query plans.
132- It can be selected ` text ` , ` json ` , ` yaml ` , ` xml ` . Default is ` text ` .
133- - * pg_show_plans.max_plan_length* : It sets the maximum length of query plans.
134- Default is ` 16384 ` [ byte] . Note that this parameter must be set to an
135- integer. Note that pg_show plans allocates approximately (max_plan_length *
136- max_connecions) bytes on the shared memory to store plans, Therefore, if the
137- value of max_plan_length is too large, PostgreSQL may not start due to an
138- out of memory error.
139- - * pg_show_plans.is_enabled* : It controls whether the extension starts
140- enabled. Default is ` true `
108+ # DOCUMENTATION
109+
110+ ## GUC Variables
111+
112+ * ` pg_show_plans.plan_format = text ` : query plans output format, either of
113+ ` text ` , ` json ` , ` yaml ` , and ` xml ` .
114+ * ` pg_show_plans.max_plan_length = 16384 ` : query plan maximal length in bytes.
115+ This value affects the amount of shared memory the extension asks for, the
116+ server may not start if the value is too high.
117+ * ` pg_show_plans.is_enabled = true ` : whether the extension is enabled at
118+ server start up.
119+
120+ * Default values are shown after '=' sign.*
121+
122+ ## VIEWS
123+
124+ * ` pg_show_plans ` : defined as ` SELECT * FROM pg_show_plans(); ` .
125+
126+ ## FUNCTIONS
127+
128+ * ` pg_show_plans() ` : show query plans:
129+ - ` pid ` : server process ID that runs the query.
130+ - ` level ` : query nest level. Top level is 0. For example, if you execute a
131+ simple select query, the level of this query's plan is 0. If you execute a
132+ function that invokes a select query, level 0 is the plan of the function
133+ and level 1 is the plan of the select query invoked by the function.
134+ - ` userid ` : user ID who runs the query.
135+ - ` dbid ` : database ID the query runs in.
136+ - ` plan ` : query plan.
137+ * ` pg_show_plans_disable() ` : disable extension.
138+ * ` pg_show_plans_enable() ` : enable extension.
139+ * ` pgsp_format_text() ` : changes query format to ` json ` .
140+ * ` pgsp_format_json() ` : changes query format to ` json ` .
141+ * ` pgsp_format_yaml() ` : changes query format to ` yaml ` .
142+ * ` pgsp_format_xml() ` : changes query format to ` xml ` .
0 commit comments