Prometheus: nightly TSDB compaction windows cause Grafana queries to time out and remote_write backlog growth
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
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
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
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
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?
Verified community troubleshooting
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.