Prompt
How do I set up retention policies in a time-series database?
Latest observation
Retention policies in a time-series database control how long data is kept before it is automatically deleted or downsampled. The exact setup depends on the database, but the general process is similar.
Basic steps
-
Decide your retention requirements
- Raw high-resolution data: keep for days/weeks/months
- Aggregated/downsampled data: keep for months/years
- Compliance or audit data: keep longer if needed
-
Choose the retention strategy
- Delete old data automatically after a fixed period
- Downsample older data into lower-resolution summaries
- Tiered retention: keep recent raw data, older aggregated data
-
Configure the policy in your database
- Some databases support native retention policies
- Others use:
- TTL on measurements/tables
- partition expiration
- scheduled jobs/cron
- lifecycle rules
-
Apply the policy to the right data
- Per database
- Per measurement/measurement group
- Per table/series
- Per tenant or namespace
-
Verify deletion/aggregation is working
- Check old partitions are removed
- Ensure queries still return expected historical data
- Monitor storage usage
Common examples
InfluxDB
Older versions use retention policies directly:
CREATE RETENTION POLICY "30_days" ON "metrics_db"
DURATION 30d REPLICATION 1 DEFAULT
TimescaleDB
Use retention policies on hypertable chunks, often with drop_chunks() or automation:
SELECT add_retention_policy('metrics', INTERVAL '30 days');
Prometheus
Retention is usually configured via startup flags:
--storage.tsdb.retention.time=30d
Cassandra-based TSDBs / general systems
Often implemented with TTL:
INSERT INTO metrics (...) VALUES (...) USING TTL 2592000;
Best practices
- Keep raw data only as long as needed
- Downsample before deleting raw data if long-term trends matter
- Set retention based on business needs, not just storage limits
- Test on a small dataset first
- Make sure backups are aligned with retention rules
- Consider time-based partitioning for efficient deletion
Things to watch out for
- Deleting data too early can break dashboards or alerts
- Retention may not apply to derived data unless configured separately
- Large deletions can affect performance if not chunked/partitioned
- Some systems require background jobs to enforce retention
If you tell me which time-series database you’re using (for example InfluxDB, TimescaleDB, Prometheus, QuestDB, etc.), I can give you exact setup commands and recommended settings.