# ERROR: archive command failed with exit code 1 DETAIL: The archive command was: cp %p /archive/%f

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

## Root Cause

PostgreSQL WAL archiving command fails due to insufficient disk space, permission issues, or incorrect archive destination path.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| PostgreSQL 14 | active | — | — |
| PostgreSQL 15 | active | — | — |
| PostgreSQL 16 | active | — | — |

## Workarounds

1. **Check disk space on archive destination: df -h /archive; if full, free space or increase archive destination mount size.** (90% success)
   ```
   Check disk space on archive destination: df -h /archive; if full, free space or increase archive destination mount size.
   ```
2. **Fix permissions on archive directory: chown -R postgres:postgres /archive; chmod 700 /archive;** (85% success)
   ```
   Fix permissions on archive directory: chown -R postgres:postgres /archive; chmod 700 /archive;
   ```
3. **Test the archive command manually: sudo -u postgres cp /var/lib/postgresql/16/main/pg_wal/000000010000000000000001 /archive/; then fix any errors.** (95% success)
   ```
   Test the archive command manually: sudo -u postgres cp /var/lib/postgresql/16/main/pg_wal/000000010000000000000001 /archive/; then fix any errors.
   ```

## Dead Ends

- **Increase wal_keep_segments to a very high value to avoid archiving** — This only delays the problem; WAL segments still accumulate and eventually fill pg_wal, causing PostgreSQL to crash. (60% fail)
- **Set archive_mode=off to disable archiving entirely** — Disabling archiving breaks point-in-time recovery and replication; not a viable fix for production systems that require backups. (90% fail)
