I started with these 2 tutorials:
https://dummylabs.com/post/2019-01-13-influxdb-part1/
https://dummylabs.com/posts/2019-05-28-influxdb-part2/
(Found them somewhere here in a post)
To clean up your database is not a short way, i had a look in every measurement what entities are stored and which one i really needed. In the last years i had a include all and exclude some sensors, this approach is really bad if you want to store your data for a long time.
To look into your database you can for example see what entities are stored in one measurement with:
select * from homeassistant.autogen."%" where time > '2022-04-22' and time < '2022-04-24'
Paste this into explore the influxdb addon. Then you see all entities that are stored yesterday with the “%” measurement.
To look what measurements you have use SHOW MEASUREMENTS
into the explore query.
A similar query for °C would be:
select * from homeassistant.autogen."°C" where time > '2022-04-22' and time < '2022-04-24'
When you have entities you want get rid off delete them. This was a bit tricky for me because the delete from did not work in explore in influxdb (i did not find the right syntax). So i logged into the container (see the dummylabs tutorial part 2)
ssh onto your host, execute:
user@host:~$ docker exec -it addon_a0d7b954_influxdb influx -precision rfc3339
Connected to http://localhost:8086 version 1.7.2
InfluxDB shell version: 1.7.2
Enter an InfluxQL query
and then
> auth
username: homeassistant
password:
> use homeassistant
Using database homeassistant
Then you can delete data with:
delete from "%" where entity_id = 'your_sensor'
So you have to go through every measurement, check what is stored and delete everything you don’t need. Don’t forget to change your influxdb config to only a include strategy of the sensors you really need.
To change how much data is stored i wrote a little tutorial which compresses data after 6 months and after 2 years in different retention policies to save space. For me cleaning up changed my db size from 4.5GB to around 350MB for 3 years of recording. For example i do not need the ink levels of a printer that left me before 2 years
Guidance enough?