Diagnostic Queries
Symptoms
The configured archive_command returned a non-zero exit code, so a WAL segment was not archived. PostgreSQL raises SQLSTATE 58000 (system_error) and retries.
- WAL archiving failed for a segment.
- PostgreSQL retries until it succeeds.
- Unarchived WAL accumulates, risking a full pg_wal.
What the server log shows
LOG: archive command failed with exit code 1
DETAIL: The failed archive command was: test ! -f /mnt/arch/000000010000000000000023 && cp pg_wal/000000010000000000000023 /mnt/arch/
Why PostgreSQL raises this — what the manual says
Section 25.3.1 Setting Up WAL Archiving:
“This will cause WAL files to accumulate in pg_wal/ until a working archive_command is re-established.”
Continuous archiving runs archive_command per WAL segment; a zero exit means success. A non-zero exit signals failure, so PostgreSQL keeps the segment and retries, reporting 58000. Persistent failures cause WAL to pile up.
Common causes
- Archive destination full, unreachable, or permission-denied.
- A bug in the archive command (overwrite/exit-code handling).
- Network/mount failure for remote archive storage.
How to fix it
- Fix the archive destination (space, permissions, connectivity).
- Test the command manually; ensure it returns 0 only on success and never overwrites.
- Monitor
pg_stat_archiverand pg_wal size to avoid running out of space.
Diagnostic query
SELECT archived_count, failed_count, last_failed_wal, last_failed_time FROM pg_stat_archiver;
Rising failed_count and a recent last_failed_time confirm ongoing archiving failures.
Related & next steps
Reference: PostgreSQL 18 Section 26.3 “Continuous Archiving”.
Thanks — noted. This helps keep the database accurate.