From 41eb480a5c52c3ebcee4488e38bef5b8aed59ff5 Mon Sep 17 00:00:00 2001 From: Xuneng Zhou Date: Tue, 19 May 2026 22:11:04 -0700 Subject: [PATCH] Stabilize replslot limit test after standby catchup 019_replslot_limit.pl checks primary-side WAL availability for a physical replication slot after stopping and restarting a standby. wait_for_catchup() now waits for the standby to reach the target LSN locally, so it can return before the primary has processed standby feedback and advanced the slot's restart_lsn. Make the test wait explicitly for that slot advancement before stopping the standby. --- src/test/recovery/t/019_replslot_limit.pl | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/test/recovery/t/019_replslot_limit.pl b/src/test/recovery/t/019_replslot_limit.pl index 7b253e64d9c..0c43acdf8a7 100644 --- a/src/test/recovery/t/019_replslot_limit.pl +++ b/src/test/recovery/t/019_replslot_limit.pl @@ -12,6 +12,16 @@ use PostgreSQL::Test::Cluster; use Test::More; use Time::HiRes qw(usleep); +sub wait_for_standby_and_slot_catchup +{ + my ($primary, $standby, $slot_name) = @_; + + my $target_lsn = $primary->lsn('write'); + + $primary->wait_for_catchup($standby, 'replay', $target_lsn); + $primary->wait_for_slot_catchup($slot_name, 'restart', $target_lsn); +} + # Initialize primary node, setting wal-segsize to 1MB my $node_primary = PostgreSQL::Test::Cluster->new('primary'); $node_primary->init(allows_streaming => 1, extra => ['--wal-segsize=1']); @@ -44,8 +54,9 @@ $node_standby->append_conf('postgresql.conf', "primary_slot_name = 'rep1'"); $node_standby->start; -# Wait until standby has replayed enough data -$node_primary->wait_for_catchup($node_standby); +# Wait until the standby has replayed enough data, and the primary has +# processed feedback advancing the slot's restart_lsn. +wait_for_standby_and_slot_catchup($node_primary, $node_standby, 'rep1'); # Stop standby $node_standby->stop; @@ -79,7 +90,7 @@ is($result, "reserved|t", 'check that slot is working'); # The standby can reconnect to primary $node_standby->start; -$node_primary->wait_for_catchup($node_standby); +wait_for_standby_and_slot_catchup($node_primary, $node_standby, 'rep1'); $node_standby->stop; @@ -109,7 +120,7 @@ is($result, "reserved", # The standby can reconnect to primary $node_standby->start; -$node_primary->wait_for_catchup($node_standby); +wait_for_standby_and_slot_catchup($node_primary, $node_standby, 'rep1'); $node_standby->stop; # wal_keep_size overrides max_slot_wal_keep_size @@ -128,7 +139,7 @@ $result = $node_primary->safe_psql('postgres', # The standby can reconnect to primary $node_standby->start; -$node_primary->wait_for_catchup($node_standby); +wait_for_standby_and_slot_catchup($node_primary, $node_standby, 'rep1'); $node_standby->stop; # Advance WAL again without checkpoint, reducing remain by 6 MB. @@ -155,7 +166,7 @@ is($result, "unreserved|t", # The standby still can connect to primary before a checkpoint $node_standby->start; -$node_primary->wait_for_catchup($node_standby); +wait_for_standby_and_slot_catchup($node_primary, $node_standby, 'rep1'); $node_standby->stop; -- 2.50.1 (Apple Git-155)