From 3c4b5206850263ec0585db60bf5d17187b0dd513 Mon Sep 17 00:00:00 2001 From: Bruce Momjian Date: Thu, 15 Oct 2020 15:15:29 -0400 Subject: [PATCH] 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 --- doc/src/sgml/config.sgml | 144 ++++++++++++++++++++++++++++++-------- src/include/access/xact.h | 3 +- 2 files changed, 116 insertions(+), 31 deletions(-) diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml index c496e57877..6abccb2971 100644 --- a/doc/src/sgml/config.sgml +++ b/doc/src/sgml/config.sgml @@ -2432,14 +2432,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_apply, remote_write, local, - 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_apply, on + (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 @@ -2451,38 +2463,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 - on, remote_apply, remote_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 @@ -2492,6 +2506,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 + + + + + + + + +
+
diff --git a/src/include/access/xact.h b/src/include/access/xact.h index 8eee897337..bbefdfafd3 100644 --- a/src/include/access/xact.h +++ b/src/include/access/xact.h @@ -68,7 +68,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 */