diff --git a/src/backend/replication/logical/worker.c b/src/backend/replication/logical/worker.c index 04985c9..f8785b0 100644 --- a/src/backend/replication/logical/worker.c +++ b/src/backend/replication/logical/worker.c @@ -1533,24 +1533,32 @@ ApplyWorkerMain(Datum main_arg) ALLOCSET_DEFAULT_SIZES); StartTransactionCommand(); oldctx = MemoryContextSwitchTo(ApplyContext); - MySubscription = GetSubscription(MyLogicalRepWorker->subid, false); + MySubscription = GetSubscription(MyLogicalRepWorker->subid, ture); + + if (!MySubscription) + { + ereport(LOG, + (errmsg("logical replication apply worker for subscription %u will not start because the subscription was removed during startup", + MyLogicalRepWorker->subid))); + proc_exit(0); + } + MySubscriptionValid = true; MemoryContextSwitchTo(oldctx); - /* Setup synchronous commit according to the user's wishes */ - SetConfigOption("synchronous_commit", MySubscription->synccommit, - PGC_BACKEND, PGC_S_OVERRIDE); - if (!MySubscription->enabled) { ereport(LOG, - (errmsg("logical replication apply worker for subscription \"%s\" will not " - "start because the subscription was disabled during startup", + (errmsg("logical replication apply worker for subscription \"%s\" will not start because the subscription was disabled during startup", MySubscription->name))); proc_exit(0); } + /* Setup synchronous commit according to the user's wishes */ + SetConfigOption("synchronous_commit", MySubscription->synccommit, + PGC_BACKEND, PGC_S_OVERRIDE); + /* Keep us informed about subscription changes. */ CacheRegisterSyscacheCallback(SUBSCRIPTIONOID, subscription_change_cb,