doc: improve description of synchronous_commit modes
authorBruce Momjian
Thu, 15 Oct 2020 19:15:29 +0000 (15:15 -0400)
committerBruce Momjian
Thu, 15 Oct 2020 19:15:29 +0000 (15:15 -0400)
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: [email protected]
Discussion: https://postgr.es/m/159741195522.14321.13812604195366728976@wrigleys.postgresql.org

Backpatch-through: 9.6

doc/src/sgml/config.sgml
src/include/access/xact.h

index ee914740cc4be3793bb4a9ec672b50d898bcd3b0..2768c85a96fb20ef81816a8488a5652e5933c513 100644 (file)
@@ -2703,14 +2703,26 @@ include_dir 'conf.d'
       
       
        
-        Specifies whether transaction commit will wait for WAL records
-        to be written to disk before the command returns a success
-        indication to the client.  Valid values are on,
-        remote_applyremote_writelocal,
-        and off.  The default, and safe, setting
-        is on.  When off, there can be a delay between
-        when success is reported to the client and when the transaction is
-        really guaranteed to be safe against a server crash.  (The maximum
+        Specifies how much WAL processing must complete before
+        the database server returns a success
+        indication to the client.  Valid values are
+        remote_applyon
+        (the default), remote_write,
+        local, and off.
+       
+
+       
+        If synchronous_standby_names is empty,
+        the only meaningful settings are on and
+        off;  remote_apply,
+        remote_write and local
+        all provide the same local synchronization level
+        as on.  The local behavior of all
+        non-off modes is to wait for local flush of WAL
+        to disk.  In off mode, there is no waiting,
+        so there can be a delay between when success is reported to the
+        client and when the transaction is later guaranteed to be safe
+        against a server crash.  (The maximum
         delay is three times .)  Unlike
         , setting this parameter to off
         does not create any risk of database inconsistency: an operating
@@ -2722,38 +2734,40 @@ include_dir 'conf.d'
         exact certainty about the durability of a transaction.  For more
         discussion see .
        
+
        
-        If  is non-empty, this
-        parameter also controls whether or not transaction commits will wait
-        for their WAL records to be replicated to the standby server(s).
-        When set to on, commits will wait until replies
+        If  is non-empty,
+        synchronous_commit also controls whether
+        transaction commits will wait for their WAL records to be
+        processed on the standby server(s).
+       
+
+       
+        When set to remote_apply, commits will wait
+        until replies from the current synchronous standby(s) indicate they
+        have received the commit record of the transaction and applied
+        it, so that it has become visible to queries on the standby(s),
+        and also written to durable storage on the standbys.  This will
+        cause much larger commit delays than previous settings since
+        it waits for WAL replay.  When set to on,
+        commits wait until replies
         from the current synchronous standby(s) indicate they have received
-        the commit record of the transaction and flushed it to disk.  This
+        the commit record of the transaction and flushed it to durable storage.  This
         ensures the transaction will not be lost unless both the primary and
         all synchronous standbys suffer corruption of their database storage.
-        When set to remote_apply, commits will wait until replies
-        from the current synchronous standby(s) indicate they have received the
-        commit record of the transaction and applied it, so that it has become
-        visible to queries on the standby(s).
         When set to remote_write, commits will wait until replies
         from the current synchronous standby(s) indicate they have
-        received the commit record of the transaction and written it out to
-        their operating system. This setting is sufficient to
-        ensure data preservation even if a standby instance of
-        PostgreSQL were to crash, but not if the standby
-        suffers an operating-system-level crash, since the data has not
+        received the commit record of the transaction and written it to
+        their file systems. This setting ensures data preservation if a standby instance of
+        PostgreSQL crashes, but not if the standby
+        suffers an operating-system-level crash because the data has not
         necessarily reached durable storage on the standby.
-        Finally, the setting local causes commits to wait for
-        local flush to disk, but not for replication.  This is not usually
+        The setting local causes commits to wait for
+        local flush to disk, but not for replication.  This is usually not
         desirable when synchronous replication is in use, but is provided for
         completeness.
        
-       
-        If synchronous_standby_names is empty, the settings
-        onremote_applyremote_write
-        and local all provide the same synchronization level:
-        transaction commits only wait for local flush to disk.
-       
+
        
         This parameter can be changed at any time; the behavior for any
         one transaction is determined by the setting in effect when it
@@ -2763,6 +2777,76 @@ include_dir 'conf.d'
         asynchronously when the default is the opposite, issue SET
         LOCAL synchronous_commit TO OFF within the transaction.
        
+
+       
+         summarizes the
+        capabilities of the synchronous_commit settings.
+       
+
+       
+        synchronous_commit Modes
+        
+         
+         
+         
+         
+         
+         
+          
+           synchronous_commit setting
+           local durable commit
+           standby durable commit after PG crash
+           standby durable commit after OS crash
+           standby query consistency
+          
+         
+
+         
+
+          
+           remote_apply
+           
+           
+           
+           
+          
+
+          
+           on
+           
+           
+           
+           
+          
+
+          
+           remote_write
+           
+           
+           
+           
+          
+
+          
+           local
+           
+           
+           
+           
+          
+
+          
+           off
+           
+           
+           
+           
+          
+
+         
+        
+       
+
       
      
 
index df1b43a932e3d119420e41bafe26b8cd619da026..7320de345c9959deef2c0cd903e4d5b378aa5882 100644 (file)
@@ -72,7 +72,8 @@ typedef enum
    SYNCHRONOUS_COMMIT_REMOTE_WRITE,    /* wait for local flush and remote
                                         * write */
    SYNCHRONOUS_COMMIT_REMOTE_FLUSH,    /* wait for local and remote flush */
-   SYNCHRONOUS_COMMIT_REMOTE_APPLY /* wait for local flush and remote apply */
+   SYNCHRONOUS_COMMIT_REMOTE_APPLY /* wait for local and remote flush
+                                      and remote apply */
 }          SyncCommitLevel;
 
 /* Define the default setting for synchronous_commit */