-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Same as pg_show_plans view but allows you to see the corresponding query strings.
- Loading branch information
Ivan Kovmir
committed
Nov 7, 2023
1 parent
9a77b73
commit 4f090b1
Showing
4 changed files
with
40 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
-- Register a view to see query plans along with the corresponding queries. | ||
CREATE VIEW pg_show_plans_q AS | ||
SELECT p.pid, p.level, p.plan, a.query | ||
FROM pg_show_plans p | ||
LEFT JOIN pg_stat_activity a | ||
ON p.pid = a.pid AND p.level = 0 ORDER BY p.pid, p.level; | ||
|
||
GRANT SELECT ON pg_show_plans_q TO PUBLIC; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* pg_show_plans/pg_show_plans--2.1.sql */ | ||
|
||
-- complain if script is sourced in psql, rather than via CREATE EXTENSION | ||
\echo Use "CREATE EXTENSION pg_show_plans" to load this file. \quit | ||
|
||
CREATE FUNCTION pg_show_plans( | ||
OUT pid int, | ||
OUT level int, | ||
OUT userid oid, | ||
OUT dbid oid, | ||
OUT plan text | ||
) | ||
RETURNS SETOF record | ||
AS 'MODULE_PATHNAME' | ||
LANGUAGE C; | ||
|
||
-- Register a view on the function for ease of use. | ||
CREATE VIEW pg_show_plans AS | ||
SELECT * FROM pg_show_plans(); | ||
|
||
-- Register a view to see query plans along with the corresponding queries. | ||
CREATE VIEW pg_show_plans_q AS | ||
SELECT p.pid, p.level, p.plan, a.query | ||
FROM pg_show_plans p | ||
LEFT JOIN pg_stat_activity a | ||
ON p.pid = a.pid AND p.level = 0 ORDER BY p.pid, p.level; | ||
|
||
GRANT SELECT ON pg_show_plans TO PUBLIC; | ||
GRANT SELECT ON pg_show_plans_q TO PUBLIC; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# pg_show_plans extension | ||
comment = 'show query plans of all currently running SQL statements' | ||
default_version = '2.0' | ||
default_version = '2.1' | ||
module_pathname = '$libdir/pg_show_plans' | ||
relocatable = true |