Prometheus TSDB Block Corruption Repair Fix
In this tutorial, you'll learn about Prometheus TSDB Block Corruption Repair Fix. We cover key concepts, practical examples, and best practices.
Your Prometheus TSDB fails to load blocks after a disk error — logs show error loading blocks: block corruption detected or checksum mismatch in block. The TSDB stores compacted data in blocks, and a corrupted block prevents the database from opening.
The Problem
level=error msg="Error opening TSDB" err="open /data/01J6KX: checksum mismatch"
A TSDB block has a checksum mismatch — the block data on disk does not match its expected checksum. This can happen due to disk errors, incomplete writes, or filesystem corruption.
Step-by-Step Fix
1. Identify corrupted blocks
# List all blocks and their status
promtool tsdb list /var/lib/prometheus/data
# Check for blocks with errors
promtool tsdb analyze /var/lib/prometheus/data
# Find blocks with checksum issues
ls -la /var/lib/prometheus/data/*/index
# If index file is missing or zero-size, the block is corrupted
2. Remove corrupted blocks
# Stop Prometheus
systemctl stop prometheus
# Remove the corrupted block directory
rm -rf /var/lib/prometheus/data/01J6KX
# Restart Prometheus
systemctl start prometheus
Data loss is limited to the time range of the removed block (typically 2 hours of data).
3. Verify remaining blocks
# Check block integrity
promtool tsdb analyze /var/lib/prometheus/data
# Check remaining blocks
promtool tsdb list /var/lib/prometheus/data
4. Prevent TSDB corruption
# prometheus.yml
storage:
tsdb:
# Retention settings
retention:
time: 15d
size: 50GB
# WAL compression reduces I/O
wal-compression: true
# Out-of-order ingestion can be disabled for stability
out-of-order-capability:
enabled: false
5. Monitor TSDB health
// TSDB health metrics
prometheus_tsdb_blocks_loaded
prometheus_tsdb_blocks_loaded{state="corrupted"}
prometheus_tsdb_reloads_failures_total
// Disk I/O issues
rate(node_disk_io_time_seconds_total[5m])
// Set an alert for block corruption
// Alert: TSDBBlockCorruption
// expr: prometheus_tsdb_blocks_loaded{state="corrupted"} > 0
Expected output:
Before repair: 421 blocks (1 corrupted)
After repair: 420 blocks (0 corrupted)
Data loss: 2 hours (single corrupted block)
TSDB loaded successfully
Prevention Tips
- Use reliable storage with checksumming (ZFS, Btrfs, or EBS)
- Monitor
<a href="/devops/prometheus-grafana/">Prometheus</a>_tsdb_blocks_loadedfor corruption - Set up remote write for data redundancy
- Run
promtool tsdb analyzein cron for early detection - Ensure clean shutdown of Prometheus
Common Mistakes with tsdb corrupt
- Mixing let bindings with <- bindings in do notation, producing type errors
- Overlapping type class instances that cause GHC to reject the program with ambiguous dispatch errors
- Non-exhaustive pattern matches that compile with warnings then crash at runtime
These mistakes appear frequently in real-world PROMETHEUS code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.
Practice Exercise
Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.
This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.
FAQ
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro