PostgreSQL standby stops applying WAL during long-running transactions on primary after pg_basebackup restore
Environment
Primary: PostgreSQL 14.5 on Debian 11, heavy OLTP workload with frequent long-running reporting transactions; Standby: streaming replication via walreceiver using primary_conninfo (replication user), recovery.signal present after pg_basebackup; wal_level = replica, synchronous_commit = on, archive_mode = on with archive_command set to copy WALs to shared NFS.
Symptoms
Standby initially replicates WAL and is caught up. When primary executes long-running SELECTs with REPEATABLE READ or application-level idle-in-transaction lasting >30 min, WAL shipping to standby continues but standby's replay_lag increases and WAL application halts until primary transaction commits. During stall, queries on standby show waiting on 'replay' and pg_stat_replication on primary shows 'write' and 'flush' positions ahead of 'replay'.
Observations
On standby, pg_stat_activity shows walreceiver active but walreceiver process reports 'waiting for new data' after a particular WAL location. primary logs show no WAL flush errors. Archive of WAL segments succeeds to NFS. There are no network interruptions; bandwidth underutilized. When the long-running transaction on primary commits, standby quickly applies backlog. Prometheus metrics show wal_receive_lag spikes in lockstep with application transactions.
Already attempted
Increased wal_receiver_timeout and work_mem on standby — no effect. Tested with synchronous_commit = local on primary to reduce flush waits — behavior unchanged. Performed a base backup again and rebuilt standby — same pattern. Stopped the long-running query on primary and standby catches up immediately. Temporarily reduced max_wal_senders — no change.
Question
Why does the standby defer WAL application while a long-running transaction remains open on the primary, and what safe configuration adjustments or operational practices will allow near-real-time replay without risking data consistency?
Verified community troubleshooting
No answers yet..
Incident analysis
Most likely causes
Summary
Suggested Fixes
Continue troubleshooting
Related troubles
Matched from the title, description and tags
- Databases37% match
PostgreSQL replica stops streaming WAL after pg_repack on primary; replication slot reports missing WAL
Open0 answers - Databases36% match
PostgreSQL primary WAL sender CPU spikes and replication lag after enabling frequent TLS renegotiation on streaming replication
Open0 answers - Databases33% match
PostgreSQL replica falls behind and reports WAL streaming delay when frequent autovacuum runs on primary
Open0 answers - Databases30% match
PostgreSQL logical replication slot grows until disk full after subscriber disconnects during nightly load
Open0 answers - Databases25% match
PostgreSQL logical replication falls behind after ALTER TABLE ADD COLUMN with non-null DEFAULT on large table
Open0 answers