Vibe monitoring with Last9 MCP: Ask your agent to fix production issues! Setup →
Last9 Last9

How to Configure and Optimize Prometheus Data Retention

Learn how to set Prometheus retention limits, avoid storage bloat, and keep the metrics that matter for your systems.

Jun 5th, ‘25
How to Configure and Optimize Prometheus Data Retention
See How Last9 Works

Unified observability for all your telemetry.Open standards. Simple pricing.

Talk to us

Prometheus can be lightweight to start with, but once it’s in production, storage usage tends to grow faster than expected. Managing how long data is kept becomes critical, especially when you're working with limited disk space or tight budgets.

This guide outlines the key concepts behind Prometheus data retention, how to configure it effectively, and what to watch out for. Whether you're setting it up for the first time or trying to optimize an existing setup, this will help you strike the right balance between storage constraints and observability goals.

Why Extend Prometheus Data Retention?

Here are a few practical reasons to consider longer retention periods:

  • Trend Analysis Over Time
    Retaining historical metrics helps track gradual performance changes and supports long-term capacity planning.
  • Regulatory and Audit Requirements
    Some environments—especially in finance, healthcare, or government—require metric data to be stored for extended periods to meet compliance standards.
  • Deeper Incident Investigations
    Not all issues show up immediately. Extended retention allows teams to review older patterns when debugging problems that evolve slowly.
  • More Informed Infrastructure Planning
    Long-term data gives better visibility into usage trends, making scaling decisions less reactive and more data-driven.
  • Understanding Seasonal Behavior
    Year-over-year patterns like holiday traffic spikes or quarterly usage drops are only visible if you retain enough historical data to compare.
💡
For tips on understanding and tracking CPU-related metrics in Prometheus, check out our guide on monitoring CPU usage.

How Prometheus Stores Data

Prometheus uses a purpose-built time-series database optimized for high-throughput metric ingestion and efficient querying. The storage engine organizes data into immutable blocks on disk, each typically covering two hours of time-series data.

Block Structure

Each block contains:

  • Metric samples – Time-stamped values for each series.
  • Index files – Allowing fast lookup of time series by label matchers during queries.
  • Metadata – Includes block-specific information such as time range, series schema, and integrity checksums.

New data is initially written to memory and the write-ahead log (WAL), ensuring durability in case of crash or restart. Every two hours, the in-memory data is persisted into a new block, and the WAL is truncated accordingly.

Over time, Prometheus automatically compacts older blocks into larger blocks—first 10-hour blocks, then daily blocks, and beyond—reducing query overhead and storage fragmentation.

Data Retention and Cleanup

Retention in Prometheus is managed via the --storage.tsdb.retention.time flag. This defines how long on-disk blocks should be kept. Prometheus does not delete individual samples—it deletes entire blocks once their data falls completely outside the retention window.

For example, if retention is set to 7 days and a block spans time from day 6 to day 8, that block won’t be removed until all of its contents are beyond the 7-day mark. As a result, actual storage usage may slightly exceed the configured retention period.

On-Disk Layout

Prometheus stores its data in the data/ directory, structured as follows:

data/
├── 01BKGV7JBM69T2G1BGBGM6KB12/   # Individual time block
├── 01BKGTZQ1SYQJTR4PB43C8PD98/   # Another block
├── chunks_head/                 # In-memory head chunks
└── wal/                         # Write-ahead log
  • Each alphanumeric directory under data/ is a block directory representing a specific time range.
  • chunks_head/ stores recent in-memory data not yet persisted into a block.
  • wal/ contains recent writes for crash recovery and durability guarantees.

Understanding this storage model is essential when tuning Prometheus for performance, planning disk capacity, or configuring backup and retention policies.

💡
For a deeper understanding of how to query multiple metrics in Prometheus, refer to our detailed guide on querying multiple metrics in Prometheus.

How to Check Your Current Prometheus Retention Settings

Before adjusting retention, make sure you know what’s already in place. Here’s how to check:

1. Check via the Web UI

  • Go to your Prometheus instance in the browser.
  • Navigate to StatusRuntime & Build Information.
  • Look for the storageRetention field—it shows the current retention period.

2. Use the API

Run this command to fetch the retention setting programmatically:

curl -s http://localhost:9090/api/v1/status/runtimeinfo | jq '.data.storageRetention'

This is useful for automation or checking multiple environments.

3. Inspect the Configuration

Look for the retention flag in how Prometheus is started:

In a Kubernetes manifest:

args:
  - "--storage.tsdb.retention.time=30d"

In a Docker command:

docker run prom/prometheus --storage.tsdb.retention.time=30d

In a systemd unit file:

ExecStart=/usr/local/bin/prometheus --storage.tsdb.retention.time=30d ...

