4
Replication types
Physical
primary-replica: data flow in one direction only
delivery of WAL records or files
binary server compatibility is required
only the cluster as a whole can be replicated
Logical
publication-subscription: data flow is possible in both directions
row level information (log_level = logical)
protocol-level compatibility is required
can replicate individual tables
There are multiple ways to set up synchronization between servers. The two
main venues available in PostgreSQL are physical and logical replication.
During physical replication, one server is assigned the main server role and
the other becomes a replica. The main server transfers WAL records to a
replica (in the form of files or a stream of records). The replica applies these
records to its data files. The WAL record application is purely mechanical,
without "understanding the meaning" of the changes, so binary compatibility
between servers is necessary (the same platforms and major PostgreSQL
versions). Since the WAL is shared across the entire cluster, only the cluster
as a whole can be replicated.
During logical replication, higher-level information is added to the WAL,
allowing the replica to sort out changes at the row level (requires the
parameter wal_level = logical). This sort of replication does not require
binary compatibility, it only needs the replica to be able to understand the
incoming WAL information. Logical replication allows, if necessary, to
replicate only the changes made to individual tables.
Logical replication was introduced in PostgreSQL 10. Before, you had to use
the pg_logical extension or set up trigger-based replication.