system residing on another computer. The only restriction is that
the mirroring must be done in a way that ensures the standby server
has a consistent copy of the file system — specifically, writes
- to the standby must be done in the same order as those on the master.
+ to the standby must be done in the same order as those on the primary.
DRBD is a popular file system replication solution
for Linux.
stream of write-ahead log (
WAL)
records. If the main server fails, the standby contains
almost all of the data of the main server, and can be quickly
- made the new master database server. This can be synchronous or
+ made the new primary database server. This can be synchronous or
asynchronous and can only be done for the entire database server.
logical replication constructs a stream of logical data modifications
from the WAL. Logical replication allows the data changes from
individual tables to be replicated. Logical replication doesn't require
- a particular server to be designated as a master or a replica but allows
+ a particular server to be designated as a primary or a replica but allows
data to flow in multiple directions. For more information on logical
replication, see . Through the
logical decoding interface (),
this is unacceptable, either the middleware or the application
must query such values from a single server and then use those
values in write queries. Another option is to use this replication
- option with a traditional master-standby setup, i.e. data modification
- queries are sent only to the master and are propagated to the
- standby servers via master-standby replication, not by the replication
+ option with a traditional primary-standby setup, i.e. data modification
+ queries are sent only to the primary and are propagated to the
+ standby servers via primary-standby replication, not by the replication
middleware. Care must also be taken that all
transactions either commit or abort on all servers, perhaps
using two-phase commit (
to reduce the communication overhead. Synchronous multimaster
replication is best for mostly read workloads, though its big
advantage is that any server can accept write requests —
- there is no need to partition workloads between master and
+ there is no need to partition workloads between primary and
standby servers, and because the data changes are sent from one
server to another, there is no problem with non-deterministic
functions like random().
|
- No master server overhead
+ No overhead on primary
•
•
|
- Master failure will never lose data
+ Primary failure will never lose data
•
•
with sync on
partitioned by offices, e.g., London and Paris, with a server
in each office. If queries combining London and Paris data
are necessary, an application can query both servers, or
- master/standby replication can be used to keep a read-only copy
+ primary/standby replication can be used to keep a read-only copy
of the other office's data on each server.
In standby mode, the server continuously applies WAL received from the
- master server. The standby server can read WAL from a WAL archive
- (see ) or directly from the master
+ primary server. The standby server can read WAL from a WAL archive
+ (see ) or directly from the primary
over a TCP connection (streaming replication). The standby server will
also attempt to restore any WAL found in the standby cluster's
pg_wal directory. That typically happens after a server
restart, when the standby replays again WAL that was streamed from the
- master before the restart, but you can also manually copy files to
+ primary before the restart, but you can also manually copy files to
pg_wal at any time to have them replayed.
pg_promote() is called, or a trigger file is found
(promote_trigger_file). Before failover,
any WAL immediately available in the archive or in pg_wal will be
- restored, but no attempt is made to connect to the master.
+ restored, but no attempt is made to connect to the primary.
- master-for-standby">
-
Preparing the Master for Standby Servers
+ primary-for-standby">
+
Preparing the Primary for Standby Servers
Set up continuous archiving on the primary to an archive directory
accessible from the standby, as described
in . The archive location should be
- accessible from the standby even when the master is down, i.e. it should
+ accessible from the standby even when the primary is down, i.e. it should
reside on the standby server itself or another trusted server, not on
- the master server.
+ the primary server.
pg_stat_replication view. Large differences between
pg_current_wal_lsn and the view's sent_lsn field
- might indicate that the master server is under heavy load, while
+ might indicate that the primary server is under heavy load, while
differences between sent_lsn and
pg_last_wal_receive_lsn on the standby might indicate
network delay, or that the standby is under heavy load.
streaming replication
- Replication slots provide an automated way to ensure that the master does
+ Replication slots provide an automated way to ensure that the primary does
not remove WAL segments until they have been received by all standbys,
- and that the master does not remove rows which could cause a
+ and that the primary does not remove rows which could cause a
recovery conflict even when the
standby is disconnected.
The cascading replication feature allows a standby server to accept replication
connections and stream WAL records to other standbys, acting as a relay.
- This can be used to reduce the number of direct connections to the master
+ This can be used to reduce the number of direct connections to the primary
and also to minimize inter-site bandwidth overheads.
A standby acting as both a receiver and a sender is known as a cascading
- standby. Standbys that are more directly connected to the master are known
+ standby. Standbys that are more directly connected to the primary are known
as upstream servers, while those standby servers further away are downstream
servers. Cascading replication does not place limits on the number or
arrangement of downstream servers, though each standby connects to only
- one upstream server which eventually links to a single master/primary
- server.
+ one upstream server which eventually links to a single primary server.
A cascading standby sends not only WAL records received from the
- master but also those restored from the archive. So even if the replication
+ primary but also those restored from the archive. So even if the replication
connection in some upstream connection is terminated, streaming replication
continues downstream for as long as new WAL records are available.
- If an upstream standby server is promoted to become new master, downstream
- servers will continue to stream from the new master if
+ If an upstream standby server is promoted to become the new primary, downstream
+ servers will continue to stream from the new primary if
recovery_target_timeline is set to 'latest' (the default).
a non-empty value. synchronous_commit must also be set to
on, but since this is the default value, typically no change is
required. (See and
- master"/>.)
+ primary"/>.)
This configuration will cause each commit to wait for
confirmation that the standby has written the commit record to durable
storage.
confirmation that the commit record has been received. These parameters
allow the administrator to specify which standby servers should be
synchronous standbys. Note that the configuration of synchronous
- replication is mainly on the master. Named standbys must be directly
- connected to the master; the master knows nothing about downstream
+ replication is mainly on the primary. Named standbys must be directly
+ connected to the primary; the primary knows nothing about downstream
standby servers using cascaded replication.
Note that in this mode, the server will apply WAL one file at a
time, so if you use the standby server for queries (see Hot Standby),
- there is a delay between an action in the master and when the
+ there is a delay between an action in the primary and when the
action becomes visible in the standby, corresponding the time it takes
to fill up the WAL file. archive_timeout can be used to make that delay
shorter. Also note that you can't combine streaming replication with
cleanup of old row versions when there are no transactions that need to
see them to ensure correct visibility of data according to MVCC rules.
However, this rule can only be applied for transactions executing on the
- master. So it is possible that cleanup on the master will remove row
+ primary. So it is possible that cleanup on the primary will remove row
versions that are still visible to a transaction on the standby.
Valid starting points for standby queries are generated at each
- checkpoint on the master. If the standby is shut down while the master
+ checkpoint on the primary. If the standby is shut down while the primary
is in a shutdown state, it might not be possible to re-enter Hot Standby
until the primary is started up, so that it generates further starting
points in the WAL logs. This situation isn't a problem in the most