Hi Alexander, Hackers, While working on adding more edge-case tests and fixing the timeline handling for WAIT FOR LSN, I noticed that the overall runtime of the test had increased by about 7 seconds since a8b61c23c5ff. I looked into the slowdown and found a potential source.
Currently, the test creates the function, waits for the standby to catch up, tests it, then creates the procedure and waits for the standby to catch up again. Since both objects are only used by the same block of top-level statement checks, we can create them together in a single primary-side transaction and perform just one wait_for_catchup() before running both standby-side calls. This small TAP cleanup merges the creation of the PL/pgSQL wrapper function and procedure used for the top-level WAIT FOR checks in 049_wait_for_lsn.pl. The change preserves the same coverage while removing one redundant replay catch-up on the delayed standby. It appears to reduce the test runtime by about 7 seconds, though I have looked into why much of the improvement comes from this change alone. Patch attached. Thanks. -- Best, Xuneng
From 5d67a5b2f37423e69f3a71d351feae349aaf25a9 Mon Sep 17 00:00:00 2001 From: alterego655 <[email protected]> Date: Fri, 17 Apr 2026 20:08:59 +0800 Subject: [PATCH v1] test: merge wrapper DDL and catchup in wait_for_lsn TAP 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. This avoids an extra 'wait_for_catchup()' on the delayed standby without changing the test coverage. --- src/test/recovery/t/049_wait_for_lsn.pl | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 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..11adcda1e9a 100644 --- a/src/test/recovery/t/049_wait_for_lsn.pl +++ b/src/test/recovery/t/049_wait_for_lsn.pl @@ -208,18 +208,7 @@ CREATE FUNCTION pg_wal_replay_wait_wrap(target_lsn pg_lsn) RETURNS void AS \$\$ END \$\$ LANGUAGE plpgsql; -]); - -$node_primary->wait_for_catchup($node_standby); -$node_standby->psql( - 'postgres', - "SELECT pg_wal_replay_wait_wrap('${lsn3}');", - stderr => \$stderr); -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); @@ -229,6 +218,13 @@ LANGUAGE plpgsql; ]); $node_primary->wait_for_catchup($node_standby); +$node_standby->psql( + 'postgres', + "SELECT pg_wal_replay_wait_wrap('${lsn3}');", + stderr => \$stderr); +ok($stderr =~ /WAIT FOR can only be executed as a top-level statement/, + "get an error when running within a function"); + $node_standby->psql( 'postgres', "CALL pg_wal_replay_wait_proc('${lsn3}');", -- 2.51.0
