FULL AI ANALYSIS

PostgreSQL WAL archiving stops when archive_command intermittently exits 75 (permission denied) — WAL accumulates on primary

Generated Oct 25, 2026, 9:44:56 AM

Analysis summary

Exit code 75 from PostgreSQL archive_command indicates the child process returned non-zero; common root causes include environment differences when invoked by postgres (PATH, ssh agent, key passphrase), resource limits (ulimit) under heavy load, or the shell wrapper relying on environment not present in postgres exec context. The fact manual runs succeed but archive fails during heavy I/O suggests transient resource starvation (fork/exec limits) or that the script depends on an agent socket (SSH_AUTH_SOCK) not available under the postgres service. Another likely vector is that scp spawns subprocesses and under high load the postgres child is killed before completion.

Possible causes

archive_command script depends on environment (SSH agent, PATH, HOME) absent when run by postgres process leading to auth failures under certain conditions.

85%

Resource limits (nproc, open files) or transient fork failures during heavy load causing child processes to exit with non-zero.

60%

Network hiccups to remote archive host causing scp to fail intermittently; script returns 75 due to mapped error code.

40%

Permission or SELinux/AppArmor denial when archive_command invoked by postgres (different context) despite manual success.

30%

Suggested fixes

1

Diagnostic step 1

Modify archive_command to use a reliable, minimal environment wrapper: e.g. /usr/local/bin/archive-wrapper.sh that sets PATH, HOME, and uses ssh -i /var/lib/postgresql/.ssh/id_rsa -o BatchMode=yes -o ConnectTimeout=10, and logs stdout/stderr to /var/log/postgres-archive.log for each attempt.

2

Diagnostic step 2

Ensure wrapper is owned by postgres and executable, and test by su -s /bin/bash postgres -c '/usr/local/bin/archive-wrapper.sh /path/to/wal'.

3

Diagnostic step 3

Increase postgres resource limits if system limits are low: check /etc/security/limits.conf and systemd unit LimitNOFILE/LimitNPROC for the postgres service.

4

Diagnostic step 4

Temporarily switch archive_mode to 'on' but set archive_timeout small and monitor; do not disable archiving. If necessary, implement local spool directory and a separate cron process (running as postgres) to forward WALs so archiving is decoupled from WAL generation.

5

Diagnostic step 5

After changes, monitor postgres log for archive success lines and that WAL files are removed. If permission/SELinux issues suspected, check audit logs and run the wrapper under the postgres service context for testing. Escalate to infra if network instability persists.