OSDN Git Service

Add replication_mode in postgresql.conf
authorMasaoFujii <masao.fujii@gmail.com>
Mon, 22 Nov 2010 02:44:41 +0000 (11:44 +0900)
committerMasaoFujii <masao.fujii@gmail.com>
Mon, 22 Nov 2010 02:51:38 +0000 (11:51 +0900)
src/backend/access/transam/xlog.c
src/backend/utils/misc/guc.c
src/backend/utils/misc/postgresql.conf.sample
src/include/access/xlog.h

index 014819f..7082a2c 100644 (file)
@@ -77,6 +77,7 @@ bool          fullPageWrites = true;
 bool           log_checkpoints = false;
 int                    sync_method = DEFAULT_SYNC_METHOD;
 int                    wal_level = WAL_LEVEL_MINIMAL;
+int                    replication_mode = REPLICATION_MODE_ASYNC;
 
 #ifdef WAL_DEBUG
 bool           XLOG_DEBUG = false;
@@ -105,6 +106,14 @@ const struct config_enum_entry wal_level_options[] = {
        {NULL, 0, false}
 };
 
+const struct config_enum_entry replication_mode_options[] = {
+       {"async", REPLICATION_MODE_ASYNC, false},
+       {"recv", REPLICATION_MODE_RECV, false},
+       {"fsync", REPLICATION_MODE_FSYNC, false},
+       {"apply", REPLICATION_MODE_APPLY, false},
+       {NULL, 0, false}
+};
+
 const struct config_enum_entry sync_method_options[] = {
        {"fsync", SYNC_METHOD_FSYNC, false},
 #ifdef HAVE_FSYNC_WRITETHROUGH
index 362daae..d13a364 100644 (file)
@@ -339,6 +339,7 @@ static const struct config_enum_entry constraint_exclusion_options[] = {
  * Options for enum values stored in other modules
  */
 extern const struct config_enum_entry wal_level_options[];
+extern const struct config_enum_entry replication_mode_options[];
 extern const struct config_enum_entry sync_method_options[];
 
 /*
@@ -2827,6 +2828,15 @@ static struct config_enum ConfigureNamesEnum[] =
        },
 
        {
+               {"replication_mode", PGC_POSTMASTER, WAL_STANDBY_SERVERS,
+                       gettext_noop("Set the synchronization mode of replication."),
+                       NULL
+               },
+               &replication_mode,
+               REPLICATION_MODE_ASYNC, replication_mode_options, NULL
+       },
+
+       {
                {"wal_sync_method", PGC_SIGHUP, WAL_SETTINGS,
                        gettext_noop("Selects the method used for forcing WAL updates to disk."),
                        NULL
index 366ad69..19896e4 100644 (file)
 #max_standby_streaming_delay = 30s     # max delay before canceling queries
                                        # when reading streaming WAL;
                                        # -1 allows indefinite delay
+#replication_mode = async                      # async, recv, fsync, or apply
+                                       # (change requires restart)
 
 
 #------------------------------------------------------------------------------
index ea156d3..a4a1f33 100644 (file)
@@ -220,6 +220,31 @@ extern int wal_level;
 /* Do we need to WAL-log information required only for Hot Standby? */
 #define XLogStandbyInfoActive() (wal_level >= WAL_LEVEL_HOT_STANDBY)
 
+/*
+ * Replication mode. This is used to identify how long transaction
+ * commit should wait for replication.
+ *
+ * REPLICATION_MODE_ASYNC doesn't make transaction commit wait for
+ * replication, i.e., asynchronous replication.
+ *
+ * REPLICATION_MODE_RECV makes transaction commit wait for XLOG
+ * records to be received on the standby.
+ *
+ * REPLICATION_MODE_FSYNC makes transaction commit wait for XLOG
+ * records to be received and fsync'd on the standby.
+ *
+ * REPLICATION_MODE_APPLY makes transaction commit wait for XLOG
+ * records to be received, fsync'd and applied on the standby.
+ */
+typedef enum ReplicationMode
+{
+       REPLICATION_MODE_ASYNC = 0,
+       REPLICATION_MODE_RECV,
+       REPLICATION_MODE_FSYNC,
+       REPLICATION_MODE_APPLY
+} ReplicationMode;
+extern int     replication_mode;
+
 #ifdef WAL_DEBUG
 extern bool XLOG_DEBUG;
 #endif