Skip to content

Commit 498095e

Browse files
committed
Add pg_show_plans_q view
Same as pg_show_plans view but allows you to see the corresponding query strings.
1 parent 142d5a9 commit 498095e

File tree

4 files changed

+40
-2
lines changed

4 files changed

+40
-2
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ OBJS = pg_show_plans.o
44
EXTENSION = pg_show_plans
55
DATA = pg_show_plans--1.0--1.1.sql \
66
pg_show_plans--1.1--2.0.sql \
7-
pg_show_plans--2.0.sql
7+
pg_show_plans--2.0--2.1.sql \
8+
pg_show_plans--2.1.sql
89
REGRESS = pg_show_plans formats
910
DOCS = pg_show_plans.md
1011

pg_show_plans--2.0--2.1.sql

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-- Register a view to see query plans along with the corresponding queries.
2+
CREATE VIEW pg_show_plans_q AS
3+
SELECT p.pid, p.level, p.plan, a.query
4+
FROM pg_show_plans p
5+
LEFT JOIN pg_stat_activity a
6+
ON p.pid = a.pid AND p.level = 0 ORDER BY p.pid, p.level;
7+
8+
GRANT SELECT ON pg_show_plans_q TO PUBLIC;

pg_show_plans--2.1.sql

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/* pg_show_plans/pg_show_plans--2.1.sql */
2+
3+
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
4+
\echo Use "CREATE EXTENSION pg_show_plans" to load this file. \quit
5+
6+
CREATE FUNCTION pg_show_plans(
7+
OUT pid int,
8+
OUT level int,
9+
OUT userid oid,
10+
OUT dbid oid,
11+
OUT plan text
12+
)
13+
RETURNS SETOF record
14+
AS 'MODULE_PATHNAME'
15+
LANGUAGE C;
16+
17+
-- Register a view on the function for ease of use.
18+
CREATE VIEW pg_show_plans AS
19+
SELECT * FROM pg_show_plans();
20+
21+
-- Register a view to see query plans along with the corresponding queries.
22+
CREATE VIEW pg_show_plans_q AS
23+
SELECT p.pid, p.level, p.plan, a.query
24+
FROM pg_show_plans p
25+
LEFT JOIN pg_stat_activity a
26+
ON p.pid = a.pid AND p.level = 0 ORDER BY p.pid, p.level;
27+
28+
GRANT SELECT ON pg_show_plans TO PUBLIC;
29+
GRANT SELECT ON pg_show_plans_q TO PUBLIC;

pg_show_plans.control

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# pg_show_plans extension
22
comment = 'show query plans of all currently running SQL statements'
3-
default_version = '2.0'
3+
default_version = '2.1'
44
module_pathname = '$libdir/pg_show_plans'
55
relocatable = true

0 commit comments

Comments
 (0)