diff --git a/src/backend/commands/subscriptioncmds.c b/src/backend/commands/subscriptioncmds.c index bf7fbb79341..4c01d21b2f3 100644 --- a/src/backend/commands/subscriptioncmds.c +++ b/src/backend/commands/subscriptioncmds.c @@ -1802,7 +1802,13 @@ DropSubscription(DropSubscriptionStmt *stmt, bool isTopLevel) List *rstates; bool must_use_password; - rel = table_open(SubscriptionRelationId, AccessShareLock); + /* + * The launcher may concurrently start a new worker for this subscription. + * During initialization, the worker checks for subscription validity and + * exits if the subscription has already been dropped. See + * InitializeLogRepWorker. + */ + rel = table_open(SubscriptionRelationId, RowExclusiveLock); tup = SearchSysCache2(SUBSCRIPTIONNAME, ObjectIdGetDatum(MyDatabaseId), CStringGetDatum(stmt->subname)); diff --git a/src/backend/replication/logical/worker.c b/src/backend/replication/logical/worker.c index 4688becd34f..1c2c9889be7 100644 --- a/src/backend/replication/logical/worker.c +++ b/src/backend/replication/logical/worker.c @@ -5417,7 +5417,8 @@ InitializeLogRepWorker(void) /* * Lock the subscription to prevent it from being concurrently dropped, - * then re-verify its existence. + * then re-verify its existence. After the initialization, the worker will + * be terminated gracefully if the subscription is dropped. */ LockSharedObject(SubscriptionRelationId, MyLogicalRepWorker->subid, 0, AccessShareLock); @@ -5432,18 +5433,9 @@ InitializeLogRepWorker(void) if (am_leader_apply_worker()) ApplyLauncherForgetWorkerStartTime(MyLogicalRepWorker->subid); - /* - * The shared object lock on subid is automatically released by - * proc_exit(), so no explicit unlock is necessary here. - */ - proc_exit(0); } - /* - * The shared object lock on subid will be released at transaction end. - */ - MySubscriptionValid = true; MemoryContextSwitchTo(oldctx);