mirror of
https://github.com/percona/pg_stat_monitor.git
synced 2026-02-04 22:16:20 +00:00
Major refactoring to support multiple new features.
Issue - (#16): PG-112: Change the column name "ip" to "client_ip" for readability purpose. Issue - (#17): PG-111: Show all the queries from complete and incomplete buckets. Issue - (#18): PG-108: Log the bucket start time. Issue - (#19): PG-99: Response time histogram. Issue - (#20): PG-97: Log CPU time for a query. Issue - (#21): PG-96: Show objects(tables) involved in the query. Issue - (#22): PG-93: Retain the bucket, and don't delete the bucket automatically. Issue - (#23): PG-91: Log queries of all the databases. Issue - (#24): PG-116: Restrict the query size. Issue - (#3) : README file update.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/* contrib/pg_stat_monitor/pg_stat_monitor--1.4.sql */
|
||||
/* contrib/pg_stat_monitor/pg_stat_monitor--1.1.sql */
|
||||
|
||||
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
|
||||
\echo Use "CREATE EXTENSION pg_stat_monitor" to load this file. \quit
|
||||
@@ -10,10 +10,13 @@ AS 'MODULE_PATHNAME'
|
||||
LANGUAGE C PARALLEL SAFE;
|
||||
|
||||
CREATE FUNCTION pg_stat_monitor(IN showtext boolean,
|
||||
OUT bucket oid,
|
||||
OUT userid oid,
|
||||
OUT dbid oid,
|
||||
OUT queryid bigint,
|
||||
|
||||
OUT queryid text,
|
||||
OUT query text,
|
||||
OUT bucket_start_time timestamptz,
|
||||
OUT calls int8,
|
||||
OUT total_time float8,
|
||||
OUT min_time float8,
|
||||
@@ -33,109 +36,126 @@ CREATE FUNCTION pg_stat_monitor(IN showtext boolean,
|
||||
OUT temp_blks_written int8,
|
||||
OUT blk_read_time float8,
|
||||
OUT blk_write_time float8,
|
||||
OUT host bigint,
|
||||
OUT hist_calls text,
|
||||
OUT hist_min_time text,
|
||||
OUT hist_max_time text,
|
||||
OUT hist_mean_time text,
|
||||
OUT slow_query text,
|
||||
OUT client_ip bigint,
|
||||
OUT resp_calls text,
|
||||
OUT cpu_user_time float8,
|
||||
OUT cpu_sys_time float8
|
||||
OUT cpu_sys_time float8,
|
||||
OUT tables_names text
|
||||
)
|
||||
RETURNS SETOF record
|
||||
AS 'MODULE_PATHNAME', 'pg_stat_monitor_1_3'
|
||||
AS 'MODULE_PATHNAME', 'pg_stat_monitor'
|
||||
LANGUAGE C STRICT VOLATILE PARALLEL SAFE;
|
||||
|
||||
CREATE FUNCTION pg_stat_agg(
|
||||
OUT queryid bigint,
|
||||
OUT queryid text,
|
||||
OUT id bigint,
|
||||
OUT type bigint,
|
||||
OUT total_calls int,
|
||||
OUT first_call_time timestamptz,
|
||||
OUT last_call_time timestamptz)
|
||||
OUT total_calls int)
|
||||
RETURNS SETOF record
|
||||
AS 'MODULE_PATHNAME', 'pg_stat_agg'
|
||||
LANGUAGE C STRICT VOLATILE PARALLEL SAFE;
|
||||
|
||||
-- Register a view on the function for ease of use.
|
||||
CREATE VIEW pg_stat_monitor AS
|
||||
SELECT * FROM pg_stat_monitor(true);
|
||||
CREATE VIEW pg_stat_monitor AS SELECT
|
||||
bucket,
|
||||
bucket_start_time,
|
||||
userid,
|
||||
dbid,
|
||||
queryid,
|
||||
query,
|
||||
calls,
|
||||
total_time,
|
||||
min_time,
|
||||
max_time,
|
||||
mean_time,
|
||||
stddev_time,
|
||||
rows int8,
|
||||
shared_blks_hit,
|
||||
shared_blks_read,
|
||||
shared_blks_dirtied,
|
||||
shared_blks_written,
|
||||
local_blks_hit,
|
||||
local_blks_read,
|
||||
local_blks_dirtied,
|
||||
local_blks_written,
|
||||
temp_blks_read,
|
||||
temp_blks_written,
|
||||
blk_read_time,
|
||||
blk_write_time,
|
||||
client_ip as host,
|
||||
'0.0.0.0'::inet + client_ip AS client_ip,
|
||||
(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);
|
||||
|
||||
GRANT SELECT ON pg_stat_monitor TO PUBLIC;
|
||||
|
||||
CREATE VIEW pg_stat_agg_database AS
|
||||
SELECT
|
||||
ss.bucket,
|
||||
agg.queryid,
|
||||
agg.id AS dbid,
|
||||
ss.userid,
|
||||
'0.0.0.0'::inet + ss.host AS host,
|
||||
client_ip,
|
||||
agg.total_calls,
|
||||
ss.min_time,
|
||||
ss.max_time,
|
||||
ss.mean_time,
|
||||
(string_to_array(hist_calls, ',')) hist_calls,
|
||||
(string_to_array(hist_min_time, ',')) hist_min_time,
|
||||
(string_to_array(hist_max_time, ',')) hist_max_time,
|
||||
(string_to_array(hist_mean_time, ',')) hist_mean_time,
|
||||
agg.first_call_time AS first_log_time,
|
||||
agg.last_call_time AS last_log_time,
|
||||
ss.resp_calls,
|
||||
ss.cpu_user_time,
|
||||
ss.cpu_sys_time,
|
||||
ss.query,
|
||||
ss.slow_query
|
||||
ss.tables_names
|
||||
FROM pg_stat_agg() agg
|
||||
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
|
||||
INNER JOIN (SELECT DISTINCT bucket, queryid, dbid, userid, query, client_ip, 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 = 0 AND id = dbid;
|
||||
|
||||
CREATE VIEW pg_stat_agg_user AS
|
||||
SELECT
|
||||
ss.bucket,
|
||||
agg.queryid,
|
||||
agg.id AS dbid,
|
||||
ss.userid,
|
||||
'0.0.0.0'::inet + ss.host AS host,
|
||||
client_ip,
|
||||
agg.total_calls,
|
||||
ss.min_time,
|
||||
ss.max_time,
|
||||
ss.mean_time,
|
||||
(string_to_array(hist_calls, ',')) hist_calls,
|
||||
(string_to_array(hist_min_time, ',')) hist_min_time,
|
||||
(string_to_array(hist_max_time, ',')) hist_max_time,
|
||||
(string_to_array(hist_mean_time, ',')) hist_mean_time,
|
||||
agg.first_call_time AS first_log_time,
|
||||
agg.last_call_time AS last_log_time,
|
||||
ss.resp_calls,
|
||||
ss.cpu_user_time,
|
||||
ss.cpu_sys_time,
|
||||
ss.query,
|
||||
ss.slow_query
|
||||
ss.tables_names
|
||||
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
|
||||
INNER JOIN (SELECT DISTINCT bucket, queryid, userid, query, client_ip, 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 = 1 AND id = userid;
|
||||
|
||||
CREATE VIEW pg_stat_agg_host AS
|
||||
CREATE VIEW pg_stat_agg_ip AS
|
||||
SELECT
|
||||
ss.bucket,
|
||||
agg.queryid,
|
||||
agg.id AS dbid,
|
||||
ss.userid,
|
||||
'0.0.0.0'::inet + ss.host AS host,
|
||||
ss.client_ip,
|
||||
ss.host,
|
||||
agg.total_calls,
|
||||
ss.min_time,
|
||||
ss.max_time,
|
||||
ss.mean_time,
|
||||
(string_to_array(hist_calls, ',')) hist_calls,
|
||||
(string_to_array(hist_min_time, ',')) hist_min_time,
|
||||
(string_to_array(hist_max_time, ',')) hist_max_time,
|
||||
(string_to_array(hist_mean_time, ',')) hist_mean_time,
|
||||
agg.first_call_time AS first_log_time,
|
||||
agg.last_call_time AS last_log_time,
|
||||
ss.resp_calls,
|
||||
ss.cpu_user_time,
|
||||
ss.cpu_sys_time,
|
||||
ss.query,
|
||||
ss.slow_query
|
||||
ss.tables_names
|
||||
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
|
||||
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;
|
||||
|
||||
-- Don't want this to be available to non-superusers.
|
||||
|
||||
Reference in New Issue
Block a user