]> granicus.if.org Git - postgresql/commitdiff
More synchronous replication tweaks.
authorRobert Haas <rhaas@postgresql.org>
Thu, 10 Mar 2011 20:38:39 +0000 (15:38 -0500)
committerRobert Haas <rhaas@postgresql.org>
Thu, 10 Mar 2011 20:43:37 +0000 (15:43 -0500)
SyncRepRequested() must check not only the value of the
synchronous_replication GUC but also whether max_wal_senders > 0.
Otherwise, we might end up waiting for sync rep even when there's no
possibility of a standby ever managing to connect.  There are some
existing cross-checks to prevent this, but they're not quite sufficient:
the user can start the server with max_wal_senders=0,
synchronous_standby_names='', and synchronous_replication=off and then
subsequent make synchronous_standby_names not empty using pg_ctl reload,
and then SET synchronous_standby=on, leading to an indefinite hang.

Along the way, rename the global variable for the synchronous_replication
GUC to match the name of the GUC itself, for clarity.

Report by Fujii Masao, though I didn't use his patch.

src/backend/replication/syncrep.c
src/backend/utils/misc/guc.c
src/include/replication/syncrep.h

index 0033b5559f382a33b58f5489c1f56214a7466ea3..ff6b328b38214d00972e19449506eb1b568d2811 100644 (file)
@@ -62,7 +62,7 @@
 #include "utils/ps_status.h"
 
 /* User-settable parameters for sync rep */
-bool   sync_rep_mode = false;                  /* Only set in user backends */
+bool   synchronous_replication = false;                /* Only set in user backends */
 char   *SyncRepStandbyNames;
 
 static bool sync_standbys_defined = false;     /* Is there at least one name? */
index 0bf1845599558c98a863c24b6c8e145fef8b5df0..d1b1c1742775358725656e56a6a8ab528ad13712 100644 (file)
@@ -759,7 +759,7 @@ static struct config_bool ConfigureNamesBool[] =
                        gettext_noop("Requests synchronous replication."),
                        NULL
                },
-               &sync_rep_mode,
+               &synchronous_replication,
                false, NULL, NULL
        },
        {
index 1c6d39238c4a63d5ef6c5bbffc790136e76cb361..9171eb61766e7b4934ce9ba58fa60822c8cf195c 100644 (file)
@@ -19,7 +19,8 @@
 #include "storage/spin.h"
 #include "utils/guc.h"
 
-#define SyncRepRequested()                             (sync_rep_mode)
+#define SyncRepRequested() \
+       (synchronous_replication && max_wal_senders > 0)
 
 /* syncRepState */
 #define SYNC_REP_NOT_WAITING           0
@@ -28,7 +29,7 @@
 #define SYNC_REP_MUST_DISCONNECT       3
 
 /* user-settable parameters for synchronous replication */
-extern bool sync_rep_mode;
+extern bool synchronous_replication;
 extern char *SyncRepStandbyNames;
 
 /* called by user backend */