If the flag isn’t set, Prometheus defaults to 15 days of retention.

Tip: Always check the active configuration before making changes—it avoids surprises and helps catch drift between environments.
💡
For a comprehensive overview of transforming Prometheus into an Application Performance Monitoring (APM) tool, explore our article on How to Use Prometheus for APM.

How to Configure Data Retention in Prometheus

Prometheus allows you to control how long metrics are stored using time-based and size-based retention settings. Both are set via command-line flags when launching Prometheus. You can use them independently or together, depending on whether you're optimizing for duration, disk space, or both.

Set a Time Limit on Stored Metrics (--storage.tsdb.retention.time)

Use this setting when you want to keep data for a specific number of days, weeks, or months, regardless of disk usage.

Example:

prometheus --storage.tsdb.retention.time=30d

Supported units:

  • d for days (e.g., 30d)
  • w for weeks (e.g., 4w)
  • h for hours (e.g., 720h)
  • m for minutes (e.g., 43200m)
  • y for years (e.g., 1y)

This approach works well when your priority is consistent historical visibility—e.g., always keeping the last 30 days of data.

Where to set it: This flag should be added to your Prometheus startup command—whether in a systemd service, Docker container, or Kubernetes manifest.

Limit Total Storage Usage (--storage.tsdb.retention.size)

Use this flag when your storage capacity is fixed and you need to keep disk usage under control.

Example:

prometheus --storage.tsdb.retention.size=100GB

Prometheus will start deleting the oldest blocks first once usage crosses the specified threshold. It will always preserve the most recent data.

This is ideal when running on smaller volumes (e.g., embedded systems, edge nodes, or constrained environments) where disk usage must stay within strict limits.

Combine Time and Size-Based Retention (Best for Production)

For most production setups, combining both retention strategies is recommended. This provides a safeguard in both directions, ensuring you don’t run out of disk space or keep stale data longer than needed.

Example:

prometheus \
  --storage.tsdb.retention.time=30d \
  --storage.tsdb.retention.size=50GB

Prometheus will delete old data when either:

  • The retention time exceeds 30 days, or
  • The storage used crosses 50GB
Important: Prometheus doesn’t delete individual samples—it deletes full 2-hour blocks. This means retention is approximate. You might see slightly more data than expected, depending on block alignment.
💡
Explore practical tips and shortcuts to get more from your PromQL queries in our guide: 21 PromQL Tricks You Should Know.

Step-by-Step Guide to Configure Prometheus Retention

Prometheus retention controls how long your monitoring data stays on disk before being deleted. Setting this right balances keeping enough history for analysis with managing disk space.

Here’s how to configure it based on your environment.

1. Linux Systems (systemd)

Most Linux systems use systemd to manage services like Prometheus. To configure retention here:

  1. Locate the ExecStart line. This is the actual command that launches Prometheus. You’ll add the retention flag here.

Confirm it’s running properly:

sudo systemctl status prometheus

Make sure Prometheus restarted without errors.

Restart Prometheus to apply the new retention setting:

sudo systemctl restart prometheus

Save your changes and reload systemd so it picks up the new config:

sudo systemctl daemon-reload

This refreshes systemd’s view of your service files.

Example snippet:

[Service]
ExecStart=/usr/local/bin/prometheus \
  --config.file=/etc/prometheus/prometheus.yml \
  --storage.tsdb.path=/var/lib/prometheus/ \
  --storage.tsdb.retention.time=60d

Add or update the retention flag:

--storage.tsdb.retention.time=60d

This example sets retention to 60 days, meaning Prometheus will keep data up to 60 days old before deleting it.

Open the Prometheus service file where the startup command is defined:

sudo vi /etc/systemd/system/prometheus.service

This file tells systemd how to start Prometheus.

2. macOS (Homebrew)

If you installed Prometheus via Homebrew, you’ll typically run it manually or via a script:

  1. Note: This runs Prometheus manually in the foreground. For continuous operation, consider setting up a launch agent or background service with this command.

Start Prometheus with the retention flag included:

/opt/homebrew/opt/prometheus/bin/prometheus \
  --config.file=/opt/homebrew/etc/prometheus.yml \
  --storage.tsdb.retention.time=30d

This tells Prometheus to keep data for 30 days.

Find your config file location:

ls /opt/homebrew/etc/prometheus.yml

This shows where your Prometheus config lives.

3. Docker Deployments

Prometheus often runs in containers. Here’s how to configure retention there:

Option A: Using docker-compose.yml

Restart the stack to apply changes:

docker-compose down
docker-compose up -d

Edit your docker-compose.yml file to add the retention flag under the command section:

