SQLSTATE 58000 WARNING Class 58: System Error

system_error archive command failed with exit code N — 58000

PostgreSQL error “archive command failed with exit code N — 58000” (SQLSTATE 58000): what it means, common causes, and how to fix it.

PG 9.6, 10, 11, 12, 13, 14, 15, 16, 17, 18 Official docs
Last reviewed Jun 2026 Grounded in source

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

  1. Fix the archive destination (space, permissions, connectivity).
  2. Test the command manually; ensure it returns 0 only on success and never overwrites.
  3. Monitor pg_stat_archiver and 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”.

Was this helpful?