For some reason synchronous replication does not work (everything works asynchronously)
Master settings:
wal_level = replica
fsync = on
synchronous_commit = on
max_wal_senders = 10
wal_keep_segments = 512
synchronous_standby_names = 'ANY 1 (post122, post124)'
Slave 1 settings:
wal_level = replica
fsync = on
synchronous_commit = on
max_wal_senders = 10
wal_keep_segments = 512
primary_conninfo = 'host=10.128.241.123 port=5432 user=replica application_name=app124'
primary_slot_name = 'slot124'
hot_standby = on
Slave 2 settings:
wal_level = replica
fsync = on
synchronous_commit = on
max_wal_senders = 10
wal_keep_segments = 512
primary_conninfo = 'host=10.128.241.123 port=5432 user=replica application_name=app122'
primary_slot_name = 'slot122'
hot_standby = on
If execute sql statement
SELECT pg_wal_lsn_diff(pg_current_wal_lsn(), s.sent_lsn) AS send_byte_lag, pg_wal_lsn_diff(s.sent_lsn,s.replay_lsn) AS replay_byte_lag, * FROM pg_stat_replication s;
you can see that sync_state = async for all nodes.
+-----------------+-------------------+-------+------------+--------------------+----------------------+------------------+-------------------+---------------+--------------------------------+----------------+-------------+----------------+----------------+----------------+----------------+-------------------+-------------------+--------------------+-----------------+--------------+--------------------------------+
| "SEND_BYTE_LAG" | "REPLAY_BYTE_LAG" | "PID" | "USESYSID" | "USENAME" | "APPLICATION_NAME" | "CLIENT_ADDR" | "CLIENT_HOSTNAME" | "CLIENT_PORT" | "BACKEND_START" | "BACKEND_XMIN" | "STATE" | "SENT_LSN" | "WRITE_LSN" | "FLUSH_LSN" | "REPLAY_LSN" | "WRITE_LAG" | "FLUSH_LAG" | "REPLAY_LAG" | "SYNC_PRIORITY" | "SYNC_STATE" | "REPLY_TIME" |
+-----------------+-------------------+-------+------------+--------------------+----------------------+------------------+-------------------+---------------+--------------------------------+----------------+-------------+----------------+----------------+----------------+----------------+-------------------+-------------------+--------------------+-----------------+--------------+--------------------------------+
| | | | | | | | | | | | | | | | | | | | | | |
| "0" | "0" | 14914 | 69296 | "replica" | "walreceiver" | "10.128.241.122" | NULL | 60010 | "2020-07-27 11:49:35.202751+03 | NULL | "streaming" | "BA5/D20002D0" | "BA5/D20002D0" | "BA5/D20002D0" | "BA5/D20002D0" | NULL | NULL | NULL | 0 | "async" | "2020-08-11 11:05:22.398199+03 |
| | | | | | | | | | | | | | | | | | | | | | |
| "0" | "0" | 14913 | 69296 | "replica" | "walreceiver" | "10.128.241.124" | NULL | 47916 | "2020-07-27 11:49:35.202262+03 | NULL | "streaming" | "BA5/D20002D0" | "BA5/D20002D0" | "BA5/D20002D0" | "BA5/D20002D0" | NULL | NULL | NULL | 0 | "async" | "2020-08-11 11:05:21.838096+03 |
| | | | | | | | | | | | | | | | | | | | | | |
| "0" | NULL | 14952 | 85885 | "streaming_barman" | "barman_receive_wal" | "10.128.241.223" | NULL | 53304 | "2020-07-27 11:50:01.795733+03 | NULL | "streaming" | "BA5/D20002D0" | "BA5/D20002D0" | "BA5/D2000000" | NULL | "00:00:07.658259" | "65:31:39.378476" | "359:15:13.971633" | 0 | "async" | "2020-08-11 11:05:15.781336+03 |
+-----------------+-------------------+-------+------------+--------------------+----------------------+------------------+-------------------+---------------+--------------------------------+----------------+-------------+----------------+----------------+----------------+----------------+-------------------+-------------------+--------------------+-----------------+--------------+--------------------------------+
And such a moment is also suspicious, in the slave settings application_name = app124
is specified and in select application_name = walreceiver
as if application_name is not recognized.
What can be done to make synchronous replication work?
synchronous_commit = remote_apply
in the configuration of the primary postgresql.org/docs/current/…remote_apply
orremote_write
as described in the link from my comment and description in the chapter Synchronous Replicationsynchronous_commit = on
is enough for synchronous replication.