WAL archiving stalls and primary reports 'could not flush file' during checkpoint under nightly bulk load
Environment
PostgreSQL 13.7 on Debian 11 VM with LVM thin-provisioned ext4 data volume hosted on shared SAN; wal_level = replica, archive_mode = on with archive_command copying WAL to a remote NFS archive server; nightly bulk import job inserts ~200M rows over several hours.
Symptoms
During nightly bulk import the primary occasionally blocks at checkpoints and reports repeated errors of the form: 'could not flush file
Observations
pg_wal contains many files awaiting archiving; archive_command processes show repeated 'No space left on device' on the NFS mount for the archive server at the time of failure. Kernel logs (/var/log/kern.log) show 'NFS: server not responding' and writeback timeouts on the VM's block device around checkpoint times. iostat shows write latency spikes on the local SAN LUN preceding the PostgreSQL errors. After freeing space on the NFS archive target, archive_command resumes but PostgreSQL still experiences long checkpoint durations and subsequent WAL file growth.
Already attempted
Manually cleared old archives on the NFS server to restore space, retried archive_command which succeeded; adjusted archive_command to use rsync with --partial to reduce retries; increased max_wal_size temporarily from 2GB to 8GB to delay checkpoints; monitored IO with iostat and vmstat; rebooted the VM when writeback timeouts persisted. Restoring space allowed archive to finish, but intermittent SAN writeback latency still correlated with checkpoints.
Question
What combination of reversible configuration changes and diagnostics will reliably prevent WAL archiving stalls and checkpoint 'could not flush file' errors during heavy bulk loads, and how can we determine whether the root cause is NFS archive target running out of space, SAN write latency under heavy writeback, or a misconfiguration of archive_command/concurrency?
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
- Databases35% match
PostgreSQL WAL archiving stalls during pg_basebackup when archive_command uses rsync over SSH
Open0 answers - Databases34% match
PostgreSQL logical replication slot grows until disk full after subscriber disconnects during nightly load
Open0 answers - Databases29% match
PostgreSQL standby stops applying WAL during long-running transactions on primary after pg_basebackup restore
Open0 answers - Databases29% match
PostgreSQL replica falls behind and reports WAL streaming delay when frequent autovacuum runs on primary
Open0 answers - Databases28% match
PostgreSQL replica stops streaming WAL after pg_repack on primary; replication slot reports missing WAL
Open0 answers