FULL AI ANALYSIS

PostgreSQL replica accumulates WAL and stalls after archive_command ownership changed during maintenance

Generated Oct 26, 2026, 9:23:15 AM

Analysis summary

Primary logs indicate archive_command permission errors preventing WAL archival; streaming replication keeps WAL segments due to retention and replication slot. Changing ownership back to postgres likely fixed some cases but strict directory permissions or SELinux/AppArmor could still block writes. The immediate goal is to restore successful archival so WAL can be archived/removed, then replay or remove excess WAL as appropriate. Caution required to avoid deleting WAL needed by lagging standby.

Possible causes

archive_command failing due to filesystem permission/ownership preventing postgres from writing WAL copies

90%

AppArmor/SELinux profile blocking postgres archive writes after ownership change

50%

Archive disk full or mount options (noexec/nosuid) interfering with archive_command scripts

30%

Replication slot preventing WAL removal because standby disconnected or unhealthy

25%

Suggested fixes

1

Diagnostic step 1

Confirm ownership and permissions: chown -R postgres:postgres /var/lib/pgsql/archive and set directories to 750 or 755; ensure postgres can create files as the postgres user.

2

Diagnostic step 2

As postgres user, run the exact archive_command on a WAL file (su - postgres; /bin/bash -c "<archive_command> path/to/WAL") and observe return code and errors.

3

Diagnostic step 3

Check AppArmor/SELinux logs (journalctl, /var/log/audit/audit.log) and temporarily put profile in complain/permissive mode while testing.

4

Diagnostic step 4

Once archival succeeds for recent WAL, monitor pg_wal removal; if disk near full, add temporary disk and set archive_command to write to new location, restart archiving, then allow old WAL to be archived and removed.