Skip to content

Commit

Permalink
Issue - (#3): README file update.
Browse files Browse the repository at this point in the history
  • Loading branch information
ibrarahmad committed Nov 21, 2019
1 parent 8db480c commit 3857313
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,29 @@ There are four views, and complete statistics can be accessed using these views.
query | text | | |
slow_query | text | | |

Examples
1 - Here in this query we are getting the exact value of f1 = '05:06:07-07' where in case of slow query.

# select userid, queryid, query, slow_query, max_time, total_calls from pg_stat_agg_user;
-[ RECORD 1 ]----------------------------------------------------------------------------------------
userid | 10
queryid | -203926152419851453
query | SELECT f1 FROM TIMETZ_TBL WHERE f1 < $1
slow_query | SELECT f1 FROM TIMETZ_TBL WHERE f1 < '05:06:07-07';
max_time | 1.237875
total_calls | 8

2 - Collect all the statistics based on user.

# select usename, query, max_time, total_calls from pg_stat_agg_user au, pg_user u where au.userid = u.usesysid;
usename | query | max_time | total_calls
---------+---------------------------------------------------------+----------+-------------
vagrant | select userid, query, total_calls from pg_stat_agg_user | 0.268842 | 7
foo | select userid, query, total_calls from pg_stat_agg_user | 0.208551 | 1
vagrant | select * from pg_stat_monitor_reset() | 0.0941 | 1
(3 rows)


#### Limitation
There are some limitations and Todo's.

Expand Down
8 changes: 4 additions & 4 deletions pg_stat_monitor--1.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ SELECT
ss.query,
ss.slow_query
FROM pg_stat_agg() agg
INNER JOIN (SELECT DISTINCT queryid, userid, query, host, min_time, max_time, mean_time, hist_calls, hist_min_time, hist_max_time,hist_mean_time,slow_query,cpu_user_time,cpu_sys_time
INNER JOIN (SELECT DISTINCT queryid, dbid, userid, query, host, min_time, max_time, mean_time, hist_calls, hist_min_time, hist_max_time,hist_mean_time,slow_query,cpu_user_time,cpu_sys_time
FROM pg_stat_monitor) ss
ON agg.queryid = ss.queryid AND agg.type = 0;
ON agg.queryid = ss.queryid AND agg.type = 0 AND id = dbid;

CREATE VIEW pg_stat_agg_user AS
SELECT
Expand All @@ -110,7 +110,7 @@ SELECT
ss.slow_query
FROM pg_stat_agg() agg
INNER JOIN (SELECT DISTINCT queryid, userid, query, host, min_time, max_time, mean_time, hist_calls, hist_min_time, hist_max_time,hist_mean_time,slow_query,cpu_user_time,cpu_sys_time FROM pg_stat_monitor) ss
ON agg.queryid = ss.queryid AND agg.type = 1;
ON agg.queryid = ss.queryid AND agg.type = 1 AND id = userid;

CREATE VIEW pg_stat_agg_host AS
SELECT
Expand All @@ -134,7 +134,7 @@ SELECT
ss.slow_query
FROM pg_stat_agg() agg
INNER JOIN (SELECT DISTINCT queryid, userid, query, host, min_time, max_time, mean_time, hist_calls, hist_min_time, hist_max_time,hist_mean_time,slow_query,cpu_user_time,cpu_sys_time FROM pg_stat_monitor) ss
ON agg.queryid = ss.queryid AND agg.type = 2;
ON agg.queryid = ss.queryid AND agg.type = 2 AND id = host;

GRANT SELECT ON pg_stat_agg_database TO PUBLIC;

Expand Down

0 comments on commit 3857313

Please sign in to comment.