Skip to content
← All articles
Fundamentals·6 min read

Logical vs physical replication: when to use each

PostgreSQL offers two replication models. Physical replication sends native WAL to a compatible standby. Logical replication decodes selected table changes and sends them to a subscriber.

Both start with the same Write-Ahead Log, but they preserve different things. Physical replication follows the cluster's storage state. Logical replication follows selected data changes.

Use physical replication when another PostgreSQL server must be ready to take over the cluster. Use logical replication when selected tables or committed changes must reach another database or CDC destination. Many deployments need both.


Physical replication

Physical replication streams WAL records from a primary to compatible standbys. Each standby writes and replays the records through PostgreSQL recovery, keeping the cluster's physical state current within PostgreSQL's compatibility rules.

Physical replication sends WAL records to a compatible standby, while logical replication decodes WAL into row-level events for selective delivery to subscribers or CDC destinations

How physical streaming works

A WAL sender on the primary streams records over a replication connection. The standby's WAL receiver writes them into pg_wal, and recovery replays them against the standby's data files.

Streaming is asynchronous by default. The primary can acknowledge a commit before the standby receives its WAL. If the primary is then lost and that standby is promoted, the missing transactions are outside the standby's recovered state.

Synchronous replication makes the primary wait for configured standby feedback. The exact durability and visibility boundary depends on synchronous_commit, the selected synchronous standbys, and the failover procedure.

With hot_standby = on, PostgreSQL accepts client connections during recovery, but those transactions are strictly read-only. Even temporary tables and sequence updates are blocked. PostgreSQL still performs internal writes for WAL replay, hint bits, temporary query files, and other recovery work.

Physical replication strengths

Failover target. An operator or failover system can promote a suitable standby when the primary becomes unavailable. The possible data-loss window depends on commit settings and how far the standby had written, flushed, or replayed WAL.

Cluster-wide state. Physical WAL covers the cluster rather than a publication's selected tables. Temporary and unlogged data follow different durability rules, while configuration outside the cluster needs separate management.

Read scaling. A hot standby can serve read-only queries. Query results may lag behind the primary, and replay can cancel queries that conflict with recovery.

Shared recovery format. WAL archiving uses the same physical format for point-in-time recovery, but PITR is an archiving and base-backup mechanism rather than a streaming-replication feature.

Physical replication limits

No table selection. Physical replication applies the cluster's WAL. It cannot publish one table or database independently.

Physical compatibility. PostgreSQL 18 does not support log shipping across major versions or different hardware architectures. Different minor releases may work, but PostgreSQL offers no formal support and recommends keeping primary and standby at the same release where possible.

PostgreSQL-only bytes. A non-PostgreSQL destination cannot apply native WAL as logical row changes.

No writable standby. A physical standby cannot accept client writes until promotion ends recovery.


Logical replication

Logical replication converts WAL into structured INSERT, UPDATE, DELETE, and TRUNCATE changes. PostgreSQL's built-in subscriber applies those changes to its own tables rather than replaying the publisher's physical storage records.

How publication and subscription work

The pgoutput plugin produces logical-replication messages. A logical replication slot retains the subscriber's position and required WAL.

A publication selects tables, columns, row filters, and operation types:

CREATE PUBLICATION orders_pub FOR TABLE orders, order_items;

A subscription connects the subscriber to one or more publications:

CREATE SUBSCRIPTION orders_sub
    CONNECTION 'host=primary dbname=mydb'
    PUBLICATION orders_pub;

With the default copy_data = true, PostgreSQL starts dedicated table-synchronization workers. Each worker copies an initial table snapshot, then catches up with changes that arrived during the copy before normal replication continues.

The publisher needs wal_level = logical, enough replication slots, and enough WAL senders for subscriptions and table synchronization.

Logical replication strengths

Selective replication. Publications can choose tables, columns, row filters, and any combination of INSERT, UPDATE, DELETE, and TRUNCATE.

Cross-version upgrades. PostgreSQL supports logical replication between major versions. Publisher and subscriber schemas must remain compatible with the replicated data, and upgrade plans still need extension, role, sequence, and DDL handling.

External CDC. An external processor can consume logical-decoding messages and map them to Kafka, object storage, another database engine, or an application endpoint. This is separate from PostgreSQL's built-in subscription apply path.

Independent subscribers. Several subscriptions can consume the same publication. Each subscription receives changes through its own replication slot.

Writable subscriber. A logical subscriber is a normal PostgreSQL database. Local writes are possible, but overlapping writes or subscriptions can produce conflicts.

Logical replication limits

DDL is not replicated. Schema changes must be managed separately. Apply compatible additive changes on the subscriber before publisher changes begin sending rows that require them.

Sequence state is not replicated. Replicated rows carry values generated by sequences, but the sequence objects do not advance on the subscriber. Update them before promoting the subscriber for application writes.

Table data only. Roles, permissions, extensions, server configuration, system catalogs, and other non-table state need separate migration.

Built-in PITR remains physical. PostgreSQL PITR restores a base backup and replays archived physical WAL. Archiving decoded events for selected-state replay is a separate external mechanism.

Large objects are not replicated. PostgreSQL's large-object API is outside built-in logical replication.


Physical and logical replication compared

PhysicalLogical
Replication unitEntire clusterSelected tables and rows
Data formatNative WAL recordsDecoded table changes
Same PostgreSQL major versionRequiredNot required
Client-writable targetOnly after promotionYes, with conflict risk
DDL effectsReplayed as physical cluster changesNot replicated
Sequence stateIncluded in cluster stateNot replicated
Non-PostgreSQL deliveryNoRequires an external decoder and sink path
Built-in PITR pathUses the same physical WAL formatNo
Table and row filteringNoYes
Read queriesHot standbyNormal subscriber queries
Minimum wal_levelreplicalogical

Running both modes

One primary can serve physical standbys and logical subscribers at the same time. wal_level = logical contains the information required by the lower replica level.

Use a physical standby for failover and read queries, then send selected logical changes to Kafka, search, or an analytical store. Each path keeps its own slots, progress, destinations, and failure boundaries.

Running both adds logical-decoding work, WAL senders, replication slots, retained WAL, and network traffic. Measure those costs against the production write rate and retention policy.


The related articles explain PostgreSQL WAL internals and Change Data Capture. For the complete category, see transaction log processing.

We built Remac to operate logical and physical transaction-log paths under one product model. PostgreSQL is the first implemented source. MySQL, MongoDB, and Oracle sources are planned.


Further reading

More from this volume