summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAmit Kapila <akapila@postgresql.org>2023-05-04 08:33:56 +0530
committerAmit Kapila <akapila@postgresql.org>2023-05-04 08:33:56 +0530
commita6e04b1d20c2e9cece9b64bb5b36ebfdc3a9031b (patch)
tree4e00d33aa7195160eaeb929fa22b39e69f11d68c
parent1ab763fc22adc88e5d779817e7b42b25a9dd7c9e (diff)
downloadpostgresql-a6e04b1d20c2e9cece9b64bb5b36ebfdc3a9031b.tar.gz
Test that invalidated logical slots doesn't retain WAL.
Author: Bertrand Drouvot Reviewed-by: Shi yu, Amit Kapila, Vignesh C Discussion: https://postgr.es/m/2fefa454-5a70-2174-ddbf-4a0e41537139@gmail.com
-rw-r--r--src/test/recovery/t/035_standby_logical_decoding.pl38
1 files changed, 36 insertions, 2 deletions
diff --git a/src/test/recovery/t/035_standby_logical_decoding.pl b/src/test/recovery/t/035_standby_logical_decoding.pl
index 66d264f230..ad1def2474 100644
--- a/src/test/recovery/t/035_standby_logical_decoding.pl
+++ b/src/test/recovery/t/035_standby_logical_decoding.pl
@@ -500,9 +500,43 @@ $node_standby->restart;
check_slots_conflicting_status(1);
##################################################
-# Verify that invalidated logical slots do not lead to retaining WAL
+# Verify that invalidated logical slots do not lead to retaining WAL.
##################################################
-# XXXXX TODO
+
+# Wait for the cascading standby to catchup before removing the WAL file(s)
+$node_standby->wait_for_replay_catchup($node_cascading_standby, $node_primary);
+
+# Get the restart_lsn from an invalidated slot
+my $restart_lsn = $node_standby->safe_psql('postgres',
+ "SELECT restart_lsn from pg_replication_slots WHERE slot_name = 'vacuum_full_activeslot' and conflicting is true;"
+);
+
+chomp($restart_lsn);
+
+# As pg_walfile_name() can not be executed on the standby,
+# get the WAL file name associated to this lsn from the primary
+my $walfile_name = $node_primary->safe_psql('postgres',
+ "SELECT pg_walfile_name('$restart_lsn')");
+
+chomp($walfile_name);
+
+# Generate some activity and switch WAL file on the primary
+$node_primary->safe_psql(
+ 'postgres', "create table retain_test(a int);
+ select pg_switch_wal();
+ insert into retain_test values(1);
+ checkpoint;");
+
+# Wait for the standby to catch up
+$node_primary->wait_for_replay_catchup($node_standby);
+
+# Request a checkpoint on the standby to trigger the WAL file(s) removal
+$node_standby->safe_psql('postgres', 'checkpoint;');
+
+# Verify that the WAL file has not been retained on the standby
+my $standby_walfile = $node_standby->data_dir . '/pg_wal/' . $walfile_name;
+ok(!-f "$standby_walfile",
+ "invalidated logical slots do not lead to retaining WAL");
##################################################
# Recovery conflict: Invalidate conflicting slots, including in-use slots