sqlinfluxdbdata-consistencyretention

InfluxDB : How to update duration of an existing database


I have a database created with default retention policy which is infinite.

# SHOW RETENTION POLICIES ON "my_database" name duration shardGroupDuration replicaN default ---- -------- ------------------ -------- ------- autogen 0s 168h0m0s 1 true

How I can modify the retention-policy of the live database so that from now it keeps data only for last 10 days?


Solution

  • Easiest solution is to change(update) the current retention-policy.

    ALTER RETENTION POLICY "autogen" ON "my_database" DURATION 10d

    Now, after a while (ranging from 30m to 1h or more), InfluxDB will reflect the new retention-policy and trim the database off the data older than the specified 10 days.

    Another approach can be to create and employ a new retention policy. Check the doc for more: https://docs.influxdata.com/influxdb/v1.2/query_language/spec/#alter-retention-policy