Skip to content

Commit e55704d

Browse files
committed
Add new wal_level, logical, sufficient for logical decoding.
When wal_level=logical, we'll log columns from the old tuple as configured by the REPLICA IDENTITY facility added in commit 07cacba. This makes it possible a properly-configured logical replication solution to correctly follow table updates even if they change the chosen key columns, or, with REPLICA IDENTITY FULL, even if the table has no key at all. Note that updates which do not modify the replica identity column won't log anything extra, making the choice of a good key (i.e. one that will rarely be changed) important to performance when wal_level=logical is configured. Each insert, update, or delete to a catalog table will also log the CMIN and/or CMAX values of stamped by the current transaction. This is necessary because logical decoding will require access to historical snapshots of the catalog in order to decode some data types, and the CMIN/CMAX values that we may need in order to judge row visibility may have been overwritten by the time we need them. Andres Freund, reviewed in various versions by myself, Heikki Linnakangas, KONDO Mitsumasa, and many others.
1 parent 9ec6199 commit e55704d

File tree

22 files changed

+745
-157
lines changed

22 files changed

+745
-157
lines changed

doc/src/sgml/backup.sgml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ tar -cf backup.tar /usr/local/pgsql/data
587587

588588
<para>
589589
To enable WAL archiving, set the <xref linkend="guc-wal-level">
590-
configuration parameter to <literal>archive</> (or <literal>hot_standby</>),
590+
configuration parameter to <literal>archive</> or higher,
591591
<xref linkend="guc-archive-mode"> to <literal>on</>,
592592
and specify the shell command to use in the <xref
593593
linkend="guc-archive-command"> configuration parameter. In practice
@@ -1259,7 +1259,7 @@ restore_command = 'cp /mnt/server/archivedir/%f %p'
12591259
If more flexibility in copying the backup files is needed, a lower
12601260
level process can be used for standalone hot backups as well.
12611261
To prepare for low level standalone hot backups, set <varname>wal_level</> to
1262-
<literal>archive</> (or <literal>hot_standby</>), <varname>archive_mode</> to
1262+
<literal>archive</> or higher, <varname>archive_mode</> to
12631263
<literal>on</>, and set up an <varname>archive_command</> that performs
12641264
archiving only when a <emphasis>switch file</> exists. For example:
12651265
<programlisting>

doc/src/sgml/config.sgml

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1648,10 +1648,12 @@ include 'filename'
16481648
<varname>wal_level</> determines how much information is written
16491649
to the WAL. The default value is <literal>minimal</>, which writes
16501650
only the information needed to recover from a crash or immediate
1651-
shutdown. <literal>archive</> adds logging required for WAL archiving,
1652-
and <literal>hot_standby</> further adds information required to run
1653-
read-only queries on a standby server.
1654-
This parameter can only be set at server start.
1651+
shutdown. <literal>archive</> adds logging required for WAL archiving;
1652+
<literal>hot_standby</> further adds information required to run
1653+
read-only queries on a standby server; and, finally
1654+
<literal>logical</> adds information necessary to support logical
1655+
decoding. Each level includes the information logged at all lower
1656+
levels. This parameter can only be set at server start.
16551657
</para>
16561658
<para>
16571659
In <literal>minimal</> level, WAL-logging of some bulk
@@ -1665,24 +1667,30 @@ include 'filename'
16651667
<member><command>COPY</> into tables that were created or truncated in the same
16661668
transaction</member>
16671669
</simplelist>
1668-
But minimal WAL does not contain
1669-
enough information to reconstruct the data from a base backup and the
1670-
WAL logs, so either <literal>archive</> or <literal>hot_standby</>
1671-
level must be used to enable
1672-
WAL archiving (<xref linkend="guc-archive-mode">) and streaming
1673-
replication.
1670+
But minimal WAL does not contain enough information to reconstruct the
1671+
data from a base backup and the WAL logs, so <literal>archive</> or
1672+
higher must be used to enable WAL archiving
1673+
(<xref linkend="guc-archive-mode">) and streaming replication.
16741674
</para>
16751675
<para>
16761676
In <literal>hot_standby</> level, the same information is logged as
16771677
with <literal>archive</>, plus information needed to reconstruct
16781678
the status of running transactions from the WAL. To enable read-only
16791679
queries on a standby server, <varname>wal_level</> must be set to
1680-
<literal>hot_standby</> on the primary, and
1680+
<literal>hot_standby</> or higher on the primary, and
16811681
<xref linkend="guc-hot-standby"> must be enabled in the standby. It is
1682-
thought that there is
1683-
little measurable difference in performance between using
1684-
<literal>hot_standby</> and <literal>archive</> levels, so feedback
1685-
is welcome if any production impacts are noticeable.
1682+
thought that there is little measurable difference in performance
1683+
between using <literal>hot_standby</> and <literal>archive</> levels,
1684+
so feedback is welcome if any production impacts are noticeable.
1685+
</para>
1686+
<para>
1687+
In <literal>logical</> level, the same information is logged as
1688+
with <literal>hot_standby</>, plus information needed to allow
1689+
extracting logical changesets from the WAL. Using a level of
1690+
<literal>logical</> will increase the WAL volume, particularly if many
1691+
tables are configured for <literal>REPLICA IDENTITY FULL</literal> and
1692+
many <command>UPDATE</> and <command>DELETE</> statements are
1693+
executed.
16861694
</para>
16871695
</listitem>
16881696
</varlistentry>
@@ -2239,9 +2247,9 @@ include 'filename'
22392247
disabled. WAL sender processes count towards the total number
22402248
of connections, so the parameter cannot be set higher than
22412249
<xref linkend="guc-max-connections">. This parameter can only
2242-
be set at server start. <varname>wal_level</> must be set
2243-
to <literal>archive</> or <literal>hot_standby</> to allow
2244-
connections from standby servers.
2250+
be set at server start. <varname>wal_level</> must be set to
2251+
<literal>archive</> or higher to allow connections from standby
2252+
servers.
22452253
</para>
22462254
</listitem>
22472255
</varlistentry>

doc/src/sgml/high-availability.sgml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1861,8 +1861,9 @@ LOG: database system is ready to accept read only connections
18611861
Consistency information is recorded once per checkpoint on the primary.
18621862
It is not possible to enable hot standby when reading WAL
18631863
written during a period when <varname>wal_level</> was not set to
1864-
<literal>hot_standby</> on the primary. Reaching a consistent state can
1865-
also be delayed in the presence of both of these conditions:
1864+
<literal>hot_standby</> or <literal>logical</> on the primary. Reaching
1865+
a consistent state can also be delayed in the presence of both of these
1866+
conditions:
18661867

18671868
<itemizedlist>
18681869
<listitem>

0 commit comments

Comments
 (0)