public inbox for [email protected]  
help / color / mirror / Atom feed
From: Xuneng Zhou <[email protected]>
To: pgsql-hackers <[email protected]>
To: Alexander Korotkov <[email protected]>
Subject: test: avoid redundant standby catchup in 049_wait_for_lsn
Date: Fri, 17 Apr 2026 20:25:35 +0800
Message-ID: <CABPTF7WZ1yuYz8V=xsbghg8e7qaAm5MpyNw6BthWcbN7+P6biw@mail.gmail.com> (raw)

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


Attachments:

  [application/x-patch] v1-0001-test-merge-wrapper-DDL-and-catchup-in-wait_for_ls.patch (1.8K, 2-v1-0001-test-merge-wrapper-DDL-and-catchup-in-wait_for_ls.patch)
  download | inline diff:
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



view thread (7+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected]
  Subject: Re: test: avoid redundant standby catchup in 049_wait_for_lsn
  In-Reply-To: <CABPTF7WZ1yuYz8V=xsbghg8e7qaAm5MpyNw6BthWcbN7+P6biw@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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