# 错误：归档命令失败，退出代码为1 详细信息：归档命令是：cp %p /archive/%f

- **ID:** `database/postgres-wal-archive-failure`
- **领域:** database
- **类别:** system_error
- **验证级别:** ai_generated
- **修复率:** 85%

## 根因

PostgreSQL WAL归档命令因磁盘空间不足、权限问题或归档目标路径不正确而失败。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| PostgreSQL 14 | active | — | — |
| PostgreSQL 15 | active | — | — |
| PostgreSQL 16 | active | — | — |

## 解决方案

1. ```
   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;
   ```
3. ```
   Test the archive command manually: sudo -u postgres cp /var/lib/postgresql/16/main/pg_wal/000000010000000000000001 /archive/; then fix any errors.
   ```

## 无效尝试

- **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% 失败率)
- **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% 失败率)
