FULL AI ANALYSIS

PostgreSQL WAL archiving stalls during pg_basebackup when archive_command uses rsync over SSH

Generated Oct 3, 2026, 12:35:03 AM

Analysis summary

Stalls during archive_command using rsync/SSH are likely due to network or disk IO instability on the backup side compounded by the fact archive_command is executed synchronously by Postgres: if an archive_command hangs or fails to reliably transfer files, Postgres will retry, causing WAL accumulation. Measures that make archive_command more robust (timeouts, retries, atomic transfers) and decouple archiving from synchronous operations (e.g., local staging + async uploader) reduce risk. Also ensure backup target has stable disk space and IO to avoid mid-transfer resets.

Possible causes

Network instability or intermittent connection resets between primary and backup host causing rsync/ssh transfers to abort mid-file.

95%

Backup host disk IO contention or temporary full-disk conditions leading to rsync failures and connection terminations.

90%

Resource limits on SSH connection (session limits, timeouts) or lack of keepalive leading to idle connection termination during large transfers.

85%

archive_command runs synchronously and lacks proper timeout/retry handling or atomic file transfer semantics; partial files on target confuse downstream processes.

80%

Suggested fixes

1

Diagnostic step 1

Change archive_command to write WAL files to a local staging directory first (simple mv or cp), return success to Postgres, and have a separate asynchronous process (systemd timer, cron, or dedicated uploader) reliably transfer staged files to the backup host with logging, retries, and timeouts.

2

Diagnostic step 2

If continuing to use rsync/ssh, enable SSH keepalive (ServerAliveInterval and ServerAliveCountMax) and configure rsync with --timeout and --partial-dir to avoid corrupt/partial targets and allow resumption. Ensure rsync exit codes are properly handled and logged.

3

Diagnostic step 3

Monitor backup host disk usage and IO during base backups; add alerting for high utilization. Consider throttling concurrent base backups or scheduling during low-load windows.

4

Diagnostic step 4

Test archive_command under simulated network and disk failure conditions in a staging environment. If issues persist, consider using streaming replication to a dedicated standby and take base backups from standby (reduces load on primary).

5

Diagnostic step 5

If you lack in-house expertise for production changes or if WAL retention is critical and at risk, escalate to DBA or SRE with access to both primary and backup hosts to implement a staged async archiving solution and run induced-failure tests.