aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRobert Haas <rhaas@postgresql.org>2011-04-04 16:13:01 -0400
committerRobert Haas <rhaas@postgresql.org>2011-04-04 16:25:52 -0400
commit240067b3b0ff989d2b28f4f917f7958f2ec76b05 (patch)
tree385e0e13abda1024fc6a5cd8a81583a3a86366bd /src
parentfc3459d70c5d842fe6519522649c8a47454f25bb (diff)
downloadpostgresql-240067b3b0ff989d2b28f4f917f7958f2ec76b05.tar.gz
postgresql-240067b3b0ff989d2b28f4f917f7958f2ec76b05.zip
Merge synchronous_replication setting into synchronous_commit.
This means one less thing to configure when setting up synchronous replication, and also avoids some ambiguity around what the behavior should be when the settings of these variables conflict. Fujii Masao, with additional hacking by me.
Diffstat (limited to 'src')
-rw-r--r--src/backend/access/transam/xact.c5
-rw-r--r--src/backend/postmaster/autovacuum.c3
-rw-r--r--src/backend/replication/syncrep.c1
-rw-r--r--src/backend/utils/misc/guc.c43
-rw-r--r--src/backend/utils/misc/postgresql.conf.sample6
-rw-r--r--src/include/access/xact.h11
-rw-r--r--src/include/replication/syncrep.h3
7 files changed, 43 insertions, 29 deletions
diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c
index c8b582cce8e..503506f1f0d 100644
--- a/src/backend/access/transam/xact.c
+++ b/src/backend/access/transam/xact.c
@@ -68,7 +68,7 @@ bool XactReadOnly;
bool DefaultXactDeferrable = false;
bool XactDeferrable;
-bool XactSyncCommit = true;
+int synchronous_commit = SYNCHRONOUS_COMMIT_ON;
int CommitDelay = 0; /* precommit delay in microseconds */
int CommitSiblings = 5; /* # concurrent xacts needed to sleep */
@@ -1056,7 +1056,8 @@ RecordTransactionCommit(void)
* if all to-be-deleted tables are temporary though, since they are lost
* anyway if we crash.)
*/
- if ((wrote_xlog && XactSyncCommit) || forceSyncCommit || nrels > 0 || SyncRepRequested())
+ if ((wrote_xlog && synchronous_commit >= SYNCHRONOUS_COMMIT_LOCAL) ||
+ forceSyncCommit || nrels > 0)
{
/*
* Synchronous commit case:
diff --git a/src/backend/postmaster/autovacuum.c b/src/backend/postmaster/autovacuum.c
index efc8e7cc82c..675bfced63c 100644
--- a/src/backend/postmaster/autovacuum.c
+++ b/src/backend/postmaster/autovacuum.c
@@ -1531,7 +1531,8 @@ AutoVacWorkerMain(int argc, char *argv[])
* if we are waiting for standbys to connect. This is important to
* ensure we aren't blocked from performing anti-wraparound tasks.
*/
- SetConfigOption("synchronous_replication", "off", PGC_SUSET, PGC_S_OVERRIDE);
+ if (synchronous_commit == SYNCHRONOUS_COMMIT_ON)
+ SetConfigOption("synchronous_commit", "local", PGC_SUSET, PGC_S_OVERRIDE);
/*
* Get the info about the database we're going to work on.
diff --git a/src/backend/replication/syncrep.c b/src/backend/replication/syncrep.c
index 17c255480eb..0d338146510 100644
--- a/src/backend/replication/syncrep.c
+++ b/src/backend/replication/syncrep.c
@@ -63,7 +63,6 @@
#include "utils/ps_status.h"
/* User-settable parameters for sync rep */
-bool synchronous_replication = false; /* Only set in user backends */
char *SyncRepStandbyNames;
#define SyncStandbysDefined() \
diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c
index b49bdaea9d0..1f7a7d24f83 100644
--- a/src/backend/utils/misc/guc.c
+++ b/src/backend/utils/misc/guc.c
@@ -351,6 +351,23 @@ static const struct config_enum_entry constraint_exclusion_options[] = {
};
/*
+ * Although only "on", "off", and "local" are documented, we
+ * accept all the likely variants of "on" and "off".
+ */
+static const struct config_enum_entry synchronous_commit_options[] = {
+ {"local", SYNCHRONOUS_COMMIT_LOCAL, false},
+ {"on", SYNCHRONOUS_COMMIT_ON, false},
+ {"off", SYNCHRONOUS_COMMIT_OFF, false},
+ {"true", SYNCHRONOUS_COMMIT_ON, true},
+ {"false", SYNCHRONOUS_COMMIT_OFF, true},
+ {"yes", SYNCHRONOUS_COMMIT_ON, true},
+ {"no", SYNCHRONOUS_COMMIT_OFF, true},
+ {"1", SYNCHRONOUS_COMMIT_ON, true},
+ {"0", SYNCHRONOUS_COMMIT_OFF, true},
+ {NULL, 0, false}
+};
+
+/*
* Options for enum values stored in other modules
*/
extern const struct config_enum_entry wal_level_options[];
@@ -747,22 +764,6 @@ static struct config_bool ConfigureNamesBool[] =
true, NULL, NULL
},
{
- {"synchronous_commit", PGC_USERSET, WAL_SETTINGS,
- gettext_noop("Sets immediate fsync at commit."),
- NULL
- },
- &XactSyncCommit,
- true, NULL, NULL
- },
- {
- {"synchronous_replication", PGC_USERSET, WAL_REPLICATION,
- gettext_noop("Requests synchronous replication."),
- NULL
- },
- &synchronous_replication,
- false, NULL, NULL
- },
- {
{"zero_damaged_pages", PGC_SUSET, DEVELOPER_OPTIONS,
gettext_noop("Continues processing past damaged page headers."),
gettext_noop("Detection of a damaged page header normally causes PostgreSQL to "
@@ -2909,6 +2910,16 @@ static struct config_enum ConfigureNamesEnum[] =
},
{
+ {"synchronous_commit", PGC_USERSET, WAL_SETTINGS,
+ gettext_noop("Sets the current transaction's synchronization level."),
+ NULL
+ },
+ &synchronous_commit,
+ SYNCHRONOUS_COMMIT_ON, synchronous_commit_options,
+ NULL, NULL
+ },
+
+ {
{"trace_recovery_messages", PGC_SIGHUP, DEVELOPER_OPTIONS,
gettext_noop("Enables logging of recovery-related debugging information."),
gettext_noop("Each level includes all the levels that follow it. The later"
diff --git a/src/backend/utils/misc/postgresql.conf.sample b/src/backend/utils/misc/postgresql.conf.sample
index 43481859993..b8a1582eaa9 100644
--- a/src/backend/utils/misc/postgresql.conf.sample
+++ b/src/backend/utils/misc/postgresql.conf.sample
@@ -153,7 +153,7 @@
#wal_level = minimal # minimal, archive, or hot_standby
# (change requires restart)
#fsync = on # turns forced synchronization on or off
-#synchronous_commit = on # immediate fsync at commit
+#synchronous_commit = on # synchronization level; on, off, or local
#wal_sync_method = fsync # the default is the first option
# supported by the operating system:
# open_datasync
@@ -184,10 +184,6 @@
#archive_timeout = 0 # force a logfile segment switch after this
# number of seconds; 0 disables
-# - Replication - User Settings
-
-#synchronous_replication = off # does commit wait for reply from standby
-
# - Streaming Replication - Server Settings
#synchronous_standby_names = '' # standby servers that provide sync rep
diff --git a/src/include/access/xact.h b/src/include/access/xact.h
index 1685a0167f5..44101453445 100644
--- a/src/include/access/xact.h
+++ b/src/include/access/xact.h
@@ -52,8 +52,15 @@ extern bool XactReadOnly;
extern bool DefaultXactDeferrable;
extern bool XactDeferrable;
-/* Asynchronous commits */
-extern bool XactSyncCommit;
+typedef enum
+{
+ SYNCHRONOUS_COMMIT_OFF, /* asynchronous commit */
+ SYNCHRONOUS_COMMIT_LOCAL, /* wait for only local flush */
+ SYNCHRONOUS_COMMIT_ON /* wait for local flush and sync rep */
+} SyncCommitLevel;
+
+/* Synchronous commit level */
+extern int synchronous_commit;
/* Kluge for 2PC support */
extern bool MyXactAccessedTempRel;
diff --git a/src/include/replication/syncrep.h b/src/include/replication/syncrep.h
index 188ec65745c..696edccb120 100644
--- a/src/include/replication/syncrep.h
+++ b/src/include/replication/syncrep.h
@@ -20,7 +20,7 @@
#include "utils/guc.h"
#define SyncRepRequested() \
- (synchronous_replication && max_wal_senders > 0)
+ (max_wal_senders > 0 && synchronous_commit == SYNCHRONOUS_COMMIT_ON)
/* syncRepState */
#define SYNC_REP_NOT_WAITING 0
@@ -28,7 +28,6 @@
#define SYNC_REP_WAIT_COMPLETE 2
/* user-settable parameters for synchronous replication */
-extern bool synchronous_replication;
extern char *SyncRepStandbyNames;
/* called by user backend */