Synchronize table list before creating slot in CREATE SUBSCRIPTION
authorPeter Eisentraut <peter_e@gmx.net>
Fri, 21 Apr 2017 12:35:24 +0000 (08:35 -0400)
committerPeter Eisentraut <peter_e@gmx.net>
Fri, 21 Apr 2017 12:37:03 +0000 (08:37 -0400)
This way a failure to synchronize the table list will not leave an
unused slot on the publisher.

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

src/backend/commands/subscriptioncmds.c

index 35dccbc0ad6204b4456fe4cade8b385bdf808be7..c29a57ed52d2bb4c9bc7045b00213e23821b007c 100644 (file)
@@ -394,20 +394,6 @@ CreateSubscription(CreateSubscriptionStmt *stmt, bool isTopLevel)
 
        PG_TRY();
        {
-           /*
-            * If requested, create permanent slot for the subscription.
-            * We won't use the initial snapshot for anything, so no need
-            * to export it.
-            */
-           if (create_slot)
-           {
-               walrcv_create_slot(wrconn, slotname, false,
-                                  CRS_NOEXPORT_SNAPSHOT, &lsn);
-               ereport(NOTICE,
-                       (errmsg("created replication slot \"%s\" on publisher",
-                               slotname)));
-           }
-
            /*
             * Set sync state based on if we were asked to do data copy or
             * not.
@@ -432,6 +418,20 @@ CreateSubscription(CreateSubscriptionStmt *stmt, bool isTopLevel)
 
            ereport(NOTICE,
                    (errmsg("synchronized table states")));
+
+           /*
+            * If requested, create permanent slot for the subscription.
+            * We won't use the initial snapshot for anything, so no need
+            * to export it.
+            */
+           if (create_slot)
+           {
+               walrcv_create_slot(wrconn, slotname, false,
+                                  CRS_NOEXPORT_SNAPSHOT, &lsn);
+               ereport(NOTICE,
+                       (errmsg("created replication slot \"%s\" on publisher",
+                               slotname)));
+           }
        }
        PG_CATCH();
        {