Skip to content

Commit

Permalink
Issue - (#27): PG-106: Support for WaitEvents, similar to pg_stat_act…
Browse files Browse the repository at this point in the history
…ivity added.
  • Loading branch information
ibrarahmad committed Mar 20, 2020
1 parent 7601509 commit fca8cd4
Show file tree
Hide file tree
Showing 3 changed files with 599 additions and 300 deletions.
30 changes: 27 additions & 3 deletions pg_stat_monitor--1.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ RETURNS SETOF record
AS 'MODULE_PATHNAME', 'pg_stat_monitor'
LANGUAGE C STRICT VOLATILE PARALLEL SAFE;

CREATE FUNCTION pg_stat_wait_events(
OUT queryid text,
OUT pid bigint,
OUT wait_event text,
OUT wait_event_type text
)
RETURNS SETOF record
AS 'MODULE_PATHNAME', 'pg_stat_wait_events'
LANGUAGE C STRICT VOLATILE PARALLEL SAFE;

CREATE FUNCTION pg_stat_agg(
OUT queryid text,
OUT id bigint,
Expand All @@ -61,7 +71,7 @@ CREATE VIEW pg_stat_monitor AS SELECT
bucket_start_time,
userid,
dbid,
queryid,
m.queryid,
query,
calls,
total_time,
Expand All @@ -87,9 +97,21 @@ CREATE VIEW pg_stat_monitor AS SELECT
(string_to_array(resp_calls, ',')) resp_calls,
cpu_user_time,
cpu_sys_time,
(string_to_array(tables_names, ',')) tables_names
FROM pg_stat_monitor(true);
(string_to_array(tables_names, ',')) tables_names,
wait_event,
wait_event_type
FROM pg_stat_monitor(true) m, pg_stat_wait_events() w WHERE (w.queryid = m.queryid) OR w.queryid IS NULL;


-- Register a view on the function for ease of use.
CREATE VIEW pg_stat_wait_events AS SELECT
m.queryid,
query,
wait_event,
wait_event_type
FROM pg_stat_monitor(true) m, pg_stat_wait_events() w WHERE w.queryid = m.queryid;

GRANT SELECT ON pg_stat_wait_events TO PUBLIC;
GRANT SELECT ON pg_stat_monitor TO PUBLIC;

CREATE VIEW pg_stat_agg_database AS
Expand Down Expand Up @@ -154,6 +176,8 @@ FROM pg_stat_agg() agg
INNER JOIN (SELECT DISTINCT bucket, queryid, userid, query, client_ip, host, min_time, max_time, mean_time, resp_calls, tables_names, cpu_user_time,cpu_sys_time FROM pg_stat_monitor) ss
ON agg.queryid = ss.queryid AND agg.type = 2 AND id = host;



GRANT SELECT ON pg_stat_agg_user TO PUBLIC;
GRANT SELECT ON pg_stat_agg_ip TO PUBLIC;
GRANT SELECT ON pg_stat_agg_database TO PUBLIC;
Expand Down
Loading

0 comments on commit fca8cd4

Please sign in to comment.