Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c25304a

Browse files
committed
Improve messaging during logical replication worker startup
In case the subscription is removed before the worker is fully started, give a specific error message instead of the generic "cache lookup" error. Author: Petr Jelinek <[email protected]> Reviewed-by: Masahiko Sawada <[email protected]>
1 parent 2cd6520 commit c25304a

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/backend/replication/logical/worker.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1553,14 +1553,20 @@ ApplyWorkerMain(Datum main_arg)
15531553
ALLOCSET_DEFAULT_SIZES);
15541554
StartTransactionCommand();
15551555
oldctx = MemoryContextSwitchTo(ApplyContext);
1556-
MySubscription = GetSubscription(MyLogicalRepWorker->subid, false);
1556+
1557+
MySubscription = GetSubscription(MyLogicalRepWorker->subid, true);
1558+
if (!MySubscription)
1559+
{
1560+
ereport(LOG,
1561+
(errmsg("logical replication apply worker for subscription %u will not "
1562+
"start because the subscription was removed during startup",
1563+
MyLogicalRepWorker->subid)));
1564+
proc_exit(0);
1565+
}
1566+
15571567
MySubscriptionValid = true;
15581568
MemoryContextSwitchTo(oldctx);
15591569

1560-
/* Setup synchronous commit according to the user's wishes */
1561-
SetConfigOption("synchronous_commit", MySubscription->synccommit,
1562-
PGC_BACKEND, PGC_S_OVERRIDE);
1563-
15641570
if (!MySubscription->enabled)
15651571
{
15661572
ereport(LOG,
@@ -1571,6 +1577,10 @@ ApplyWorkerMain(Datum main_arg)
15711577
proc_exit(0);
15721578
}
15731579

1580+
/* Setup synchronous commit according to the user's wishes */
1581+
SetConfigOption("synchronous_commit", MySubscription->synccommit,
1582+
PGC_BACKEND, PGC_S_OVERRIDE);
1583+
15741584
/* Keep us informed about subscription changes. */
15751585
CacheRegisterSyscacheCallback(SUBSCRIPTIONOID,
15761586
subscription_change_cb,

0 commit comments

Comments
 (0)