services:
  prometheus:
    image: prom/prometheus:v2.37.0
    command:
      - '--config.file=/etc/prometheus/prometheus.yml'
      - '--storage.tsdb.path=/prometheus'
      - '--storage.tsdb.retention.time=30d'
    volumes:
      - ./prometheus.yml:/etc/prometheus/prometheus.yml
      - prometheus_data:/prometheus

The retention flag here means Prometheus inside the container will keep data for 30 days.

Option B: Using docker run

  1. This command:
    • Maps your local config file into the container.
    • Maps a volume to persist metric data.
    • Sets retention to 30 days.

Run Prometheus with the retention flag directly:

docker run -d \
  -p 9090:9090 \
  -v /path/to/prometheus.yml:/etc/prometheus/prometheus.yml \
  -v prometheus-data:/prometheus \
  prom/prometheus:latest \
  --config.file=/etc/prometheus/prometheus.yml \
  --storage.tsdb.path=/prometheus \
  --storage.tsdb.retention.time=30d

Final Checks

After you’ve set retention:

  • Verify Prometheus is running without errors.
  • Use the UI or API to confirm retention settings.
  • Monitor disk usage and query performance over time to fine-tune your configuration.
💡
If you're looking to enhance your Prometheus queries, our guide on Prometheus Functions offers practical insights.

Common Prometheus Retention Scenarios and How to Choose

Different environments and use cases call for different retention strategies.

Retention Recommendations by Environment

Here’s a quick overview of typical retention settings tailored for common environments:

Environment Retention Time Storage Limit Primary Use Case
Development 3 to 7 days ~10GB Quick debugging and feature testing
Staging ~14 days ~25GB Integration testing and deployment validation
Production 30 to 60 days 100GB+ Incident response, capacity planning, trends
Compliance 1 year or more (external storage likely) Varies Regulatory auditing and long-term analysis

Development Environment: Keep It Short and Sweet

Retention time around 3 days is usually enough here. The goal is to catch recent behavior without accumulating data that you won’t analyze. Storage limits tend to be low since the focus is on speed and convenience rather than long-term visibility.

Production Environment: Balance History with Storage

For production, retention is typically set between 30 to 60 days. This allows for meaningful incident investigations, spotting slow trends, and planning capacity. Storage requirements grow accordingly, often 100GB or more, depending on traffic and metric volume.

Compliance Requirements: Plan for Long-Term Storage

Industries with strict regulations—finance, healthcare, etc.—may require data retention for months or even years. In these cases, Prometheus might not be the only storage system. Often, data is exported or archived to dedicated long-term storage systems for audit and compliance purposes.

How to Monitor Your Prometheus Retention Setup

Setting retention isn’t “set it and forget it.” Monitoring key Prometheus metrics helps you ensure your retention policies are working as expected and your system stays healthy.

Key Metrics to Watch

  • Storage Usage
    • prometheus_tsdb_symbol_table_size_bytes: Tracks memory used for series symbol tables.
    • prometheus_tsdb_head_series: Number of active time series in memory.
  • Block Management
    • prometheus_tsdb_blocks_loaded: Count of data blocks currently loaded.
    • prometheus_tsdb_compactions_total: Total number of block compactions performed.
  • Query Performance
    • prometheus_engine_query_duration_seconds: How long queries take to run.

What to Do If You Notice Problems

  • If disk usage keeps growing beyond expectations, double-check your retention settings and whether Prometheus can delete old blocks properly.
  • If query performance slows down, this could be due to too much data or very high cardinality metrics. Consider reducing retention time or optimizing your metrics.
  • Keep an eye on block compactions if they happen too frequently; they might impact Prometheus performance, indicating a need to adjust retention or block size.
💡
To enhance your understanding of querying multiple metrics in Prometheus, explore our guide on querying multiple metrics in Prometheus.

Advanced Retention Management Techniques in Prometheus

Managing retention doesn’t have to be a blunt “keep or delete” choice. There are smarter ways to stretch your storage and keep important data longer without overwhelming your system.

Conditional Cleanup with Recording Rules

Prometheus lets you control data retention more selectively by using recording rules. Instead of keeping all raw metrics for the same duration, you can:

  • Preserve important summaries or aggregates longer
  • Allow high-detail raw data to expire sooner

For example, create a recording rule that calculates a 24-hour average uptime metric. This aggregated metric can be kept for weeks or months, while raw data is kept only for days.

groups:
  - name: long_term_metrics
    interval: 5m
    rules:
      - record: service:availability_24h
        expr: avg_over_time(up[24h])

This approach saves storage by replacing detailed raw data with compact, meaningful summaries for long-term analysis.

Multi-Tier Storage Strategy

