Commit b555ed81 authored by Peter Eisentraut's avatar Peter Eisentraut

Merge wal_level "archive" and "hot_standby" into new name "replica"

The distinction between "archive" and "hot_standby" existed only because
at the time "hot_standby" was added, there was some uncertainty about
stability.  This is now a long time ago.  We would like to move forward
with simplifying the replication configuration, but this distinction is
in the way, because a primary server cannot tell (without asking a
standby or predicting the future) which one of these would be the
appropriate level.

Pick a new name for the combined setting to make it clearer that it
covers all (non-logical) backup and replication uses.  The old values
are still accepted but are converted internally.
Reviewed-by: default avatarMichael Paquier <michael.paquier@gmail.com>
Reviewed-by: default avatarDavid Steele <david@pgmasters.net>
parent 4e1d2a17
...@@ -592,7 +592,7 @@ tar -cf backup.tar /usr/local/pgsql/data ...@@ -592,7 +592,7 @@ tar -cf backup.tar /usr/local/pgsql/data
<para> <para>
To enable WAL archiving, set the <xref linkend="guc-wal-level"> To enable WAL archiving, set the <xref linkend="guc-wal-level">
configuration parameter to <literal>archive</> or higher, configuration parameter to <literal>replica</> or higher,
<xref linkend="guc-archive-mode"> to <literal>on</>, <xref linkend="guc-archive-mode"> to <literal>on</>,
and specify the shell command to use in the <xref and specify the shell command to use in the <xref
linkend="guc-archive-command"> configuration parameter. In practice linkend="guc-archive-command"> configuration parameter. In practice
...@@ -1285,7 +1285,7 @@ restore_command = 'cp /mnt/server/archivedir/%f %p' ...@@ -1285,7 +1285,7 @@ restore_command = 'cp /mnt/server/archivedir/%f %p'
If more flexibility in copying the backup files is needed, a lower If more flexibility in copying the backup files is needed, a lower
level process can be used for standalone hot backups as well. level process can be used for standalone hot backups as well.
To prepare for low level standalone hot backups, set <varname>wal_level</> to To prepare for low level standalone hot backups, set <varname>wal_level</> to
<literal>archive</> or higher, <varname>archive_mode</> to <literal>replica</> or higher, <varname>archive_mode</> to
<literal>on</>, and set up an <varname>archive_command</> that performs <literal>on</>, and set up an <varname>archive_command</> that performs
archiving only when a <emphasis>switch file</> exists. For example: archiving only when a <emphasis>switch file</> exists. For example:
<programlisting> <programlisting>
......
...@@ -2029,9 +2029,9 @@ include_dir 'conf.d' ...@@ -2029,9 +2029,9 @@ include_dir 'conf.d'
<varname>wal_level</> determines how much information is written <varname>wal_level</> determines how much information is written
to the WAL. The default value is <literal>minimal</>, which writes to the WAL. The default value is <literal>minimal</>, which writes
only the information needed to recover from a crash or immediate only the information needed to recover from a crash or immediate
shutdown. <literal>archive</> adds logging required for WAL archiving; shutdown. <literal>replica</> adds logging required for WAL
<literal>hot_standby</> further adds information required to run archiving as well as information required to run
read-only queries on a standby server; and, finally read-only queries on a standby server. Finally,
<literal>logical</> adds information necessary to support logical <literal>logical</> adds information necessary to support logical
decoding. Each level includes the information logged at all lower decoding. Each level includes the information logged at all lower
levels. This parameter can only be set at server start. levels. This parameter can only be set at server start.
...@@ -2049,30 +2049,24 @@ include_dir 'conf.d' ...@@ -2049,30 +2049,24 @@ include_dir 'conf.d'
transaction</member> transaction</member>
</simplelist> </simplelist>
But minimal WAL does not contain enough information to reconstruct the But minimal WAL does not contain enough information to reconstruct the
data from a base backup and the WAL logs, so <literal>archive</> or data from a base backup and the WAL logs, so <literal>replica</> or
higher must be used to enable WAL archiving higher must be used to enable WAL archiving
(<xref linkend="guc-archive-mode">) and streaming replication. (<xref linkend="guc-archive-mode">) and streaming replication.
</para> </para>
<para>
In <literal>hot_standby</> level, the same information is logged as
with <literal>archive</>, plus information needed to reconstruct
the status of running transactions from the WAL. To enable read-only
queries on a standby server, <varname>wal_level</> must be set to
<literal>hot_standby</> or higher on the primary, and
<xref linkend="guc-hot-standby"> must be enabled in the standby. It is
thought that there is little measurable difference in performance
between using <literal>hot_standby</> and <literal>archive</> levels,
so feedback is welcome if any production impacts are noticeable.
</para>
<para> <para>
In <literal>logical</> level, the same information is logged as In <literal>logical</> level, the same information is logged as
with <literal>hot_standby</>, plus information needed to allow with <literal>replica</>, plus information needed to allow
extracting logical change sets from the WAL. Using a level of extracting logical change sets from the WAL. Using a level of
<literal>logical</> will increase the WAL volume, particularly if many <literal>logical</> will increase the WAL volume, particularly if many
tables are configured for <literal>REPLICA IDENTITY FULL</literal> and tables are configured for <literal>REPLICA IDENTITY FULL</literal> and
many <command>UPDATE</> and <command>DELETE</> statements are many <command>UPDATE</> and <command>DELETE</> statements are
executed. executed.
</para> </para>
<para>
In releases prior to 9.6, this parameter also allowed the
values <literal>archive</literal> and <literal>hot_standby</literal>.
These are still accepted but mapped to <literal>replica</literal>.
</para>
</listitem> </listitem>
</varlistentry> </varlistentry>
...@@ -2784,7 +2778,7 @@ include_dir 'conf.d' ...@@ -2784,7 +2778,7 @@ include_dir 'conf.d'
higher than the maximum number of expected clients so disconnected higher than the maximum number of expected clients so disconnected
clients can immediately reconnect. This parameter can only clients can immediately reconnect. This parameter can only
be set at server start. <varname>wal_level</> must be set to be set at server start. <varname>wal_level</> must be set to
<literal>archive</> or higher to allow connections from standby <literal>replica</> or higher to allow connections from standby
servers. servers.
</para> </para>
</listitem> </listitem>
...@@ -2803,7 +2797,7 @@ include_dir 'conf.d' ...@@ -2803,7 +2797,7 @@ include_dir 'conf.d'
can support. The default is zero. This parameter can only be set at can support. The default is zero. This parameter can only be set at
server start. server start.
<varname>wal_level</varname> must be set <varname>wal_level</varname> must be set
to <literal>archive</literal> or higher to allow replication slots to to <literal>replica</literal> or higher to allow replication slots to
be used. Setting it to a lower value than the number of currently be used. Setting it to a lower value than the number of currently
existing replication slots will prevent the server from starting. existing replication slots will prevent the server from starting.
</para> </para>
......
...@@ -1988,7 +1988,7 @@ LOG: database system is ready to accept read only connections ...@@ -1988,7 +1988,7 @@ LOG: database system is ready to accept read only connections
Consistency information is recorded once per checkpoint on the primary. Consistency information is recorded once per checkpoint on the primary.
It is not possible to enable hot standby when reading WAL It is not possible to enable hot standby when reading WAL
written during a period when <varname>wal_level</> was not set to written during a period when <varname>wal_level</> was not set to
<literal>hot_standby</> or <literal>logical</> on the primary. Reaching <literal>replica</> or <literal>logical</> on the primary. Reaching
a consistent state can also be delayed in the presence of both of these a consistent state can also be delayed in the presence of both of these
conditions: conditions:
......
...@@ -108,7 +108,7 @@ ALTER SYSTEM RESET ALL ...@@ -108,7 +108,7 @@ ALTER SYSTEM RESET ALL
<para> <para>
Set the <literal>wal_level</>: Set the <literal>wal_level</>:
<programlisting> <programlisting>
ALTER SYSTEM SET wal_level = hot_standby; ALTER SYSTEM SET wal_level = replica;
</programlisting> </programlisting>
</para> </para>
......
...@@ -477,7 +477,7 @@ pg_upgrade.exe ...@@ -477,7 +477,7 @@ pg_upgrade.exe
<para> <para>
In the new master cluster, change <varname>wal_level</> to In the new master cluster, change <varname>wal_level</> to
<literal>hot_standby</> in the <filename>postgresql.conf</> file <literal>replica</> in the <filename>postgresql.conf</> file
and then start and stop the cluster. and then start and stop the cluster.
</para> </para>
</step> </step>
......
...@@ -25,8 +25,9 @@ ...@@ -25,8 +25,9 @@
*/ */
const struct config_enum_entry wal_level_options[] = { const struct config_enum_entry wal_level_options[] = {
{"minimal", WAL_LEVEL_MINIMAL, false}, {"minimal", WAL_LEVEL_MINIMAL, false},
{"archive", WAL_LEVEL_ARCHIVE, false}, {"replica", WAL_LEVEL_REPLICA, false},
{"hot_standby", WAL_LEVEL_HOT_STANDBY, false}, {"archive", WAL_LEVEL_REPLICA, true}, /* deprecated */
{"hot_standby", WAL_LEVEL_REPLICA, true}, /* deprecated */
{"logical", WAL_LEVEL_LOGICAL, false}, {"logical", WAL_LEVEL_LOGICAL, false},
{NULL, 0, false} {NULL, 0, false}
}; };
......
...@@ -1254,7 +1254,7 @@ RecordTransactionCommit(void) ...@@ -1254,7 +1254,7 @@ RecordTransactionCommit(void)
* this case, but we don't currently try to do that. It would certainly * this case, but we don't currently try to do that. It would certainly
* cause problems at least in Hot Standby mode, where the * cause problems at least in Hot Standby mode, where the
* KnownAssignedXids machinery requires tracking every XID assignment. It * KnownAssignedXids machinery requires tracking every XID assignment. It
* might be OK to skip it only when wal_level < hot_standby, but for now * might be OK to skip it only when wal_level < replica, but for now
* we don't.) * we don't.)
* *
* However, if we're doing cleanup of any non-temp rels or committing any * However, if we're doing cleanup of any non-temp rels or committing any
......
...@@ -5866,7 +5866,7 @@ static void ...@@ -5866,7 +5866,7 @@ static void
CheckRequiredParameterValues(void) CheckRequiredParameterValues(void)
{ {
/* /*
* For archive recovery, the WAL must be generated with at least 'archive' * For archive recovery, the WAL must be generated with at least 'replica'
* wal_level. * wal_level.
*/ */
if (ArchiveRecoveryRequested && ControlFile->wal_level == WAL_LEVEL_MINIMAL) if (ArchiveRecoveryRequested && ControlFile->wal_level == WAL_LEVEL_MINIMAL)
...@@ -5877,15 +5877,15 @@ CheckRequiredParameterValues(void) ...@@ -5877,15 +5877,15 @@ CheckRequiredParameterValues(void)
} }
/* /*
* For Hot Standby, the WAL must be generated with 'hot_standby' mode, and * For Hot Standby, the WAL must be generated with 'replica' mode, and
* we must have at least as many backend slots as the primary. * we must have at least as many backend slots as the primary.
*/ */
if (ArchiveRecoveryRequested && EnableHotStandby) if (ArchiveRecoveryRequested && EnableHotStandby)
{ {
if (ControlFile->wal_level < WAL_LEVEL_HOT_STANDBY) if (ControlFile->wal_level < WAL_LEVEL_REPLICA)
ereport(ERROR, ereport(ERROR,
(errmsg("hot standby is not possible because wal_level was not set to \"hot_standby\" or higher on the master server"), (errmsg("hot standby is not possible because wal_level was not set to \"replica\" or higher on the master server"),
errhint("Either set wal_level to \"hot_standby\" on the master, or turn off hot_standby here."))); errhint("Either set wal_level to \"replica\" on the master, or turn off hot_standby here.")));
/* We ignore autovacuum_max_workers when we make this test. */ /* We ignore autovacuum_max_workers when we make this test. */
RecoveryRequiresIntParameter("max_connections", RecoveryRequiresIntParameter("max_connections",
...@@ -9459,10 +9459,8 @@ xlog_redo(XLogReaderState *record) ...@@ -9459,10 +9459,8 @@ xlog_redo(XLogReaderState *record)
/* /*
* Update minRecoveryPoint to ensure that if recovery is aborted, we * Update minRecoveryPoint to ensure that if recovery is aborted, we
* recover back up to this point before allowing hot standby again. * recover back up to this point before allowing hot standby again.
* This is particularly important if wal_level was set to 'archive' * This is important if the max_* settings are decreased, to ensure
* before, and is now 'hot_standby', to ensure you don't run queries * you don't run queries against the WAL preceding the change.
* against the WAL preceding the wal_level change. Same applies to
* decreasing max_* settings.
*/ */
minRecoveryPoint = ControlFile->minRecoveryPoint; minRecoveryPoint = ControlFile->minRecoveryPoint;
minRecoveryPointTLI = ControlFile->minRecoveryPointTLI; minRecoveryPointTLI = ControlFile->minRecoveryPointTLI;
...@@ -9793,7 +9791,7 @@ do_pg_start_backup(const char *backupidstr, bool fast, TimeLineID *starttli_p, ...@@ -9793,7 +9791,7 @@ do_pg_start_backup(const char *backupidstr, bool fast, TimeLineID *starttli_p,
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
errmsg("WAL level not sufficient for making an online backup"), errmsg("WAL level not sufficient for making an online backup"),
errhint("wal_level must be set to \"archive\", \"hot_standby\", or \"logical\" at server start."))); errhint("wal_level must be set to \"replica\" or \"logical\" at server start.")));
if (strlen(backupidstr) > MAXPGPATH) if (strlen(backupidstr) > MAXPGPATH)
ereport(ERROR, ereport(ERROR,
...@@ -10264,7 +10262,7 @@ do_pg_stop_backup(char *labelfile, bool waitforarchive, TimeLineID *stoptli_p) ...@@ -10264,7 +10262,7 @@ do_pg_stop_backup(char *labelfile, bool waitforarchive, TimeLineID *stoptli_p)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
errmsg("WAL level not sufficient for making an online backup"), errmsg("WAL level not sufficient for making an online backup"),
errhint("wal_level must be set to \"archive\", \"hot_standby\", or \"logical\" at server start."))); errhint("wal_level must be set to \"replica\" or \"logical\" at server start.")));
/* /*
* OK to update backup counters and forcePageWrites * OK to update backup counters and forcePageWrites
......
...@@ -154,7 +154,7 @@ pg_create_restore_point(PG_FUNCTION_ARGS) ...@@ -154,7 +154,7 @@ pg_create_restore_point(PG_FUNCTION_ARGS)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
errmsg("WAL level not sufficient for creating a restore point"), errmsg("WAL level not sufficient for creating a restore point"),
errhint("wal_level must be set to \"archive\", \"hot_standby\", or \"logical\" at server start."))); errhint("wal_level must be set to \"replica\" or \"logical\" at server start.")));
restore_name_str = text_to_cstring(restore_name); restore_name_str = text_to_cstring(restore_name);
......
...@@ -858,7 +858,7 @@ PostmasterMain(int argc, char *argv[]) ...@@ -858,7 +858,7 @@ PostmasterMain(int argc, char *argv[])
(errmsg("WAL archival cannot be enabled when wal_level is \"minimal\""))); (errmsg("WAL archival cannot be enabled when wal_level is \"minimal\"")));
if (max_wal_senders > 0 && wal_level == WAL_LEVEL_MINIMAL) if (max_wal_senders > 0 && wal_level == WAL_LEVEL_MINIMAL)
ereport(ERROR, ereport(ERROR,
(errmsg("WAL streaming (max_wal_senders > 0) requires wal_level \"archive\", \"hot_standby\", or \"logical\""))); (errmsg("WAL streaming (max_wal_senders > 0) requires wal_level \"replica\" or \"logical\"")));
/* /*
* Other one-time internal sanity checks can go here, if they are fast. * Other one-time internal sanity checks can go here, if they are fast.
......
...@@ -760,7 +760,7 @@ CheckSlotRequirements(void) ...@@ -760,7 +760,7 @@ CheckSlotRequirements(void)
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
(errmsg("replication slots can only be used if max_replication_slots > 0")))); (errmsg("replication slots can only be used if max_replication_slots > 0"))));
if (wal_level < WAL_LEVEL_ARCHIVE) if (wal_level < WAL_LEVEL_REPLICA)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
errmsg("replication slots can only be used if wal_level >= archive"))); errmsg("replication slots can only be used if wal_level >= archive")));
......
...@@ -173,7 +173,7 @@ ...@@ -173,7 +173,7 @@
# - Settings - # - Settings -
#wal_level = minimal # minimal, archive, hot_standby, or logical #wal_level = minimal # minimal, replica, or logical
# (change requires restart) # (change requires restart)
#fsync = on # turns forced synchronization on or off #fsync = on # turns forced synchronization on or off
#synchronous_commit = on # synchronization level; #synchronous_commit = on # synchronization level;
......
...@@ -43,7 +43,7 @@ $node->command_fails( ...@@ -43,7 +43,7 @@ $node->command_fails(
open CONF, ">>$pgdata/postgresql.conf"; open CONF, ">>$pgdata/postgresql.conf";
print CONF "max_replication_slots = 10\n"; print CONF "max_replication_slots = 10\n";
print CONF "max_wal_senders = 10\n"; print CONF "max_wal_senders = 10\n";
print CONF "wal_level = archive\n"; print CONF "wal_level = replica\n";
close CONF; close CONF;
$node->restart; $node->restart;
......
...@@ -73,10 +73,8 @@ wal_level_str(WalLevel wal_level) ...@@ -73,10 +73,8 @@ wal_level_str(WalLevel wal_level)
{ {
case WAL_LEVEL_MINIMAL: case WAL_LEVEL_MINIMAL:
return "minimal"; return "minimal";
case WAL_LEVEL_ARCHIVE: case WAL_LEVEL_REPLICA:
return "archive"; return "replica";
case WAL_LEVEL_HOT_STANDBY:
return "hot_standby";
case WAL_LEVEL_LOGICAL: case WAL_LEVEL_LOGICAL:
return "logical"; return "logical";
} }
......
...@@ -121,25 +121,24 @@ extern int XLogArchiveMode; ...@@ -121,25 +121,24 @@ extern int XLogArchiveMode;
typedef enum WalLevel typedef enum WalLevel
{ {
WAL_LEVEL_MINIMAL = 0, WAL_LEVEL_MINIMAL = 0,
WAL_LEVEL_ARCHIVE, WAL_LEVEL_REPLICA,
WAL_LEVEL_HOT_STANDBY,
WAL_LEVEL_LOGICAL WAL_LEVEL_LOGICAL
} WalLevel; } WalLevel;
extern int wal_level; extern int wal_level;
/* Is WAL archiving enabled (always or only while server is running normally)? */ /* Is WAL archiving enabled (always or only while server is running normally)? */
#define XLogArchivingActive() \ #define XLogArchivingActive() \
(XLogArchiveMode > ARCHIVE_MODE_OFF && wal_level >= WAL_LEVEL_ARCHIVE) (AssertMacro(XLogArchiveMode == ARCHIVE_MODE_OFF || wal_level >= WAL_LEVEL_REPLICA), XLogArchiveMode > ARCHIVE_MODE_OFF)
/* Is WAL archiving enabled always (even during recovery)? */ /* Is WAL archiving enabled always (even during recovery)? */
#define XLogArchivingAlways() \ #define XLogArchivingAlways() \
(XLogArchiveMode == ARCHIVE_MODE_ALWAYS && wal_level >= WAL_LEVEL_ARCHIVE) (AssertMacro(XLogArchiveMode == ARCHIVE_MODE_OFF || wal_level >= WAL_LEVEL_REPLICA), XLogArchiveMode == ARCHIVE_MODE_ALWAYS)
#define XLogArchiveCommandSet() (XLogArchiveCommand[0] != '\0') #define XLogArchiveCommandSet() (XLogArchiveCommand[0] != '\0')
/* /*
* Is WAL-logging necessary for archival or log-shipping, or can we skip * Is WAL-logging necessary for archival or log-shipping, or can we skip
* WAL-logging if we fsync() the data before committing instead? * WAL-logging if we fsync() the data before committing instead?
*/ */
#define XLogIsNeeded() (wal_level >= WAL_LEVEL_ARCHIVE) #define XLogIsNeeded() (wal_level >= WAL_LEVEL_REPLICA)
/* /*
* Is a full-page image needed for hint bit updates? * Is a full-page image needed for hint bit updates?
...@@ -153,7 +152,7 @@ extern int wal_level; ...@@ -153,7 +152,7 @@ extern int wal_level;
#define XLogHintBitIsNeeded() (DataChecksumsEnabled() || wal_log_hints) #define XLogHintBitIsNeeded() (DataChecksumsEnabled() || wal_log_hints)
/* Do we need to WAL-log information required only for Hot Standby and logical replication? */ /* Do we need to WAL-log information required only for Hot Standby and logical replication? */
#define XLogStandbyInfoActive() (wal_level >= WAL_LEVEL_HOT_STANDBY) #define XLogStandbyInfoActive() (wal_level >= WAL_LEVEL_REPLICA)
/* Do we need to WAL-log information required only for logical replication? */ /* Do we need to WAL-log information required only for logical replication? */
#define XLogLogicalInfoActive() (wal_level >= WAL_LEVEL_LOGICAL) #define XLogLogicalInfoActive() (wal_level >= WAL_LEVEL_LOGICAL)
......
...@@ -54,7 +54,7 @@ typedef struct CheckPoint ...@@ -54,7 +54,7 @@ typedef struct CheckPoint
/* /*
* Oldest XID still running. This is only needed to initialize hot standby * Oldest XID still running. This is only needed to initialize hot standby
* mode from an online checkpoint, so we only bother calculating this for * mode from an online checkpoint, so we only bother calculating this for
* online checkpoints and only when wal_level is hot_standby. Otherwise * online checkpoints and only when wal_level is replica. Otherwise
* it's set to InvalidTransactionId. * it's set to InvalidTransactionId.
*/ */
TransactionId oldestActiveXid; TransactionId oldestActiveXid;
......
...@@ -404,7 +404,7 @@ sub init ...@@ -404,7 +404,7 @@ sub init
if ($params{allows_streaming}) if ($params{allows_streaming})
{ {
print $conf "wal_level = hot_standby\n"; print $conf "wal_level = replica\n";
print $conf "max_wal_senders = 5\n"; print $conf "max_wal_senders = 5\n";
print $conf "wal_keep_segments = 20\n"; print $conf "wal_keep_segments = 20\n";
print $conf "max_wal_size = 128MB\n"; print $conf "max_wal_size = 128MB\n";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment