From 40afdce2eb0f5bfd3393dc6967fe15afbba7ffff Mon Sep 17 00:00:00 2001 From: Ibrar Ahmed Date: Tue, 15 Nov 2022 17:10:42 +0000 Subject: [PATCH] PG-552: Remove unnecessary columns from PostgreSQL 11 and 12 views. There was a typo while checking the PostgreSQL version in the SQL file. This commit will fix the typo, and only the necessary columns will be visible in the view. --- pg_stat_monitor--1.0.sql | 17 ++++++++--------- pg_stat_monitor--2.0.sql | 18 +++++++++--------- pg_stat_monitor.c | 7 +++++-- 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/pg_stat_monitor--1.0.sql b/pg_stat_monitor--1.0.sql index 51873b4..1e4e0f9 100644 --- a/pg_stat_monitor--1.0.sql +++ b/pg_stat_monitor--1.0.sql @@ -195,7 +195,6 @@ CREATE VIEW pg_stat_monitor AS SELECT datname, '0.0.0.0'::inet + client_ip AS client_ip, queryid, - toplevel, top_queryid, query, comments, @@ -210,11 +209,11 @@ CREATE VIEW pg_stat_monitor AS SELECT sqlcode, message, calls, - total_exec_time, - min_exec_time, - max_exec_time, - mean_exec_time, - stddev_exec_time, + total_exec_time AS total_time, + min_exec_time AS min_time, + max_exec_time AS max_time, + mean_exec_time AS mean_time, + stddev_exec_time AS stddev_time, rows_retrieved, shared_blks_hit, shared_blks_read, @@ -373,13 +372,13 @@ $$ DECLARE ver integer; BEGIN SELECT current_setting('server_version_num') INTO ver; - IF (ver >= 14000) THEN + IF (ver >= 140000) THEN return pgsm_create_14_view(); END IF; - IF (ver >= 13000) THEN + IF (ver >= 130000) THEN return pgsm_create_13_view(); END IF; - IF (ver >= 11000) THEN + IF (ver >= 110000) THEN return pgsm_create_11_view(); END IF; RETURN 0; diff --git a/pg_stat_monitor--2.0.sql b/pg_stat_monitor--2.0.sql index f3e299a..b2eb83a 100644 --- a/pg_stat_monitor--2.0.sql +++ b/pg_stat_monitor--2.0.sql @@ -116,8 +116,9 @@ CREATE FUNCTION pg_stat_monitor_internal( OUT planid text, OUT query text, OUT query_plan text, + OUT state_code int8, OUT top_queryid text, - OUT top_query text, + OUT top_query text, OUT application_name text, OUT relations text, -- 11 @@ -181,7 +182,6 @@ CREATE VIEW pg_stat_monitor AS SELECT datname, '0.0.0.0'::inet + client_ip AS client_ip, queryid, - toplevel, top_queryid, query, comments, @@ -197,10 +197,10 @@ CREATE VIEW pg_stat_monitor AS SELECT message, calls, total_exec_time, - min_exec_time, - max_exec_time, - mean_exec_time, - stddev_exec_time, + min_time, + max_time, + mean_time, + stddev_time, rows_retrieved, shared_blks_hit, shared_blks_read, @@ -352,13 +352,13 @@ $$ DECLARE ver integer; BEGIN SELECT current_setting('server_version_num') INTO ver; - IF (ver >= 14000) THEN + IF (ver >= 140000) THEN return pgsm_create_14_view(); END IF; - IF (ver >= 13000) THEN + IF (ver >= 130000) THEN return pgsm_create_13_view(); END IF; - IF (ver >= 11000) THEN + IF (ver >= 110000) THEN return pgsm_create_11_view(); END IF; RETURN 0; diff --git a/pg_stat_monitor.c b/pg_stat_monitor.c index 9147d67..76cf180 100644 --- a/pg_stat_monitor.c +++ b/pg_stat_monitor.c @@ -1627,7 +1627,7 @@ pg_stat_monitor_internal(FunctionCallInfo fcinfo, if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE) elog(ERROR, "pg_stat_monitor: return type must be a row type"); - if (tupdesc->natts != 50) + if (tupdesc->natts != 51) elog(ERROR, "pg_stat_monitor: incorrect number of output arguments, required %d", tupdesc->natts); tupstore = tuplestore_begin_heap(true, false, work_mem); @@ -1772,7 +1772,10 @@ pg_stat_monitor_internal(FunctionCallInfo fcinfo, values[i++] = CStringGetTextDatum(""); } - /* parentid at column number 8 */ + /* state at column number 8 */ + values[i++] = Int64GetDatumFast(tmp.state); + + /* parentid at column number 9 */ if (tmp.info.parentid != UINT64CONST(0)) { snprintf(parentid_txt, 32, "%08lX", tmp.info.parentid);