Postgres WAL Replay Outpaces Logical Replication Under Write Bursts
A write burst exposes the difference between physical WAL replay and logical replication more sharply than any benchmark. Physical replay ships raw blocks and scales with sequential write bandwidth. Logical decoding parses every change, and that per-row tax compounds under load. This piece explains why the gap exists, walks through a real failure at a payments startup, and lays out an operational playbook for keeping logical subscribers from becoming a liability.
WAL Replay Wins on Burst Throughput
Physical replication ships raw blocks. The primary writes WAL records, and a standby replays those records without interpreting them as SQL. A block change is a block change. The standby does not need to know which table it belongs to, which index it touches, or what the planner would do with the statement that produced it.
Logical replication works differently. It reads the same WAL stream but runs each record through an output plugin, which reconstructs a row-level change. That means parsing the record, looking up catalog metadata, and emitting a message the subscriber can apply. The overhead is small per transaction and large per million.
Bursts expose the gap. A batch job that inserts a few million rows in a short window produces a WAL volume that physical replay consumes at disk speed. Logical decoding consumes it at parse speed, which is slower and less predictable. Replay scales with sequential write bandwidth. Decode scales with CPU and catalog contention.
The shape of the WAL matters too. Physical replay is indifferent to transaction boundaries in the sense that it applies page changes as they arrive, so a single enormous transaction does not create a cliff at commit time. Logical decoding holds the whole transaction in memory until commit, then emits it in one burst of messages. The larger the transaction, the more pronounced the spike at the moment it lands. Batch jobs that wrap millions of rows in one transaction hit the decoder and the subscriber at exactly the same instant, which is the worst possible timing for a system that wants steady, predictable apply rates.
Logical Replication Decodes Every Change
Output plugins parse WAL records into a logical format. The built-in pgoutput plugin, used by native logical replication, reads each record and produces insert, update, or delete messages. For every change, it consults the system catalogs to resolve relation OIDs, column types, and replica identity settings.
Catalog lookups add per-transaction cost. The plugin caches some metadata, but a burst that touches many tables or creates temporary relations forces repeated lookups. Long transactions amplify memory pressure because the decoder must hold change data until commit. A single transaction that writes a million rows can pin a large chunk of memory in the walsender process.
Subscribers apply changes single-threaded by default. Postgres has added parallel apply for logical replication in recent versions, but the default remains one apply worker per subscription. The subscriber becomes the bottleneck even when the publisher keeps up. The decode tax on the publisher and the apply bottleneck on the subscriber compound under sustained write pressure.
There is a subtler cost that shows up only under bursts: the decoder has to maintain a consistent snapshot view while it works. When the workload churns through schema changes, or when a batch job touches a wide set of partitions, the catalog cache thrashes. Each miss is a catalog read, and catalog reads compete with the same buffer pool the rest of the system is using. At steady state this is noise. At burst rates it turns into a measurable drag on the whole primary, not just the walsender.
The 2 AM Incident at a Payments Startup
A payments startup ran a logical replication slot to feed an analytics cluster. The slot was created for a selective set of tables and had worked fine for months at steady-state traffic. Then a nightly batch settlement job changed shape. A new pricing rule caused the job to write several times more rows than before, in a tighter window.
The logical subscriber fell hours behind. The walsender kept decoding, but the apply worker on the subscriber could not keep pace. WAL segments accumulated on the primary because the slot retained them until the subscriber confirmed receipt. Postgres does not discard WAL that an active slot still needs, so the primary's disk filled.
Failover to a physical standby restored service. The standby had been replaying the same WAL stream at block level and was nearly current. Promoting it took seconds. The logical slot on the old primary was abandoned, and the analytics feed was rebuilt from a fresh snapshot the next day. The incident cost a few hours of analytics freshness and one tense morning.
What made the incident instructive was the sequence. The disk did not fill because the primary was slow. The primary was healthy and writing at full speed. The disk filled because a consumer that had nothing to do with serving traffic could not confirm receipt fast enough, and the retention rule held the primary hostage to that consumer's pace. The failure mode lived entirely in the coupling between a fast producer and a slow, optional consumer.
Why Replay Avoids the Decode Tax
There is no SQL parsing on the standby. The standby reads WAL records and applies page-level changes to shared buffers. It does not run the planner, evaluate expressions, or check constraints in the same way. Constraint checks happened on the primary. The standby trusts the WAL.
Block-level copy skips the planner entirely. A physical standby does not need to know why a page changed. It applies the change and moves on. That is why replay latency stays predictable under sustained load, even when the workload includes large transactions and many small ones interleaved.
Recent Postgres versions added parallel redo, which lets the standby apply WAL records using multiple processes. The feature is not a cure-all, and it depends on the workload, but it widens the margin between replay and decode under burst conditions. The standby's apply rate tracks disk throughput more closely than CPU headroom.
Predictability is the real prize. A logical subscriber's lag is a function of row shape, table count, catalog churn, and subscriber apply capacity, which means it can swing by an order of magnitude between two workloads that generate identical WAL volume. A physical standby's lag is a function of disk write bandwidth, which is boring and therefore easy to reason about. When you are deciding what to put behind a promotion button, boring wins.
When Logical Replication Still Earns Its Place
Cross-version upgrades need logical slots. A physical standby must run the same major version as the primary. Logical replication can bridge a major-version upgrade with less downtime, because the subscriber can run the new version while the publisher runs the old one. That flexibility has real value during a migration window.
Selective table replication for analytics is another case. Logical replication can publish a subset of tables, which keeps the analytics cluster from carrying data it does not need. Physical replication ships everything. For a primary with large tables that analytics never touches, the selectivity is worth the decode cost.
Zero-downtime migrations across clusters often depend on logical replication. The same mechanism that makes it slower under bursts makes it more flexible for cutovers. Accept the decode cost when schema flexibility or version bridging matters more than raw throughput. The trade-off is real, and it is not always the wrong choice. This site has argued before that failure reasoning matters more than framework fluency, and the same logic applies here: know which failure mode you are optimizing for.
There is a middle path worth naming. You can run logical replication for the tables that genuinely need row-level filtering and keep everything else on physical replication, so the decode tax applies only to the slice of traffic that benefits from it. Splitting the workload this way keeps the burst-sensitive bulk path on block replay while the analytics feed carries only the narrow tables it was built for. It costs you a second slot to manage and a second set of lag metrics to watch, which is a fair price for removing the coupling that caused the incident above.
Operational Playbook for Write Bursts
Set max_slot_wal_keep_size to cap disk risk. The setting limits how much WAL a slot can retain. When the limit is exceeded, Postgres invalidates the slot rather than filling the disk. An invalidated slot breaks the subscriber, but a broken subscriber is easier to rebuild than a full primary.
Monitor pg_stat_replication lag continuously. The view reports write, flush, and replay lag for each standby and logical subscriber. Alert on sustained lag growth rather than a fixed threshold, because a burst can push lag up briefly without indicating a real problem. Sustained growth is the signal that matters.
Keep a physical standby as the failover target. A logical subscriber is not a failover target. It applies changes through a different path, and it may be behind in ways that make promotion unsafe. The physical standby should be the promotion candidate, with the logical subscriber reserved for its specific purpose.
Test logical subscribers against peak write rates. A subscriber that keeps up at steady state can fall far behind during a batch job. Run the batch job against a staging replica and measure apply lag. If the subscriber cannot keep up, either add parallel apply workers or move the feed to a different mechanism.
Alert on WAL generation rate spikes. A sudden increase in WAL generation often precedes a replication problem. The rate spike is visible before lag grows, which gives operators time to react. Pair the alert with a runbook that names the slot, the subscriber, and the failover target. For teams thinking about how to staff this kind of operational reasoning, a related piece on SRE hiring and routing depth covers the broader skill question.
Size the retention budget against real disk headroom, not against a round number. If the primary has a few hundred gigabytes free, a slot cap in the low tens of gigabytes is a reasonable guardrail, and the exact figure should come from measuring how long a rebuild takes versus how long the disk can absorb a stalled consumer. The cap is a fuse, and a fuse you have never sized against your own rebuild time is a fuse you are trusting blindly.