Home-assistant_v2.db growing exponentially - Not sure why

Hello everyone, I have dealt with my home-assistant_v2.db growing before and correct with a 5 day purge of the db and not having it track some changes, but something is causing it to grow at a rapid rate and I am not sure why. Even loading the history tab in homeassistant will crash the webpage. Is there any way to easily find what is causing this? I am currently running Home Assistant on an Intel NUC using the NUC Image directly installed onto it. I have tried rebooting, etc, and even manually purging the DB using the recorder.purge service and keeping 0 days but this has no effect. Only thing that has resolved it is manually deleting it but then it obviously builds right back. I can actually see the file growing while looking at it on my Samba share from windows.

Thanks again and let me know what more information is needed.

image

if you have an sqlite Client available (like in the ssh & web terminal addon from frenck), you could query the database, to see what’s going on.

select count(*), event_type from events group by event_type order by count(*) desc;
select entity_id, count(*) from states group by entity_id order by count(*) desc limit 20;

But be aware: these queries are extremely inefficient, so they should be performed on a fairly small database. Mine is only around 100 MB and it takes a few seconds.

So my database file is littered with these. How would I track down what is causing all the state changes? I do not see any way to identify inside the database.

Think I may have answered my own question going through the logbook in HA. It appears the Ubiquiti Integration is tracking client uptimes and sending to the DB every second. Seems to not do it all the time though so I guess we will see if this works.

This doesn’t seem to be the result of the queries I posted. So there is not much I could tell you.

This does not seem to work anymore starting with HA Core 2023.4 where the new table states_meta has been introduced. How to adapt this statement so it works again?

Edit: found a working version, thanks to @jeedewee, see How to keep your recorder database size under control - #126 by jeedewee