From 2c14e1dc0845ab173e74ed64edf3aa3352d2d614 Mon Sep 17 00:00:00 2001 From: Diego Fronza Date: Fri, 21 Jan 2022 13:35:14 -0300 Subject: [PATCH] PG-338: Fix query call count (utilities). There was a missing increment/decrement to exec_nested_level in pgss_ProcessUtility hook, due to this, some utility statements could end up being processed more than once, as PostgreSQL may recurse into this hook for sub-statements or when processing a query string containing multiple semicolon-separated statements. --- pg_stat_monitor.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pg_stat_monitor.c b/pg_stat_monitor.c index bcc8e8b..5b2f007 100644 --- a/pg_stat_monitor.c +++ b/pg_stat_monitor.c @@ -986,6 +986,7 @@ static void pgss_ProcessUtility(PlannedStmt *pstmt, const char *queryString, WalUsage walusage_start = pgWalUsage; #endif INSTR_TIME_SET_CURRENT(start); + exec_nested_level++; PG_TRY(); { #if PG_VERSION_NUM >= 140000 @@ -1024,12 +1025,12 @@ static void pgss_ProcessUtility(PlannedStmt *pstmt, const char *queryString, dest, completionTag); #endif + exec_nested_level--; } PG_CATCH(); { exec_nested_level--; PG_RE_THROW(); - } PG_END_TRY();