# ERROR: archive command failed with exit code 1: cp pg_wal/000000010000000000000001 /archive/000000010000000000000001

- **ID:** `database/postgresql-wal-archiver-failed`
- **Domain:** database
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 82%

## Root Cause

The PostgreSQL archiver process fails to copy WAL segments to the archive destination, typically due to disk full, permission issues, or missing directory.

## Version Compatibility

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

## Workarounds

1. **Check disk space and permissions: df -h /archive; ls -ld /archive; then ensure the archive directory exists: mkdir -p /archive && chown postgres:postgres /archive** (80% success)
   ```
   Check disk space and permissions: df -h /archive; ls -ld /archive; then ensure the archive directory exists: mkdir -p /archive && chown postgres:postgres /archive
   ```
2. **Test the archive command manually: su - postgres -c 'cp /var/lib/postgresql/16/main/pg_wal/000000010000000000000001 /archive/000000010000000000000001' and fix errors (e.g., SELinux context).** (85% success)
   ```
   Test the archive command manually: su - postgres -c 'cp /var/lib/postgresql/16/main/pg_wal/000000010000000000000001 /archive/000000010000000000000001' and fix errors (e.g., SELinux context).
   ```

## Dead Ends

- **Restarting PostgreSQL without fixing the archive destination** — Restarting does not resolve the underlying issue; the archiver will continue to fail on the next WAL segment. (95% fail)
- **Setting archive_mode to off to stop archiving** — Disabling archiving can lead to WAL accumulation and potential data loss in case of a disaster recovery scenario. (90% fail)
