diff --git a/src/test/recovery/t/038_save_logical_slots_shutdown.pl b/src/test/recovery/t/038_save_logical_slots_shutdown.pl
index 5a4f5dc1d4..1fddab78b1 100644
--- a/src/test/recovery/t/038_save_logical_slots_shutdown.pl
+++ b/src/test/recovery/t/038_save_logical_slots_shutdown.pl
@@ -81,6 +81,8 @@ is($result, qq(5), "check initial copy was done");
 
 my $offset = -s $node_publisher->logfile;
 
+$node_publisher->safe_psql('postgres', "SELECT pg_switch_wal()");
+
 # Restart the publisher to ensure that the slot will be flushed if required
 $node_publisher->restart();
 
