4
Hot Standby for High
Availability
synchronous replication: the replica stays as closely aligned with the leader as
possible
queries to replica are possible, but not a priority:
they will be terminated in case of any conflict
primary
(leader)
WAL segments
select, insert
update, delete
standby
(replica)
wal sender
wal receiver
startup
synchronous_commit = on
synchronous_standby_names
hot_standby_feedback = off
max_standby_streaming_delay = t
A replica can be set up to serve different purposes, and its configuration
depends on the intended use case.
One possible scenario is maintaining a hot standby for high availability
purposes. This means that if the main server fails, we need to switch over to
the replica as quickly as possible without losing any data.
Reliability is ensured by synchronous replication with synchronous_commit =
on mode (write option does not guarantee reliability, apply may cause
unnecessary delays).
For synchronous replication, the synchronous_standby_names configuration
parameter must specify a list of standby servers (replicas).
To minimize the replica's lag behind the primary server, WAL records should
be applied immediately. We can set the max_standby_streaming_delay
parameter to something small to achieve this.
To prevent queries on the replica from negatively impacting the primary
server, we can disable feedback (hot_standby_feedback = off).
With these settings, queries on the replica are allowed, but they'll be
terminated if conflicts occur. If queries to the replica aren't planned, you can
set it up in warm standby mode with hot_standby = off.
Note that replication is a fundamental mechanism for ensuring high
availability, but it's just one of many features of HA systems. This is covered
in more detail in the "Cluster Technologies" module.