Servers

Prometheus: nightly TSDB compaction windows cause Grafana queries to time out and remote_write backlog growth

Environment

Environment

Prometheus 2.33.1 on a single node VM (12 cores, 64 GB RAM) with NVMe SSD, scraping 3k targets and receiving bursts from batch jobs ~50k samples/s for ~1 hour nightly. Remote_write configured to push to a Cortex cluster over a 1 Gbps link. Retention 30d.

Symptoms

Symptoms

Between 02:00–03:00 during nightly load spikes, Grafana dashboards time out or return partial results. Prometheus UI shows slow response and occasional 500 errors. promtool and logs show prolonged compaction and WAL GC activity. Remote_write queue length and latency increase; memory and CPU spike; alerts are missed.

Observations

Observations

Prometheus logs report 'tsdb: compacting' and 'WAL segment' churn; compaction duration grows with the ingest burst; WAL tail grows and remote_write backpressure increases. Rebooting Prometheus during the window made the outage longer. Tuning wal-compression helped CPU but compactions still cause query latency.

Already attempted

Already attempted

Moved storage to faster NVMe, enabled wal-compression, adjusted scrape and ingestion rates where possible. Tried increasing --storage.tsdb.min-block-duration to 2h which reduced frequency but didn’t eliminate long compactions. Considered sharding Prometheus but need time to validate.

Question

Question

How to reduce query impact during compactions and handle the remote_write backlog without data loss? What are safe configuration changes to avoid query timeouts during nightly ingest spikes?

COMMUNITY RESPONSES

Verified community troubleshooting

1 reply
0
nordicbyte Answer
user
Posted 1mo ago • 0 confirmations

Compaction spikes come from lots of small blocks and an overloaded remote_write path. Short-term: increase --storage.tsdb.min-block-duration (try 2h) to reduce how often compaction runs, and throttle remote_write (smaller batches / lower concurrency) so WAL doesn't pile up. Verify by watching Prometheus logs and query latency during the next window. Medium-term: split ingestion (multiple Prometheus shards) or add Thanos/Cortex to handle queries off the TSDB while compaction runs. Revert flags if query shape worsens; architecture changes are the real fix.

Showing 1 of 1 community responses
AI DIAGNOSTICS

Incident analysis

Updated 1mo ago• Trouble ID

Most likely causes

High ingest spike producing many small TSDB blocks and tombstones, triggering heavy compaction work 85%
Remote_write throughput insufficient, causing WAL to grow and compaction pressure 70%
Disk IO bottleneck (even NVMe saturated under write pattern) slowing compaction 60%

Summary

Compaction is IO/CPU intensive; massive short-lived ingest produces many small TSDB blocks and tombstones, which triggers expensive compaction work. Remote_write backpressure increases WAL retention, making compaction and memory use worse. Short-term mitigations: increase min-block-duration to reduce compaction frequency, raise WAL/compression settings, and throttle remote_write concurrency/throughput. Medium/long-term: scale by sharding ingestion (multiple Prometheus servers), deploy a remote read/long-term store (Thanos/Cortex) to offload queries, or introduce a write buffer tier that absorbs bursts. Reboots during compaction increase unavailability and risk data loss—prefer configuration changes or horizontal scaling.

Suggested Fixes

Diagnostic step 1
Enable or increase --storage.tsdb.min-block-duration (e.g., to 2h) to lower compaction frequency and test impact on query latency.
Diagnostic step 2
Tune remote_write concurrency and batch size (reduce in-flight requests) to avoid WAL backlog; monitor queue_length.
Diagnostic step 3
Offload reads: deploy a Thanos sidecar or Cortex read path so queries hit a read replica during compaction.