# 错误：归档命令失败，退出代码 1：cp pg_wal/000000010000000000000001 /archive/000000010000000000000001

- **ID:** `database/postgresql-wal-archiver-failed`
- **领域:** database
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 82%

## 根因

PostgreSQL 归档进程无法将 WAL 段复制到归档目标，通常由于磁盘满、权限问题或缺少目录。

## 版本兼容性

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

## 解决方案

1. ```
   检查磁盘空间和权限：df -h /archive; ls -ld /archive；然后确保归档目录存在：mkdir -p /archive && chown postgres:postgres /archive
   ```
2. ```
   手动测试归档命令：su - postgres -c 'cp /var/lib/postgresql/16/main/pg_wal/000000010000000000000001 /archive/000000010000000000000001' 并修复错误（例如 SELinux 上下文）。
   ```

## 无效尝试

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