diff --git a/README.md b/README.md index 01a78772a9df..910167d19d12 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/pg_stat_monitor--1.0.sql b/pg_stat_monitor--1.0.sql index 8f742272e9a9..762961af20db 100644 --- a/pg_stat_monitor--1.0.sql +++ b/pg_stat_monitor--1.0.sql @@ -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 @@ -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 @@ -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;