From 23cbadeeb4738b8f5e615f0c5a2ef7af6111d512 Mon Sep 17 00:00:00 2001 From: Alexander Korotkov Date: Mon, 20 Apr 2026 13:05:55 +0300 Subject: [PATCH] 049_wait_for_lsn.pl: create function and procedure at once Create the PL/pgSQL function and procedure for the top-level WAIT FOR checks in a single transaction, then wait once for standby replay before running both tests. Also revise some surrounding comments. This avoids an extra 'wait_for_catchup()' on the delayed standby without changing the test coverage. Discussion: https://postgr.es/m/CABPTF7WZ1yuYz8V%3Dxsbghg8e7qaAm5MpyNw6BthWcbN7%2BP6biw%40mail.gmail.com Author: Xuneng Zhou Reviewed-by: Alexander Korotkov --- src/test/recovery/t/049_wait_for_lsn.pl | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/test/recovery/t/049_wait_for_lsn.pl b/src/test/recovery/t/049_wait_for_lsn.pl index 8358c57f7b7..0e74175f9eb 100644 --- a/src/test/recovery/t/049_wait_for_lsn.pl +++ b/src/test/recovery/t/049_wait_for_lsn.pl @@ -172,8 +172,8 @@ ok($output eq "timeout", "WAIT FOR returns correct status after timeout"); # 5. Check mode validation: standby modes error on primary, primary mode errors # on standby, and primary_flush works on primary. Also check that WAIT FOR -# triggers an error if called within another function or inside a transaction -# with an isolation level higher than READ COMMITTED. +# triggers an error if called within a function, procedure, anonymous DO block, +# or inside a transaction with an isolation level higher than READ COMMITTED. # Test standby_flush on primary - should error $node_primary->psql( @@ -200,6 +200,8 @@ ok( $stderr =~ "get an error when running in a transaction with an isolation level higher than REPEATABLE READ" ); +# Test wrapping WAIT FOR into function, procedure, and anonymous DO block -- +# should error $node_primary->safe_psql( 'postgres', qq[ CREATE FUNCTION pg_wal_replay_wait_wrap(target_lsn pg_lsn) RETURNS void AS \$\$ @@ -208,6 +210,13 @@ CREATE FUNCTION pg_wal_replay_wait_wrap(target_lsn pg_lsn) RETURNS void AS \$\$ END \$\$ LANGUAGE plpgsql; + +CREATE PROCEDURE pg_wal_replay_wait_proc(target_lsn pg_lsn) AS \$\$ + BEGIN + EXECUTE format('WAIT FOR LSN %L;', target_lsn); + END +\$\$ +LANGUAGE plpgsql; ]); $node_primary->wait_for_catchup($node_standby); @@ -218,17 +227,6 @@ $node_standby->psql( ok($stderr =~ /WAIT FOR can only be executed as a top-level statement/, "get an error when running within a function"); -$node_primary->safe_psql( - 'postgres', qq[ -CREATE PROCEDURE pg_wal_replay_wait_proc(target_lsn pg_lsn) AS \$\$ - BEGIN - EXECUTE format('WAIT FOR LSN %L;', target_lsn); - END -\$\$ -LANGUAGE plpgsql; -]); - -$node_primary->wait_for_catchup($node_standby); $node_standby->psql( 'postgres', "CALL pg_wal_replay_wait_proc('${lsn3}');",