Dear developer: The patch submitted addresses #17663 in the pgsql-b...@lists.postgresql.org list. Problem: Add the parameters --enable-debug and --enable-cassert when the database is compiled. Driven by jdbc, the stored procedure containing rollbck is called, and an assertion occurs. Cause of the problem: Driven by jdbc, in the function BuildCachedPlan, the CachedPlan memory context is generated to save the execution plan (plan) of the input SQL. If the stored procedure contains rollback, call the function ReleaseCachedPlan to release the CachedPlan memory context. Therefore, before the function pgss_store collects statistical information, it is necessary to retain the stmt_location and stmt_len data required in pstmt, which will not be released by the cCachedPlan memory context, resulting in random values for the parameters required by the function pgss_store.?
From 4d02406b92339c561aa3b5deca96ca875473655a Mon Sep 17 00:00:00 2001 From: oracle <oracle@localhost.localdomain> Date: Tue, 1 Nov 2022 20:14:14 +0800 Subject: [PATCH] fix BUG #17663: Connect to the database through jdbc, call the stored procedure containing the rollback statement, the database triggers an assertion, and the database is in recovery mode
--- contrib/pg_stat_statements/pg_stat_statements.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/contrib/pg_stat_statements/pg_stat_statements.c b/contrib/pg_stat_statements/pg_stat_statements.c index 0beb56a..3330f35 100644 --- a/contrib/pg_stat_statements/pg_stat_statements.c +++ b/contrib/pg_stat_statements/pg_stat_statements.c @@ -1083,6 +1083,8 @@ pgss_ProcessUtility(PlannedStmt *pstmt, const char *queryString, { Node *parsetree = pstmt->utilityStmt; uint64 saved_queryId = pstmt->queryId; + int stmt_location = pstmt->stmt_location; + int stmt_len = pstmt->stmt_len; /* * Force utility statements to get queryId zero. We do this even in cases @@ -1172,8 +1174,8 @@ pgss_ProcessUtility(PlannedStmt *pstmt, const char *queryString, pgss_store(queryString, saved_queryId, - pstmt->stmt_location, - pstmt->stmt_len, + stmt_location, + stmt_len, PGSS_EXEC, INSTR_TIME_GET_MILLISEC(duration), rows, -- 1.8.3.1