This seems to be a bit of a recurring theme. I’ve read multiple posts by may people, over several years with the same issue. My over-riding thought is: surely there as got to be a better answer than repeatedly deleting the database. These are my findings. I haven’t got 100% to the bottom of it, but I am a lot happier and I hope others find this useful.
I have HA 0.96.5. It’s running on an old, but very competent laptop. I rarely see CPU usage above about 5%, never seem memory usage over 50% and the hard drive is almost empty.
When the home-assistant_v2.db file reaches about 2Gb, updates to my tabs get very slow. It can take 10 seconds to refresh. I have only about 20 sensors, on 5 minute updates.
I can fix the problem by shutting down HA, deleting the DB and running it again. It runs sweet for a couple of weeks, then starts, again, to grind.
I would like to maintain 14 days history, so I have
recorder:
purge_interval: 2
purge_keep_days: 14
exclude:
domains:
- automation
- weblink
- updater
- light
- script
entities:
- sun.sun # Don't record sun data
This morning, I ran recorder.purge with {“keep_days”:“14”, “repack”:“true”}. My understanding is that rather than trying to remove entries, repack creates a fresh file, then deletes the old database, replacing it with the new. Sure enough, I spot home-assistant_v2.db-wal ramping up in size until about 4Gb, then going back to zero.
So, I considered that 4Gb must simply be the size for 14 days worth of data for my sensors. That irked me, because it’s just too slow to refresh the display. So, I figured I have to bite the bullet and set
recorder:
purge_interval: 1
purge_keep_days: 7
and I re-tried recorder.purge with {“keep_days”:“7”, “repack”:“true”}.
Well, the results surprised me. The DB file is now 3.5Mb, and I’ve only lost 1 week’s worth of readings. Better than deleting the database!
So, conclusions?
- I’m still a bit confused as to how my original purge yielded up a 4Gb data file with 2 weeks worth of data, when 2 weeks of data appears to only occupy 3.5Mb.
- Is it possible that purge_keep_days in the configuration over-rides keep-days when executing the purge?
- Is it possible that the initial purge to 14 days did actually work, but i wasn’t patient enough to wait for the file size to drop?
I’ll keep an eye on my file size and report back, but for now I’m putting the purge_keep_days back to 14.
Keep up the good work, folks.