From 60427959308dd6610133f7ec04cb7e498c455b8b Mon Sep 17 00:00:00 2001 From: Diego Fronza Date: Thu, 9 Dec 2021 15:55:30 -0300 Subject: [PATCH] PG-293: Add pg_stat_monitor.extract_comments GUC. This new GUC allows the user to enable/disable extracting query comments. --- guc.c | 12 ++++++++++++ pg_stat_monitor.c | 7 +++++-- pg_stat_monitor.h | 7 ++++--- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/guc.c b/guc.c index 528318f..b7f5e08 100644 --- a/guc.c +++ b/guc.c @@ -191,6 +191,18 @@ init_guc(void) } DefineEnumGUC(&conf[i++], track_options); + conf[i] = (GucVariable) { + .guc_name = "pg_stat_monitor.extract_comments", + .guc_desc = "Enable/Disable extracting comments from queries.", + .guc_default = 0, + .guc_min = 0, + .guc_max = 0, + .guc_restart = false, + .guc_unit = 0, + .guc_value = &PGSM_EXTRACT_COMMENTS + }; + DefineBoolGUC(&conf[i++]); + #if PG_VERSION_NUM >= 130000 conf[i] = (GucVariable) { .guc_name = "pg_stat_monitor.pgsm_track_planning", diff --git a/pg_stat_monitor.c b/pg_stat_monitor.c index 4e33ad8..0e6a4ac 100644 --- a/pg_stat_monitor.c +++ b/pg_stat_monitor.c @@ -1496,8 +1496,6 @@ pgss_store(uint64 queryid, planid = plan_info ? plan_info->planid : 0; appid = djb2_hash((unsigned char *)application_name, application_name_len); - extract_query_comments(query, comments, sizeof(comments)); - prev_bucket_id = pg_atomic_read_u64(&pgss->current_wbucket); bucketid = get_next_wbucket(pgss); @@ -1608,6 +1606,10 @@ pgss_store(uint64 queryid, } if (jstate == NULL) + { + if (PGSM_EXTRACT_COMMENTS) + extract_query_comments(query, comments, sizeof(comments)); + pgss_update_entry(entry, /* entry */ bucketid, /* bucketid */ queryid, /* queryid */ @@ -1625,6 +1627,7 @@ pgss_store(uint64 queryid, kind, /* kind */ application_name, application_name_len); + } LWLockRelease(pgss->lock); if (norm_query) diff --git a/pg_stat_monitor.h b/pg_stat_monitor.h index eedc702..8cb78f9 100644 --- a/pg_stat_monitor.h +++ b/pg_stat_monitor.h @@ -95,9 +95,9 @@ #define SQLCODE_LEN 20 #if PG_VERSION_NUM >= 130000 -#define MAX_SETTINGS 14 +#define MAX_SETTINGS 15 #else -#define MAX_SETTINGS 13 +#define MAX_SETTINGS 14 #endif /* Update this if need a enum GUC with more options. */ @@ -443,7 +443,8 @@ static const struct config_enum_entry track_options[] = #define PGSM_OVERFLOW_TARGET get_conf(10)->guc_variable #define PGSM_QUERY_PLAN get_conf(11)->guc_variable #define PGSM_TRACK get_conf(12)->guc_variable -#define PGSM_TRACK_PLANNING get_conf(13)->guc_variable +#define PGSM_EXTRACT_COMMENTS get_conf(13)->guc_variable +#define PGSM_TRACK_PLANNING get_conf(14)->guc_variable /*---- Benchmarking ----*/