@@ -500,9 +500,43 @@ sub check_for_invalidation
500
500
check_slots_conflicting_status(1);
501
501
502
502
# #################################################
503
- # Verify that invalidated logical slots do not lead to retaining WAL
503
+ # Verify that invalidated logical slots do not lead to retaining WAL.
504
504
# #################################################
505
- # XXXXX TODO
505
+
506
+ # Wait for the cascading standby to catchup before removing the WAL file(s)
507
+ $node_standby -> wait_for_replay_catchup($node_cascading_standby , $node_primary );
508
+
509
+ # Get the restart_lsn from an invalidated slot
510
+ my $restart_lsn = $node_standby -> safe_psql(' postgres' ,
511
+ " SELECT restart_lsn from pg_replication_slots WHERE slot_name = 'vacuum_full_activeslot' and conflicting is true;"
512
+ );
513
+
514
+ chomp ($restart_lsn );
515
+
516
+ # As pg_walfile_name() can not be executed on the standby,
517
+ # get the WAL file name associated to this lsn from the primary
518
+ my $walfile_name = $node_primary -> safe_psql(' postgres' ,
519
+ " SELECT pg_walfile_name('$restart_lsn ')" );
520
+
521
+ chomp ($walfile_name );
522
+
523
+ # Generate some activity and switch WAL file on the primary
524
+ $node_primary -> safe_psql(
525
+ ' postgres' , " create table retain_test(a int);
526
+ select pg_switch_wal();
527
+ insert into retain_test values(1);
528
+ checkpoint;" );
529
+
530
+ # Wait for the standby to catch up
531
+ $node_primary -> wait_for_replay_catchup($node_standby );
532
+
533
+ # Request a checkpoint on the standby to trigger the WAL file(s) removal
534
+ $node_standby -> safe_psql(' postgres' , ' checkpoint;' );
535
+
536
+ # Verify that the WAL file has not been retained on the standby
537
+ my $standby_walfile = $node_standby -> data_dir . ' /pg_wal/' . $walfile_name ;
538
+ ok(!-f " $standby_walfile " ,
539
+ " invalidated logical slots do not lead to retaining WAL" );
506
540
507
541
# #################################################
508
542
# Recovery conflict: Invalidate conflicting slots, including in-use slots
0 commit comments