From 805bcfb8af27472dc5b59ff210b512345730c69e Mon Sep 17 00:00:00 2001 From: MasaoFujii Date: Mon, 22 Nov 2010 11:44:41 +0900 Subject: [PATCH] Add replication_mode in postgresql.conf --- src/backend/access/transam/xlog.c | 9 +++++++++ src/backend/utils/misc/guc.c | 10 ++++++++++ src/backend/utils/misc/postgresql.conf.sample | 2 ++ src/include/access/xlog.h | 25 +++++++++++++++++++++++++ 4 files changed, 46 insertions(+) diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index 014819f766..7082a2c8ec 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -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 diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c index 362daaeefd..d13a36492a 100644 --- a/src/backend/utils/misc/guc.c +++ b/src/backend/utils/misc/guc.c @@ -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 diff --git a/src/backend/utils/misc/postgresql.conf.sample b/src/backend/utils/misc/postgresql.conf.sample index 366ad6988c..19896e4a15 100644 --- a/src/backend/utils/misc/postgresql.conf.sample +++ b/src/backend/utils/misc/postgresql.conf.sample @@ -202,6 +202,8 @@ #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) #------------------------------------------------------------------------------ diff --git a/src/include/access/xlog.h b/src/include/access/xlog.h index ea156d3834..a4a1f33296 100644 --- a/src/include/access/xlog.h +++ b/src/include/access/xlog.h @@ -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 -- 2.11.0