From 409f384ce81b8d0e8abafa14a30536df939efd7e Mon Sep 17 00:00:00 2001 From: Diego Fronza Date: Mon, 11 Apr 2022 14:20:43 -0300 Subject: [PATCH] PG-369: Fix wal_bytes values on PG <= 12. Similar to pg_stat_statements, pg_stat_monitor tracks wal data metrics since PostgreSQL 13, the problem was that for PostgreSQL versions 11 and 12 we left the WalUsage variable declared in the stack unitialized, thus leading to garbage values. Fixed the problem by ignoring the WalUsage variable value for PG <= 12. --- pg_stat_monitor.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pg_stat_monitor.c b/pg_stat_monitor.c index 6978cd1..f3db2ad 100644 --- a/pg_stat_monitor.c +++ b/pg_stat_monitor.c @@ -989,9 +989,9 @@ static void pgss_ProcessUtility(PlannedStmt *pstmt, const char *queryString, instr_time duration; uint64 rows; BufferUsage bufusage; - WalUsage walusage; BufferUsage bufusage_start = pgBufferUsage; #if PG_VERSION_NUM >= 130000 + WalUsage walusage; WalUsage walusage_start = pgWalUsage; #endif INSTR_TIME_SET_CURRENT(start); @@ -1083,7 +1083,11 @@ static void pgss_ProcessUtility(PlannedStmt *pstmt, const char *queryString, INSTR_TIME_GET_MILLISEC(duration), /* total_time */ rows, /* rows */ &bufusage, /* bufusage */ +#if PG_VERSION_NUM >= 130000 &walusage, /* walusage */ +#else + NULL, /* walusage, NULL for PG <= 12 */ +#endif NULL, /* JumbleState */ PGSS_FINISHED); /* pgssStoreKind */ }