diff --git a/src/backend/replication/logical/tablesync.c b/src/backend/replication/logical/tablesync.c index 682c107e74..7dc8e6a476 100644 --- a/src/backend/replication/logical/tablesync.c +++ b/src/backend/replication/logical/tablesync.c @@ -1064,16 +1064,9 @@ LogicalRepSyncTableStart(XLogRecPtr *origin_startpos) * Create a new permanent logical decoding slot. This slot will be used * for the catchup phase after COPY is done, so tell it to use the * snapshot to make the final data consistent. - * - * Prevent cancel/die interrupts while creating slot here because it is - * possible that before the server finishes this command, a concurrent - * drop subscription happens which would complete without removing this - * slot leading to a dangling slot on the server. */ - HOLD_INTERRUPTS(); walrcv_create_slot(LogRepWorkerWalRcvConn, slotname, false /* permanent */ , CRS_USE_SNAPSHOT, origin_startpos); - RESUME_INTERRUPTS(); /* * Setup replication origin tracking. The purpose of doing this before the diff --git a/src/test/subscription/t/004_sync.pl b/src/test/subscription/t/004_sync.pl index 959e47fad5..545599b8f8 100644 --- a/src/test/subscription/t/004_sync.pl +++ b/src/test/subscription/t/004_sync.pl @@ -163,9 +163,13 @@ $result = $node_subscriber->poll_query_until('postgres', $started_query) # subscriber is stuck on data copy for constraint violation. $node_subscriber->safe_psql('postgres', "DROP SUBSCRIPTION tap_sub"); -$result = $node_publisher->safe_psql('postgres', - "SELECT count(*) FROM pg_replication_slots"); -is($result, qq(0), +# When DROP SUBSCRIPTION tries to drop the tablesync slot, the slot may not +# have been created, which causes the slot to be created after the DROP +# SUSCRIPTION finishes. Such slots eventually get dropped at walsender exit +# time. So, to prevent being affected by such ephemeral tablesync slots, we +# wait until all the slots have been cleaned. +ok( $node_publisher->poll_query_until( + 'postgres', 'SELECT count(*) = 0 FROM pg_replication_slots'), 'DROP SUBSCRIPTION during error can clean up the slots on the publisher'); $node_subscriber->stop('fast');