From b5d4d9a130658859bcf6e21ca3bed131dbdddb57 Mon Sep 17 00:00:00 2001 From: Petr Jelinek Date: Fri, 7 Jul 2017 00:04:43 +0200 Subject: [PATCH 2/6] Exit in sync worker if relation was removed during startup --- src/backend/replication/logical/tablesync.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/backend/replication/logical/tablesync.c b/src/backend/replication/logical/tablesync.c index 32abf5b..9fbdd8c 100644 --- a/src/backend/replication/logical/tablesync.c +++ b/src/backend/replication/logical/tablesync.c @@ -824,6 +824,20 @@ LogicalRepSyncTableStart(XLogRecPtr *origin_startpos) relstate = GetSubscriptionRelState(MyLogicalRepWorker->subid, MyLogicalRepWorker->relid, &relstate_lsn, true); + /* + * The relation is not locked during startup of sync worker so it's + * possible that it has been removed in meantime. Exit gracefully in that + * case as it's perfectly normal scenario. + */ + if (relstate == SUBREL_STATE_UNKNOWN) + { + ereport(LOG, + (errmsg("logical replication table synchronization worker for subscription \"%s\", " + "table \"%s\" will stop because the table is no longer subscribed", + MySubscription->name, + get_rel_name(MyLogicalRepWorker->relid)))); + proc_exit(0); + } CommitTransactionCommand(); SpinLockAcquire(&MyLogicalRepWorker->relmutex); -- 2.7.4