DEBUG.WIKI
ZgoCloud:多地区部署,按需选节点;日本、美国、香港、德国
V.PS:让项目靠近用户,亚太、欧洲、北美 KVM VPS
晚安云;香港 CN2 ¥15/月

解决 Prometheus 报错 TSDB: WAL corruption at head commit 崩溃

分析 Prometheus 启动报 TSDB WAL corruption at head commit 崩溃根因,详解 WAL 损坏片段定位、安全修复与数据恢复步骤。

问题现象

Prometheus Pod 或服务在意外断电重启后无法启动并处于 CrashLoopBackOff,日志输出致命异常:

ts=2026-11-15T11:30:00.123Z caller=main.go:800 level=error err="opening storage failed: TSDB: WAL corruption at head commit: read /var/prometheus/wal/00000123: unexpected EOF"
panic: opening storage failed

触发根因

  1. 写操作期间操作系统宕机导致最新 WAL 块截断(Unexpected EOF):预写日志物理文件末尾缺少完整的校验和,TSDB 引擎出于数据完整性考虑主动放弃加载并崩溃。

诊断排查步骤

  1. 检查 WAL 目录中的文件序列:
ls -lh /var/prometheus/wal/

找到日志中报错的那个具体文件(如 00000123),通常其文件体积异常变小。

解决步骤与操作命令

步骤一:备份当前 WAL 目录(防止二次破坏)

cp -r /var/prometheus/wal /var/prometheus/wal_corrupted_bak

步骤二:直接删除受损的最后一个 WAL 片段文件

由于 Prometheus WAL 仅用于重放最近 2 小时未持久化落盘的数据,删除损坏的最末端文件只会损失断电前几分钟的临时数据,但能彻底让整个历史时序库自愈拉起:

rm -f /var/prometheus/wal/00000123

步骤三:或者在启动参数中开启自动修复容错

在 Prometheus 启动参数中加入容灾跳过参数:

--storage.tsdb.wal-compression

步骤四:重新启动 Prometheus 服务

systemctl start prometheus
# 或在 K8s 中重建 Pod
kubectl delete pod -l app.kubernetes.io/name=prometheus -n monitoring

验证方法

检查 Prometheus 运行日志:

kubectl logs -l app.kubernetes.io/name=prometheus -n monitoring --tail=50

输出显示 TSDB started,Web UI 正常打开,历史监控数据完整保留。