pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
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.
2+ messages / 2 participants
[nested] [flat]

* 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.
@ 2022-11-01 12:57 =?gb2312?B?1dTG5Lnw?= <zhaoqg45023@hundsun.com>
  2022-11-01 16:01 ` Re: 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. Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 2+ messages in thread

From: 赵其桂 @ 2022-11-01 12:57 UTC (permalink / raw)
  To: pgsql-hackers@lists.postgresql.org <pgsql-hackers@lists.postgresql.org>; +Cc: 402142054@qq.com <402142054@qq.com>

Dear developer:
The patch submitted addresses #17663 in the pgsql-bugs@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



Attachments:

  [text/plain] 0001-fix-BUG-17663-Connect-to-the-database-through-jdbc-c.patch (1.4K, ../../1667307420050.56657@hundsun.com/2-0001-fix-BUG-17663-Connect-to-the-database-through-jdbc-c.patch)
  download | inline diff:
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



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: 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.
  2022-11-01 12:57 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. =?gb2312?B?1dTG5Lnw?= <zhaoqg45023@hundsun.com>
@ 2022-11-01 16:01 ` Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 2+ messages in thread

From: Tom Lane @ 2022-11-01 16:01 UTC (permalink / raw)
  To: 赵其桂 <zhaoqg45023@hundsun.com>; +Cc: pgsql-hackers@lists.postgresql.org <pgsql-hackers@lists.postgresql.org>; 402142054@qq.com <402142054@qq.com>

=?gb2312?B?1dTG5Lnw?= <zhaoqg45023@hundsun.com> writes:
> The patch submitted addresses #17663 in the pgsql-bugs@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.?

Indeed ... thanks for the patch!

			regards, tom lane





^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2022-11-01 16:01 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2022-11-01 12:57 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. =?gb2312?B?1dTG5Lnw?= <zhaoqg45023@hundsun.com>
2022-11-01 16:01 ` Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox