Handle change of slot name in logical replication apply
authorPeter Eisentraut <peter_e@gmx.net>
Mon, 3 Apr 2017 15:10:28 +0000 (11:10 -0400)
committerPeter Eisentraut <peter_e@gmx.net>
Mon, 3 Apr 2017 15:10:28 +0000 (11:10 -0400)
Since change of slot name is a supported operation, handle it more
gracefully, instead of in the this-should-not-happen way.

Author: Petr Jelinek <petr.jelinek@2ndquadrant.com>

src/backend/replication/logical/worker.c

index bbf3506be04db63cb5150223f4efc0f524bda2eb..d6986f59c1c0a4b09b4c231805f201bfb2509d71 100644 (file)
@@ -1350,6 +1350,21 @@ reread_subscription(void)
        proc_exit(0);
    }
 
+   /*
+    * We need to make new connection to new slot if slot name has changed
+    * so exit here as well if that's the case.
+    */
+   if (strcmp(newsub->slotname, MySubscription->slotname) != 0)
+   {
+       ereport(LOG,
+               (errmsg("logical replication worker for subscription \"%s\" will "
+                       "restart because the replication slot name was changed",
+                       MySubscription->name)));
+
+       walrcv_disconnect(wrconn);
+       proc_exit(0);
+   }
+
    /*
     * Exit if publication list was changed. The launcher will start
     * new worker.
@@ -1382,8 +1397,7 @@ reread_subscription(void)
    }
 
    /* Check for other changes that should never happen too. */
-   if (newsub->dbid != MySubscription->dbid ||
-       strcmp(newsub->slotname, MySubscription->slotname) != 0)
+   if (newsub->dbid != MySubscription->dbid)
    {
        elog(ERROR, "subscription %u changed unexpectedly",
             MyLogicalRepWorker->subid);