Prompt
How do I ingest Prometheus metrics into a database for long-term storage?
Latest observation
To store Prometheus metrics long-term, the usual pattern is not to write directly from Prometheus into a database, but to use Prometheus’s remote write or federation mechanisms, or to place a compatible long-term storage layer behind it.
Common options
1) Use a remote storage backend
Prometheus can remote_write samples to systems designed for long-term metrics storage, such as:
- Thanos
- Cortex / Grafana Mimir
- VictoriaMetrics
- InfluxDB (via integration)
- TimescaleDB/PostgreSQL via exporters or custom pipelines
- ClickHouse via ingestion tools/connectors
This is usually the best approach if you want:
- long retention
- horizontal scaling
- fast querying
- PromQL compatibility (for some backends)
How it works
- Prometheus scrapes metrics as usual.
- Prometheus
remote_writes samples to the backend. - The backend stores data long term and serves queries.
Prometheus config example
remote_write:
- url: "http://your-backend/api/v1/write"
2) Use Thanos / Mimir / Cortex with object storage
If you want “Prometheus-like” long-term storage at scale, these are popular.
- Thanos: adds long-term storage using S3/GCS/Azure Blob
- Mimir/Cortex: multi-tenant, scalable Prometheus backend
- VictoriaMetrics: simpler to operate for many use cases
This is the most common production choice.
3) Export to a relational or analytics database
If you specifically want a “database” like PostgreSQL, TimescaleDB, or ClickHouse, typically you do one of these:
- Use a Prometheus remote_write receiver or bridge
- Run a collector/ETL that reads from Prometheus or remote_write stream and inserts into the DB
- Use a purpose-built connector
This is less common than using a metrics backend, but useful if you need SQL queries or join with other business data.
4) Federation for aggregation, not long-term raw storage
Prometheus federation lets one Prometheus scrape metrics from another. This is useful for:
- consolidating metrics
- reducing cardinality
- centralizing a subset of metrics
But federation alone is not ideal for long-term archival.
Recommended choices by goal
- Best general-purpose long-term Prometheus storage: Thanos / Mimir / VictoriaMetrics
- Need SQL and analytics: ClickHouse or TimescaleDB with an ingestion path
- Small setup, simple retention extension: VictoriaMetrics
- Kubernetes-heavy environment: Thanos or Mimir
Important considerations
Cardinality
Prometheus metrics can explode in storage if labels are high-cardinality. Before sending to long-term storage:
- remove unnecessary labels
- avoid unbounded labels like user IDs, request IDs
- record rules for aggregation
Retention
Prometheus local TSDB retention is limited. Long-term storage is for:
- months to years of data
- centralized querying
- backups and durability
Query compatibility
If you want to keep using PromQL, choose a backend that supports it well:
- Thanos
- Mimir/Cortex
- VictoriaMetrics
Practical path
If you want a straightforward production setup:
- Keep Prometheus for scraping
- Configure
remote_write - Send to Thanos or VictoriaMetrics
- Store long-term data in object storage or the backend’s native storage
- Query through Grafana
If you tell me which database you mean specifically — for example PostgreSQL, ClickHouse, TimescaleDB, InfluxDB, or S3/object storage — I can give you a concrete setup and config example.