Standby PostgreSQL fails replay with 'invalid record length' after restoring base backup from different wal_segment_size
Environment
PostgreSQL 14 primary built with default wal_segment_size during initdb on primary host; standby was provisioned via pg_basebackup from a primary which used a non-default wal_segment_size (e.g., 64MB vs 16MB). Standby is running streaming replication as a physical standby.
Symptoms
Standby connects to primary and receives WAL, but WAL replay aborts with errors such as 'invalid record length' or 'unexpected end of WAL' at early LSN. Replication slot on standby grows as standby cannot apply WAL. System logs show repeated replay failures at same LSN.
Observations
pg_basebackup completed without error. pg_controldata on primary and standby show different wal_segment_size values. stalling occurs immediately after starting recovery; there are no disk IO errors or kernel messages indicating hardware corruption. Re-fetching WAL segments from primary does not resolve replay errors.
Already attempted
Re-ran pg_basebackup once; verified recovery.conf and restore_command; attempted to copy older WAL files manually; tried pg_resetwal (abandoned due to risk). Did not perform pg_rewind. No changes to postgresql.conf besides hot_standby settings.
Question
Can the standby be recovered without a full resync? What is the safe recovery path when wal_segment_size differs between clusters used for base backup and primary?
Verified community troubleshooting
Check pg_controldata on both primary and standby — if wal_segment_size differs, you must reinitialize the standby from a base backup taken from the primary. The WAL format depends on that size, so replaying incompatible WAL yields 'invalid record length'. Take a fresh pg_basebackup from the primary and start the standby from that backup; once replication is streaming and replaying cleanly, remove the old standby. Keep the old data directory offline for investigation but don’t run pg_resetwal unless you accept possible data loss. This restores safe replication with matching control data.
Incident analysis
Most likely causes
Summary
Suggested Fixes
Continue troubleshooting
Related troubles
Matched from the title, description and tags
- Databases37% match
PostgreSQL standby stops applying WAL during long-running transactions on primary after pg_basebackup restore
Open0 answers - Databases29% match
PostgreSQL standby stops applying WAL with 'invalid record length' after pg_upgrade and manual archive restore
Open0 answers - Databases29% match
PostgreSQL standby stops applying WAL after pg_basebackup restore — replication slot grows and disk fills
Open0 answers - Databases28% match
PostgreSQL standby reports 'invalid checksum' and stops applying WAL after incremental base backup restore
Open0 answers - Databases26% match
PostgreSQL WAL archiving stalls during pg_basebackup when archive_command uses rsync over SSH
Open0 answers