Fix BF introduced in commit ddd5f4f54a.
authorAmit Kapila <akapila@postgresql.org>
Wed, 14 Feb 2024 10:46:08 +0000 (16:16 +0530)
committerAmit Kapila <akapila@postgresql.org>
Wed, 14 Feb 2024 10:46:08 +0000 (16:16 +0530)
The failure is that the remote slot is not synchronized after the same
slot on standby gets invalidated. The reason was that remote_slot's
restart_lsn was lagged behind the standby's oldest WAL segment. The test
didn't ensure that remote_slot's LSN was advanced to the latest position
before we tried to sync the slots via new the function
pg_sync_replication_slots().

Discussion: https://postgr.es/m/CAA4eK1JLBi3HzenB6do3_hd78kN0UDD1mz-vumWE52XHHEq5Bw@mail.gmail.com

src/test/recovery/t/040_standby_failover_slots_sync.pl

index c96515d178ba7c880627d615f9e9713d20408770..9634a50b3ec3551eb46b594d96047146bc77efb7 100644 (file)
@@ -171,7 +171,7 @@ $standby1->safe_psql('postgres', "SELECT pg_sync_replication_slots();");
 # flagged as 'synced'
 is( $standby1->safe_psql(
        'postgres',
-       q{SELECT count(*) = 2 FROM pg_replication_slots WHERE slot_name IN ('lsub1_slot', 'lsub2_slot') AND synced;}
+       q{SELECT count(*) = 2 FROM pg_replication_slots WHERE slot_name IN ('lsub1_slot', 'lsub2_slot') AND synced AND NOT temporary;}
    ),
    "t",
    'logical slots have synced as true on standby');
@@ -227,6 +227,13 @@ $standby1->reload;
 $subscriber1->safe_psql('postgres',
    "ALTER SUBSCRIPTION regress_mysub1 ENABLE");
 
+# This wait ensures that confirmed_flush_lsn has been moved to latest
+# position.
+$primary->wait_for_catchup('regress_mysub1');
+
+# To ensure that restart_lsn has moved to a recent WAL position, we need
+# to log XLOG_RUNNING_XACTS and make sure the same is processed as well
+$primary->psql('postgres', "CHECKPOINT");
 $primary->wait_for_catchup('regress_mysub1');
 
 # Do not allow any further advancement of the restart_lsn for the lsub1_slot.
@@ -256,7 +263,7 @@ $standby1->wait_for_log(qr/dropped replication slot "lsub1_slot" of dbid [0-9]+/
 # flagged as 'synced'
 is( $standby1->safe_psql(
        'postgres',
-       q{SELECT conflict_reason IS NULL AND synced FROM pg_replication_slots WHERE slot_name = 'lsub1_slot';}
+       q{SELECT conflict_reason IS NULL AND synced AND NOT temporary FROM pg_replication_slots WHERE slot_name = 'lsub1_slot';}
    ),
    "t",
    'logical slot is re-synced');