Excerpt from: https://yq.aliyun.com/articles/61274
Synchronous multi-Copy configuration method
The parameters are configured as follows
Synchronous_standby_names (String)
supports two types of writing
num_sync ( standby_name [, ...] ) standby_name [, ...]
A num_sync number that represents the number of copies synchronized.
A format that does not write Num_sync is compatible with the previous configuration, representing 1 copies.
Standby_name is a application_name configured in recovery.conf in standby and can be used instead of all standby.
Example
2 (s1, s2, s3, s4)
Indicates that 2 replicas are synchronous standby, and others are asynchronous standby.
When the thing commits, make sure that the Xlog is synchronized to any 2 copies (the first two are the synchronization nodes, the next 2 are the substitutes, and when any of the preceding two nodes are faulty, the latter will be replaced in turn).
The synchronization level of a transaction is configured through the parameter Synchronous_commit (enum).
If you want to configure a transaction or session-level parameter, use the following syntax
SET [ SESSION | LOCAL ] configuration_parameter { TO | = } { value | ‘value‘ | DEFAULT }
In other words, users can set different synchronization levels for different transactions based on the actual business needs.
The current supported synchronization levels are as follows
事务提交或回滚时,会产生一笔事务结束的commit/rollback redo record,在REDO的地址系统中,用LSN表示。 on, 事务commit或rollback时,等待其redo在primary、以及同步standby(s)已持久化(>=其lsn)。 remote_apply, 事务commit或rollback时,等待其redo在primary、以及同步standby(s)已持久化(>=其lsn)。 并且其redo在同步standby(s)已apply(>=其lsn)。 remote_write, 事务commit或rollback时,等待其redo在primary已持久化; 其redo在同步standby(s)已调用write接口(写到OS, 但是还没有调用持久化接口如fsync)(>=其lsn)。 local, 事务commit或rollback时,等待其redo在primary已持久化;off 事务commit或rollback时,等待其redo在primary已写入wal buffer,不需要等待其持久化;
Manual description
1. Reliability
Combined with the Synchronous_standby_names and synchronous_commit settings, you can achieve very flexible transaction-level reliability requirements.
2. Read-and-write separation of reading consistency guarantee
When Synchronous_commit=remote_apply, the redo of this transaction must be put on sync standby (s) before returning to the end of the client transaction.
This type of transaction, the read request initiated after the transaction ends, is fully consistent with the primary and sync standby.
At the expense of the RT of the write transaction, get the full consistency of the read transaction at the multi-borrowing point.
3. Switching delay
When the synchronous_commit=remote_apply transactional replication level is set, the switching delay can be reduced.
The standby library is activated without the need for apply redo and can be quickly activated to become the main library
PostgreSQL 9.6 Synchronous Multi-copy, remote_apply record