0002-Add-regression-tests-for-WAIT-FOR-LSN-inside-PL-pgSQ.patch

application/octet-stream

Filename: 0002-Add-regression-tests-for-WAIT-FOR-LSN-inside-PL-pgSQ.patch
Type: application/octet-stream
Part: 0
Message: Bug: WAIT FOR LSN crashes with assertion failure inside PL/pgSQL DO blocks and procedures

Patch

Same data as JSON: GET /api/v1/attachments/:id/patch the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes. API reference →
Format: format-patch
Series: patch v1-0002
Subject: Add regression tests for WAIT FOR LSN inside PL/pgSQL
File+
src/test/recovery/t/049_wait_for_lsn.pl 35 0
From d82c0f0d207537defadc25e8ef8f69cd3dc28b32 Mon Sep 17 00:00:00 2001
From: Satya Narlapuram <satyanarlapuram@gmail.com>
Date: Thu, 9 Apr 2026 00:50:43 +0000
Subject: [PATCH v1 2/2] Add regression tests for WAIT FOR LSN inside PL/pgSQL

Add test section 7f to 049_wait_for_lsn.pl covering WAIT FOR LSN ...
INTO inside PL/pgSQL DO blocks and procedures.

---
 src/test/recovery/t/049_wait_for_lsn.pl | 35 +++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/src/test/recovery/t/049_wait_for_lsn.pl b/src/test/recovery/t/049_wait_for_lsn.pl
index bf61b8c4..11d3611d 100644
--- a/src/test/recovery/t/049_wait_for_lsn.pl
+++ b/src/test/recovery/t/049_wait_for_lsn.pl
@@ -587,6 +587,41 @@ $output = $node_primary->safe_psql('postgres',
 ok($output >= 0,
 	"multiple primary_flush waiters: primary flushed WAL up to target LSN");
 
+# Use an already-replayed LSN so the WAIT returns immediately on standby.
+my $wait_into_lsn = $node_standby->safe_psql('postgres',
+	"SELECT pg_last_wal_replay_lsn()");
+
+# 7f. Test DO block with WAIT FOR INTO followed by RAISE NOTICE on standby.
+$node_standby->safe_psql(
+	'postgres', qq[
+	DO \$\$
+	DECLARE
+	  result text;
+	BEGIN
+	  WAIT FOR LSN '${wait_into_lsn}' INTO result;
+	  RAISE NOTICE 'got: %', result;
+	END;
+	\$\$;]);
+ok(1, "WAIT FOR INTO in DO block does not crash on standby");
+
+# Test void procedure with WAIT FOR INTO followed by RAISE on standby.
+$node_primary->safe_psql(
+	'postgres', qq[
+	CREATE PROCEDURE test_wait_into_raise()
+	LANGUAGE plpgsql AS \$\$
+	DECLARE
+	  result text;
+	BEGIN
+	  WAIT FOR LSN '${wait_into_lsn}' INTO result;
+	  RAISE NOTICE 'wait result: %', result;
+	END;
+	\$\$;]);
+$node_primary->wait_for_catchup($node_standby);
+
+$node_standby->safe_psql('postgres',
+	"CALL test_wait_into_raise()");
+ok(1, "WAIT FOR INTO in void procedure does not crash on standby");
+
 # 8. Check that the standby promotion terminates all standby wait modes.  Start
 # waiting for unreachable LSNs with standby_replay, standby_write, and
 # standby_flush modes, then promote.  Check the log for the relevant error
-- 
2.43.0