Handling retention across different "tiers" of storage can balance cost and detail:

  • Hot Storage: Keep full-resolution data for recent days (e.g., 7 days) to support detailed troubleshooting and real-time monitoring.
  • Warm Storage: Store downsampled or aggregated data for a longer period (e.g., 30 days) to track medium-term trends without using excessive space.
  • Cold Storage: Archive long-term aggregated metrics or snapshots externally, useful for compliance or yearly analysis.

Prometheus itself doesn’t natively manage multi-tier storage, but you can implement this by combining retention policies with external tools that handle data downsampling and archiving.

External Backup for Critical Metrics

If certain metrics are vital for audits or historical analysis, export them before Prometheus deletes the raw data. Use promtool or other export utilities to back up data in JSON or other formats.

Example command to export data within a time range:

promtool query range \
  --start=2023-01-01T00:00:00Z \
  --end=2023-01-02T00:00:00Z \
  'up' > backup.json

Make backing up part of your regular retention workflow to avoid losing important historical insights.

💡
Fix Prometheus related production issues instantly right from your IDE, with Last9 MCP. Bring real-time production context—logs, metrics, and traces—into your local environment to debug and resolve problems faster.

Troubleshooting Common Prometheus Retention Issues

Even with careful configuration, retention settings can lead to some common problems. Here’s how to identify and fix them quickly.

1. Insufficient Disk Space Causes Prometheus to Stop or Fail to Start

Symptoms:

  • Prometheus stops ingesting new data
  • Prometheus fails to start or crashes unexpectedly

What to do:

  • Add more disk space: Increase your storage capacity if possible.
  • Reduce retention period temporarily: Lower retention time to free up space while investigating.
  • Enable or verify compression: Prometheus compresses data blocks by default—make sure this is working correctly.
  • Clean up corrupted WAL files: If write-ahead logs are corrupted, delete old WAL files cautiously after stopping Prometheus to avoid startup issues.

2. Data Inconsistencies — Missing Data or Query Errors

Symptoms:

  • Gaps or missing metrics in your dashboards
  • Errors when querying data

What to do:

  • Check Prometheus logs: Look for corruption warnings or errors during startup or runtime.
  • Restart with a clean storage directory: If corruption is suspected, stop Prometheus and clear the storage directory (backup first!).
  • Verify filesystem health: Run disk checks to ensure there are no underlying filesystem problems causing data loss.

3. Increased Query Latency Affecting Dashboard Performance

Symptoms:

  • Slow-loading dashboards
  • Query timeouts or delays

What to do:

  • Optimize queries: Use recording rules to pre-aggregate common queries and reduce load.
  • Limit query time ranges: Shorter time windows mean faster results.
  • Consider query result caching: Cache frequent queries to speed up repeated access.
  • Monitor system resources: Keep an eye on CPU, memory, and disk I/O. High usage may require tuning retention or scaling resources.

4. Prometheus Fails to Start After Changing Retention Settings

Symptoms:

  • Prometheus won’t start or crash immediately after config changes

What to do:

  • Check service logs: Use sudo journalctl -u prometheus -f to view detailed startup errors.
  • Validate configuration syntax: Make sure flags and settings are correctly formatted.
  • Verify storage directory permissions: Ensure Prometheus user has read/write access to its data directories.
  • Look for conflicting flags: Check that no other retention flags or settings conflict with your changes in service files or startup scripts.

Retention-related issues often boil down to disk space, data integrity, query load, or configuration errors.

Conclusion

Prometheus retention shapes how you store, query, and act on data. Time and size limits are just the starting point; what matters is keeping what’s useful and dropping what’s not.

At scale, this becomes harder to manage, and Last9 supports this by handling high-volume metrics, applying sensible retention defaults, and highlighting what’s relevant, without adding config overhead or hidden costs. Using Prometheus’s remote_write we forward metrics to Last9’s backend for efficient, long-term storage.

Get started with us today, and take control of your Prometheus retention strategy.

FAQs

How do I check the current retention settings?
Check the Prometheus web UI under Status > Runtime & Build Information, or look at the command-line flags used to start your instance.

Can I change retention without restarting?
No, retention settings require a restart. Plan changes during maintenance windows.

What happens if I reduce retention time?
Prometheus immediately starts cleaning up data older than the new period. This can't be undone, so backup important data first.

How much storage does Prometheus typically use?
Roughly 1-2 bytes per sample, but high-cardinality metrics can increase this significantly. Monitor your actual usage patterns.

Time-based or size-based retention?
Time-based is more predictable for operations. Size-based works better with strict storage limits but variable data volumes.

Can I have different retention for different metrics?
Not directly. Prometheus applies retention globally. Use recording rules to preserve important aggregations while letting detailed metrics expire.

Authors
Preeti Dewani

Preeti Dewani

Technical Product Manager at Last9

X

Contents

Do More with Less

Unlock high cardinality monitoring for your teams.