Databases

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

Environment

Environment

PostgreSQL 13 primary on Debian 11; archive_mode=on; archive_command calls a shell script that scp WAL files to remote archiver. Script runs as postgres user, uses ssh key in /var/lib/postgresql/.ssh, remote host reachable via corporate WAN. Observed during nightly bulk loads.

Symptoms

Symptoms

WAL files stop being archived; primary logs show repeated WARNING: archive command failed with exit code 75, archiver process sleeping for 60 seconds. Replica lag grows; disk on primary starts filling with WAL. The scp/ssh endpoint is reachable from other hosts and filesystem on the primary has free space.

Observations

Observations

Postgres log entries show 'archive command failed with exit code 75' at times matching the bulk load bursts. Running the archive script manually as the postgres user succeeds. strace on postgres process not possible in prod. File permissions on /var/lib/postgresql/.ssh/id_rsa are 600 and owned by postgres. The script uses /bin/bash -l -c 'scp ...' via sudo in some older configs.

Already attempted

Already attempted

Restarted postgresql service (temporary archival resumed then failed again); ran the archive script manually as postgres and it worked. Switched archive_command to a simpler psql-friendly 'test-wal && scp' wrapper temporarily; still saw intermittent exit 75 from PostgreSQL. Increased logging verbosity for archive_command but logs only show exit code.

Question

Question

What causes PostgreSQL's archive_command to return 75 intermittently despite the script working when run manually, and how to prevent WAL pileup safely?

COMMUNITY RESPONSES

Verified community troubleshooting

0 replies

No answers yet..

Showing 0 of 0 community responses
AI DIAGNOSTICS

Incident analysis

Updated 4w ago• Trouble ID

Most likely 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%

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.

Suggested Fixes

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.
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'.
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.

Continue troubleshooting

Matched from the title, description and tags