InfluxDB: Clear old records

I have searched for this and i am astonished to not find it

The question is simple : how to clear the influxdb openhab for all the records for all the items older than one year

Thanks in Advance

I think you need a retention policy for this:

1 Like

You can use the command line of influx. Go into influx, set the database with the ‘use’ command (login if needed), then you can use select and delete as desired. Example below where I delete where time is equal to a value, but you can use less than. These are in the unix epoch time format (many converters available online), but there may be a way to do this with other time formats.

See influx documentation.

> delete from OUTDOOR_TEMPERATURE where time = 1570960095541000000

There is an example of almost exactly what you want on the doc page above:

Delete all data in the database that occur before January 01, 2016:

> DELETE WHERE time < '2016-01-01'

Thanks but it do not work

DELETE WHERE time< ‘2016-01-01’ -database=“openhab_db”

do the command in 2 separate lines. I.e., try this:

> use openhab_db
> DELETE WHERE time < '2016-01-01'

Note that this will be from the default retention policy. If you have more than one that you use, you’ll need to select the one you want.

By the way, the command above will delete prior to January 1, 2016. You probably want to change it to a more recent date. One year ago is ‘2018-12-24’.

1 Like

just for others that will read this. I had to use this commands:

the information can be found here