mirror of
https://github.com/postgres/postgres.git
synced 2025-07-31 22:04:40 +03:00
Introduce wal_level GUC to explicitly control if information needed for
archival or hot standby should be WAL-logged, instead of deducing that from other options like archive_mode. This replaces recovery_connections GUC in the primary, where it now has no effect, but it's still used in the standby to enable/disable hot standby. Remove the WAL-logging of "unlogged operations", like creating an index without WAL-logging and fsyncing it at the end. Instead, we keep a copy of the wal_mode setting and the settings that affect how much shared memory a hot standby server needs to track master transactions (max_connections, max_prepared_xacts, max_locks_per_xact) in pg_control. Whenever the settings change, at server restart, write a WAL record noting the new settings and update pg_control. This allows us to notice the change in those settings in the standby at the right moment, they used to be included in checkpoint records, but that meant that a changed value was not reflected in the standby until the first checkpoint after the change. Bump PG_CONTROL_VERSION and XLOG_PAGE_MAGIC. Whack XLOG_PAGE_MAGIC back to the sequence it used to follow, before hot standby and subsequent patches changed it to 0x9003.
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
<!-- $PostgreSQL: pgsql/doc/src/sgml/backup.sgml,v 2.152 2010/04/20 00:26:06 rhaas Exp $ -->
|
||||
<!-- $PostgreSQL: pgsql/doc/src/sgml/backup.sgml,v 2.153 2010/04/28 16:10:39 heikki Exp $ -->
|
||||
|
||||
<chapter id="backup">
|
||||
<title>Backup and Restore</title>
|
||||
@ -689,8 +689,7 @@ archive_command = 'test ! -f /mnt/server/archivedir/%f && cp %p /mnt/ser
|
||||
</para>
|
||||
|
||||
<para>
|
||||
When <varname>archive_mode</> is <literal>off</> and <xref
|
||||
linkend="guc-max-wal-senders"> is zero some SQL commands
|
||||
When <varname>wal_level</> is <literal>minimal</> some SQL commands
|
||||
are optimized to avoid WAL logging, as described in <xref
|
||||
linkend="populate-pitr">. If archiving or streaming replication were
|
||||
turned on during execution of one of these statements, WAL would not
|
||||
|
@ -1,4 +1,4 @@
|
||||
<!-- $PostgreSQL: pgsql/doc/src/sgml/config.sgml,v 1.270 2010/04/26 10:51:59 rhaas Exp $ -->
|
||||
<!-- $PostgreSQL: pgsql/doc/src/sgml/config.sgml,v 1.271 2010/04/28 16:10:39 heikki Exp $ -->
|
||||
|
||||
<chapter Id="runtime-config">
|
||||
<title>Server Configuration</title>
|
||||
@ -1353,6 +1353,45 @@ SET ENABLE_SEQSCAN TO OFF;
|
||||
<title>Settings</title>
|
||||
<variablelist>
|
||||
|
||||
<varlistentry id="guc-wal-level" xreflabel="wal_level">
|
||||
<term><varname>wal_level</varname> (<type>enum</type>)</term>
|
||||
<indexterm>
|
||||
<primary><varname>wal_level</> configuration parameter</primary>
|
||||
</indexterm>
|
||||
<listitem>
|
||||
<para>
|
||||
<varname>wal_level</> determines how much information is written
|
||||
to the WAL. The default value is <literal>minimal</>, which writes
|
||||
only minimal information needed to recover from a crash or immediate
|
||||
shutdown. <literal>archive</> adds logging required for WAL archiving,
|
||||
and <literal>hot_standby</> further adds information required to run
|
||||
read-only queries on a standby server.
|
||||
This parameter can only be set at server start.
|
||||
</para>
|
||||
<para>
|
||||
In <literal>minimal</> level, WAL-logging of some bulk operations, like
|
||||
<command>CREATE INDEX</>, <command>CLUSTER</> and <command>COPY</> on
|
||||
a table that was created or truncated in the same transaction can be
|
||||
safely skipped, which can make those operations much faster (see
|
||||
<xref linkend="populate-pitr">). But minimal WAL does not contain
|
||||
enough information to reconstruct the data from a base backup and the
|
||||
WAL logs, so at least <literal>archive</> level must be used to enable
|
||||
WAL archiving (<xref linkend="guc-archive-mode">) and streaming
|
||||
replication.
|
||||
</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</> on the primary. It is thought that there is
|
||||
little measurable difference in performance from using
|
||||
<literal>hot_standby</> level over <literal>archive</>, so feedback
|
||||
is welcome if any production impacts are noticeable.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry id="guc-fsync" xreflabel="fsync">
|
||||
<indexterm>
|
||||
<primary><varname>fsync</> configuration parameter</primary>
|
||||
@ -1726,7 +1765,9 @@ SET ENABLE_SEQSCAN TO OFF;
|
||||
<varname>archive_mode</> and <varname>archive_command</> are
|
||||
separate variables so that <varname>archive_command</> can be
|
||||
changed without leaving archiving mode.
|
||||
This parameter can only be set at server start.
|
||||
This parameter can only be set at server start. <varname>wal_level</>
|
||||
must be set to <literal>archive</> or <literal>hot_standby</> to
|
||||
enable <varname>archive_mode</>.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
@ -1818,7 +1859,9 @@ SET ENABLE_SEQSCAN TO OFF;
|
||||
Specifies the maximum number of concurrent connections from standby
|
||||
servers (i.e., the maximum number of simultaneously running WAL sender
|
||||
processes). The default is zero. This parameter can only be set at
|
||||
server start.
|
||||
server start. <varname>wal_level</> must be set to <literal>archive</>
|
||||
or <literal>hot_standby</> to allow connections from standby
|
||||
connections.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
@ -1884,16 +1927,11 @@ SET ENABLE_SEQSCAN TO OFF;
|
||||
</indexterm>
|
||||
<listitem>
|
||||
<para>
|
||||
Parameter has two roles. During recovery, specifies whether or not
|
||||
you can connect and run queries to enable <xref linkend="hot-standby">.
|
||||
During normal running, specifies whether additional information is written
|
||||
to WAL to allow recovery connections on a standby server that reads
|
||||
WAL data generated by this server. The default value is
|
||||
<literal>on</literal>. It is thought that there is little
|
||||
measurable difference in performance from using this feature, so
|
||||
feedback is welcome if any production impacts are noticeable.
|
||||
It is likely that this parameter will be removed in later releases.
|
||||
This parameter can only be set at server start.
|
||||
Specifies whether or not you can connect and run queries during
|
||||
recovery, for <xref linkend="hot-standby">. The default value is
|
||||
<literal>on</literal>.
|
||||
This parameter can only be set at server start. It only has effect
|
||||
during archive recovery or in standby mode.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
@ -1,4 +1,4 @@
|
||||
<!-- $PostgreSQL: pgsql/doc/src/sgml/high-availability.sgml,v 1.63 2010/04/26 19:09:25 momjian Exp $ -->
|
||||
<!-- $PostgreSQL: pgsql/doc/src/sgml/high-availability.sgml,v 1.64 2010/04/28 16:10:40 heikki Exp $ -->
|
||||
|
||||
<chapter id="high-availability">
|
||||
<title>High Availability, Load Balancing, and Replication</title>
|
||||
@ -1593,9 +1593,9 @@ LOG: database system is ready to accept read only connections
|
||||
</programlisting>
|
||||
|
||||
Consistency information is recorded once per checkpoint on the primary, as long
|
||||
as <varname>recovery_connections</> is enabled on the primary. It is not possible
|
||||
as <varname>wal_level</> is set to <literal>hot_standby</> on the primary. It is not possible
|
||||
to enable recovery connections on the standby when reading WAL written during the
|
||||
period that <varname>recovery_connections</> was disabled on the primary.
|
||||
period that <varname>wal_level</> was not set to <literal>hot_standby</> on the primary.
|
||||
Reaching a consistent state can also be delayed in the presence
|
||||
of both of these conditions:
|
||||
|
||||
@ -1842,7 +1842,7 @@ LOG: database system is ready to accept read only connections
|
||||
</para>
|
||||
|
||||
<para>
|
||||
On the primary, parameters <varname>recovery_connections</> and
|
||||
On the primary, parameters <varname>wal_level</> and
|
||||
<varname>vacuum_defer_cleanup_age</> can be used.
|
||||
<varname>max_standby_delay</> has no effect if set on the primary.
|
||||
</para>
|
||||
|
@ -1,4 +1,4 @@
|
||||
<!-- $PostgreSQL: pgsql/doc/src/sgml/perform.sgml,v 1.76 2010/04/20 00:26:06 rhaas Exp $ -->
|
||||
<!-- $PostgreSQL: pgsql/doc/src/sgml/perform.sgml,v 1.77 2010/04/28 16:10:40 heikki Exp $ -->
|
||||
|
||||
<chapter id="performance-tips">
|
||||
<title>Performance Tips</title>
|
||||
@ -835,10 +835,9 @@ SELECT * FROM x, y, a, b, c WHERE something AND somethingelse;
|
||||
<command>TRUNCATE</command> command. In such cases no WAL
|
||||
needs to be written, because in case of an error, the files
|
||||
containing the newly loaded data will be removed anyway.
|
||||
However, this consideration does not apply when
|
||||
<xref linkend="guc-archive-mode"> is on or streaming replication
|
||||
is allowed (i.e., <xref linkend="guc-max-wal-senders"> is more
|
||||
than or equal to one), as all commands must write WAL in that case.
|
||||
However, this consideration only applies when
|
||||
<xref linkend="guc-wal-level"> is <literal>minimal</> as all commands
|
||||
must write WAL otherwise.
|
||||
</para>
|
||||
|
||||
</sect2>
|
||||
@ -910,29 +909,27 @@ SELECT * FROM x, y, a, b, c WHERE something AND somethingelse;
|
||||
</sect2>
|
||||
|
||||
<sect2 id="populate-pitr">
|
||||
<title>Turn off <varname>archive_mode</varname> and streaming replication</title>
|
||||
<title>Disable WAL archival and streaming replication</title>
|
||||
|
||||
<para>
|
||||
When loading large amounts of data into an installation that uses
|
||||
WAL archiving or streaming replication, you might want to disable
|
||||
archiving (turn off the <xref linkend="guc-archive-mode">
|
||||
configuration variable) and replication (zero the
|
||||
<xref linkend="guc-max-wal-senders"> configuration variable)
|
||||
while loading. It might be
|
||||
faster to take a new base backup after the load has completed
|
||||
than to process a large amount of incremental WAL data.
|
||||
But note that changing either of these variables requires
|
||||
a server restart.
|
||||
WAL archiving or streaming replication, it might be faster to take a
|
||||
new base backup after the load has completed than to process a large
|
||||
amount of incremental WAL data. You might want to disable archiving
|
||||
and streaming replication while loading, by setting
|
||||
<xref linkend="guc-wal-level"> to <literal>minimal</>,
|
||||
<xref linkend="guc-archive-mode"> <literal>off</>, and
|
||||
<xref linkend="guc-max-wal-senders"> to zero).
|
||||
But note that changing these settings requires a server restart.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Aside from avoiding the time for the archiver or WAL sender to
|
||||
process the WAL data,
|
||||
doing this will actually make certain commands faster, because they
|
||||
are designed not to write WAL at all if <varname>archive_mode</varname>
|
||||
is off and <varname>max_wal_senders</varname> is zero. (They can
|
||||
guarantee crash safety more cheaply by doing an
|
||||
<function>fsync</> at the end than by writing WAL.)
|
||||
are designed not to write WAL at all if <varname>wal_level</varname>
|
||||
is <literal>minimal</>. (They can guarantee crash safety more cheaply
|
||||
by doing an <function>fsync</> at the end than by writing WAL.)
|
||||
This applies to the following commands:
|
||||
<itemizedlist>
|
||||
<listitem>
|
||||
@ -1014,10 +1011,12 @@ SELECT * FROM x, y, a, b, c WHERE something AND somethingelse;
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>
|
||||
If using WAL archiving, consider disabling it during the restore.
|
||||
To do that, turn off <varname>archive_mode</varname> before loading the
|
||||
dump script, and afterwards turn it back on
|
||||
and take a fresh base backup.
|
||||
If using WAL archiving or streaming replication, consider disabling
|
||||
them during the restore. To do that, set <varname>arcive_mode</> off,
|
||||
<varname>wal_level</varname> to <literal>minimal</>, and
|
||||
<varname>max_wal_senders</> zero before loading the dump script,
|
||||
and afterwards set them back to the right values and take a fresh
|
||||
base backup.
|
||||
</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
|
Reference in New Issue
Block a user