6

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?

kmonsoor
  • 7,600
  • 7
  • 41
  • 55

1 Answers1

19

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

kmonsoor
  • 7,600
  • 7
  • 41
  • 55
  • Would this change duration of retention policy "autogen" if it is used on other databases? Because if you have "autogen" on all databases, would that impact others? – user3292147 Sep 11 '20 at 13:53
  • it is a per database setting so it wont impact other databases. – clonerworks Nov 06 '20 at 02:18
  • does that remove the existing data injected into db that before you alter the policy? – Zhongmin Jan 23 '23 at 22:40
  • @Zhongmin if the new retention limit is less than the old one, then yes. The data for the extra days will be deleted, but its not instantly. – kmonsoor Jan 25 '23 at 02:16