From b23df84af94a4be5c771dd5bdc69385da9225db7 Mon Sep 17 00:00:00 2001 From: Ibrar Ahmed Date: Mon, 12 Oct 2020 17:54:44 +0000 Subject: [PATCH] Issue - (#52): Create a function to return the build version. Jira: PG-142 --- pg_stat_monitor--1.0.sql | 12 ++++++++---- pg_stat_monitor.c | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/pg_stat_monitor--1.0.sql b/pg_stat_monitor--1.0.sql index c6d2d1f..84b5546 100644 --- a/pg_stat_monitor--1.0.sql +++ b/pg_stat_monitor--1.0.sql @@ -9,17 +9,21 @@ RETURNS void AS 'MODULE_PATHNAME' LANGUAGE C PARALLEL SAFE; +CREATE FUNCTION pg_stat_monitor_version() +RETURNS text +AS 'MODULE_PATHNAME' +LANGUAGE C PARALLEL SAFE; + CREATE FUNCTION pg_stat_monitor(IN showtext boolean, OUT bucket int, OUT userid oid, OUT dbid oid, OUT client_ip bigint, - + OUT queryid text, OUT query text, OUT bucket_start_time timestamptz, - OUT plan_calls int8, OUT plan_total_time float8, OUT plan_min_time float8, @@ -27,7 +31,7 @@ CREATE FUNCTION pg_stat_monitor(IN showtext boolean, OUT plan_mean_time float8, OUT plan_stddev_time float8, OUT plan_rows int8, - + OUT total_calls int8, OUT total_time float8, OUT min_time float8, @@ -35,7 +39,7 @@ CREATE FUNCTION pg_stat_monitor(IN showtext boolean, OUT mean_time float8, OUT stddev_time float8, OUT affected_rows int8, - + OUT shared_blks_hit int8, OUT shared_blks_read int8, OUT shared_blks_dirtied int8, diff --git a/pg_stat_monitor.c b/pg_stat_monitor.c index 581cdd9..3992280 100644 --- a/pg_stat_monitor.c +++ b/pg_stat_monitor.c @@ -16,6 +16,8 @@ PG_MODULE_MAGIC; +#define BUILD_VERSION "0.6.0" + /*---- Initicalization Function Declarations ----*/ void _PG_init(void); void _PG_fini(void); @@ -45,6 +47,7 @@ static ExecutorEnd_hook_type prev_ExecutorEnd = NULL; static ProcessUtility_hook_type prev_ProcessUtility = NULL; +PG_FUNCTION_INFO_V1(pg_stat_monitor_version); PG_FUNCTION_INFO_V1(pg_stat_monitor_reset); PG_FUNCTION_INFO_V1(pg_stat_monitor_1_2); PG_FUNCTION_INFO_V1(pg_stat_monitor_1_3); @@ -194,6 +197,17 @@ _PG_fini(void) hash_entry_reset(); } +/* + * Select the version of pg_stat_monitor. + */ +Datum +pg_stat_monitor_version(PG_FUNCTION_ARGS) +{ + PG_RETURN_TEXT_P(cstring_to_text(BUILD_VERSION)); +} + +#define PG_STAT_STATEMENTS_COLS 38 /* maximum of above */ + /* * Post-parse-analysis hook: mark query with a queryId */