Improve messaging during logical replication worker startup
authorPeter Eisentraut <[email protected]>
Fri, 6 Apr 2018 13:07:09 +0000 (09:07 -0400)
committerPeter Eisentraut <[email protected]>
Fri, 6 Apr 2018 13:07:09 +0000 (09:07 -0400)
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]>
src/backend/replication/logical/worker.c

index 93a42d9322cd73a043726e348ff5b3172a6a3e04..b10857550a6105ec509c607c5b38961d3006b358 100644 (file)
@@ -1553,14 +1553,20 @@ ApplyWorkerMain(Datum main_arg)
                                                                                 ALLOCSET_DEFAULT_SIZES);
        StartTransactionCommand();
        oldctx = MemoryContextSwitchTo(ApplyContext);
-       MySubscription = GetSubscription(MyLogicalRepWorker->subid, false);
+
+       MySubscription = GetSubscription(MyLogicalRepWorker->subid, true);
+       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,
@@ -1571,6 +1577,10 @@ ApplyWorkerMain(Datum main_arg)
                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,