Skip to content

Commit 264e517

Browse files
committed
doc: improve description of synchronous_commit modes
Previously it wasn't clear exactly what each of the synchronous_commit modes accomplished. This clarifies that, and adds a table describing it. Only backpatched through 9.6 since 9.5 doesn't have all the options. Reported-by: kghost0@gmail.com Discussion: https://postgr.es/m/159741195522.14321.13812604195366728976@wrigleys.postgresql.org Backpatch-through: 9.6
1 parent 9f783ae commit 264e517

File tree

2 files changed

+116
-31
lines changed

2 files changed

+116
-31
lines changed

doc/src/sgml/config.sgml

Lines changed: 114 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2650,14 +2650,26 @@ include_dir 'conf.d'
26502650
</term>
26512651
<listitem>
26522652
<para>
2653-
Specifies whether transaction commit will wait for WAL records
2654-
to be written to disk before the command returns a <quote>success</quote>
2655-
indication to the client. Valid values are <literal>on</literal>,
2656-
<literal>remote_apply</literal>, <literal>remote_write</literal>, <literal>local</literal>,
2657-
and <literal>off</literal>. The default, and safe, setting
2658-
is <literal>on</literal>. When <literal>off</literal>, there can be a delay between
2659-
when success is reported to the client and when the transaction is
2660-
really guaranteed to be safe against a server crash. (The maximum
2653+
Specifies how much WAL processing must complete before
2654+
the database server returns a <quote>success</quote>
2655+
indication to the client. Valid values are
2656+
<literal>remote_apply</literal>, <literal>on</literal>
2657+
(the default), <literal>remote_write</literal>,
2658+
<literal>local</literal>, and <literal>off</literal>.
2659+
</para>
2660+
2661+
<para>
2662+
If <varname>synchronous_standby_names</varname> is empty,
2663+
the only meaningful settings are <literal>on</literal> and
2664+
<literal>off</literal>; <literal>remote_apply</literal>,
2665+
<literal>remote_write</literal> and <literal>local</literal>
2666+
all provide the same local synchronization level
2667+
as <literal>on</literal>. The local behavior of all
2668+
non-<literal>off</literal> modes is to wait for local flush of WAL
2669+
to disk. In <literal>off</literal> mode, there is no waiting,
2670+
so there can be a delay between when success is reported to the
2671+
client and when the transaction is later guaranteed to be safe
2672+
against a server crash. (The maximum
26612673
delay is three times <xref linkend="guc-wal-writer-delay"/>.) Unlike
26622674
<xref linkend="guc-fsync"/>, setting this parameter to <literal>off</literal>
26632675
does not create any risk of database inconsistency: an operating
@@ -2669,38 +2681,40 @@ include_dir 'conf.d'
26692681
exact certainty about the durability of a transaction. For more
26702682
discussion see <xref linkend="wal-async-commit"/>.
26712683
</para>
2684+
26722685
<para>
2673-
If <xref linkend="guc-synchronous-standby-names"/> is non-empty, this
2674-
parameter also controls whether or not transaction commits will wait
2675-
for their WAL records to be replicated to the standby server(s).
2676-
When set to <literal>on</literal>, commits will wait until replies
2686+
If <xref linkend="guc-synchronous-standby-names"/> is non-empty,
2687+
<varname>synchronous_commit</varname> also controls whether
2688+
transaction commits will wait for their WAL records to be
2689+
processed on the standby server(s).
2690+
</para>
2691+
2692+
<para>
2693+
When set to <literal>remote_apply</literal>, commits will wait
2694+
until replies from the current synchronous standby(s) indicate they
2695+
have received the commit record of the transaction and applied
2696+
it, so that it has become visible to queries on the standby(s),
2697+
and also written to durable storage on the standbys. This will
2698+
cause much larger commit delays than previous settings since
2699+
it waits for WAL replay. When set to <literal>on</literal>,
2700+
commits wait until replies
26772701
from the current synchronous standby(s) indicate they have received
2678-
the commit record of the transaction and flushed it to disk. This
2702+
the commit record of the transaction and flushed it to durable storage. This
26792703
ensures the transaction will not be lost unless both the primary and
26802704
all synchronous standbys suffer corruption of their database storage.
2681-
When set to <literal>remote_apply</literal>, commits will wait until replies
2682-
from the current synchronous standby(s) indicate they have received the
2683-
commit record of the transaction and applied it, so that it has become
2684-
visible to queries on the standby(s).
26852705
When set to <literal>remote_write</literal>, commits will wait until replies
26862706
from the current synchronous standby(s) indicate they have
2687-
received the commit record of the transaction and written it out to
2688-
their operating system. This setting is sufficient to
2689-
ensure data preservation even if a standby instance of
2690-
<productname>PostgreSQL</productname> were to crash, but not if the standby
2691-
suffers an operating-system-level crash, since the data has not
2707+
received the commit record of the transaction and written it to
2708+
their file systems. This setting ensures data preservation if a standby instance of
2709+
<productname>PostgreSQL</productname> crashes, but not if the standby
2710+
suffers an operating-system-level crash because the data has not
26922711
necessarily reached durable storage on the standby.
2693-
Finally, the setting <literal>local</literal> causes commits to wait for
2694-
local flush to disk, but not for replication. This is not usually
2712+
The setting <literal>local</literal> causes commits to wait for
2713+
local flush to disk, but not for replication. This is usually not
26952714
desirable when synchronous replication is in use, but is provided for
26962715
completeness.
26972716
</para>
2698-
<para>
2699-
If <varname>synchronous_standby_names</varname> is empty, the settings
2700-
<literal>on</literal>, <literal>remote_apply</literal>, <literal>remote_write</literal>
2701-
and <literal>local</literal> all provide the same synchronization level:
2702-
transaction commits only wait for local flush to disk.
2703-
</para>
2717+
27042718
<para>
27052719
This parameter can be changed at any time; the behavior for any
27062720
one transaction is determined by the setting in effect when it
@@ -2710,6 +2724,76 @@ include_dir 'conf.d'
27102724
asynchronously when the default is the opposite, issue <command>SET
27112725
LOCAL synchronous_commit TO OFF</command> within the transaction.
27122726
</para>
2727+
2728+
<para>
2729+
<xref linkend="synchronous-commit-matrix"/> summarizes the
2730+
capabilities of the <varname>synchronous_commit</varname> settings.
2731+
</para>
2732+
2733+
<table id="synchronous-commit-matrix">
2734+
<title>synchronous_commit Modes</title>
2735+
<tgroup cols="5">
2736+
<colspec colname="col1" colwidth="1.1*"/>
2737+
<colspec colname="col2" colwidth="1*"/>
2738+
<colspec colname="col3" colwidth="1*"/>
2739+
<colspec colname="col4" colwidth="1*"/>
2740+
<colspec colname="col5" colwidth="1*"/>
2741+
<thead>
2742+
<row>
2743+
<entry>synchronous_commit setting</entry>
2744+
<entry>local durable commit</entry>
2745+
<entry>standby durable commit after PG crash</entry>
2746+
<entry>standby durable commit after OS crash</entry>
2747+
<entry>standby query consistency</entry>
2748+
</row>
2749+
</thead>
2750+
2751+
<tbody>
2752+
2753+
<row>
2754+
<entry>remote_apply</entry>
2755+
<entry align="center">&bull;</entry>
2756+
<entry align="center">&bull;</entry>
2757+
<entry align="center">&bull;</entry>
2758+
<entry align="center">&bull;</entry>
2759+
</row>
2760+
2761+
<row>
2762+
<entry>on</entry>
2763+
<entry align="center">&bull;</entry>
2764+
<entry align="center">&bull;</entry>
2765+
<entry align="center">&bull;</entry>
2766+
<entry align="center"></entry>
2767+
</row>
2768+
2769+
<row>
2770+
<entry>remote_write</entry>
2771+
<entry align="center">&bull;</entry>
2772+
<entry align="center">&bull;</entry>
2773+
<entry align="center"></entry>
2774+
<entry align="center"></entry>
2775+
</row>
2776+
2777+
<row>
2778+
<entry>local</entry>
2779+
<entry align="center">&bull;</entry>
2780+
<entry align="center"></entry>
2781+
<entry align="center"></entry>
2782+
<entry align="center"></entry>
2783+
</row>
2784+
2785+
<row>
2786+
<entry>off</entry>
2787+
<entry align="center"></entry>
2788+
<entry align="center"></entry>
2789+
<entry align="center"></entry>
2790+
<entry align="center"></entry>
2791+
</row>
2792+
2793+
</tbody>
2794+
</tgroup>
2795+
</table>
2796+
27132797
</listitem>
27142798
</varlistentry>
27152799

src/include/access/xact.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ typedef enum
7272
SYNCHRONOUS_COMMIT_REMOTE_WRITE, /* wait for local flush and remote
7373
* write */
7474
SYNCHRONOUS_COMMIT_REMOTE_FLUSH, /* wait for local and remote flush */
75-
SYNCHRONOUS_COMMIT_REMOTE_APPLY /* wait for local flush and remote apply */
75+
SYNCHRONOUS_COMMIT_REMOTE_APPLY /* wait for local and remote flush
76+
and remote apply */
7677
} SyncCommitLevel;
7778

7879
/* Define the default setting for synchronous_commit */

0 commit comments

Comments
 (0)