# ERROR: archive command failed with exit code 1

- **ID:** `database/postgresql-wal-archive-timeout`
- **Domain:** database
- **Category:** system_error
- **Verification:** ai_generated
- **Fix Rate:** 85%

## Root Cause

The PostgreSQL archive_command (e.g., cp or rsync) failed due to disk full, permission issues, or network unreachability, causing WAL archiving to stall and potentially leading to replication lag or transaction loss.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| PostgreSQL 15.6 | active | — | — |
| PostgreSQL 14.11 | active | — | — |
| PostgreSQL 16.2 | active | — | — |

## Workarounds

1. **Check the archive destination for disk space (df -h /archive/path) and permissions (ls -ld /archive/path). If full, free space or move to a different location; then update archive_command in postgresql.conf and reload: SELECT pg_reload_conf();** (90% success)
   ```
   Check the archive destination for disk space (df -h /archive/path) and permissions (ls -ld /archive/path). If full, free space or move to a different location; then update archive_command in postgresql.conf and reload: SELECT pg_reload_conf();
   ```
2. **Test the archive command manually: su - postgres -c 'archive_command_test' (e.g., cp /path/to/test.wal /archive/). If it fails, fix the command (e.g., add -p to mkdir) or switch to a simpler method like pg_receivewal.** (85% success)
   ```
   Test the archive command manually: su - postgres -c 'archive_command_test' (e.g., cp /path/to/test.wal /archive/). If it fails, fix the command (e.g., add -p to mkdir) or switch to a simpler method like pg_receivewal.
   ```
3. **If the archive destination is temporarily unavailable, set archive_mode = off in postgresql.conf and restart, then re-enable it after fixing the destination: ALTER SYSTEM SET archive_mode = off; SELECT pg_reload_conf(); -- then fix destination, then set archive_mode = on.** (80% success)
   ```
   If the archive destination is temporarily unavailable, set archive_mode = off in postgresql.conf and restart, then re-enable it after fixing the destination: ALTER SYSTEM SET archive_mode = off; SELECT pg_reload_conf(); -- then fix destination, then set archive_mode = on.
   ```

## Dead Ends

- **Increasing archive_timeout to reduce archiving frequency** — This only delays the failure; the archive command will still fail if the underlying issue (e.g., disk space) is not resolved. (90% fail)
- **Setting archive_mode = off to stop archiving entirely** — This disables WAL archiving, which may be required for PITR or replication; it also leaves the system without a backup strategy, risking data loss. (85% fail)
- **Restarting PostgreSQL without fixing the archive destination** — Restarting does not resolve the root cause; the archive command will fail again immediately after the restart. (100% fail)
