After 2024.7.x I noticed every morning around 4am my recorder stop recording. I also noticed my database start bloating out to 13GB. I eventually ran out of disk space, and needed to extend the disk. This was not a sustainable solution.
I have spent weeks researching, and eventually I found the issue. Initially I suspected the 2024.7 release had an issue with recorded, but I believe the issue actually stems much further back than that. There was a big SQL change around 6 months prior, and I believe that process failed. Then in 2024.7 an enhancement was made to SQL, and the 2 issues together have destroyed any ability for recorded or normal delete/vaccum commands to work.
When trying to manually clean up the database (manually purge and vacuum) I was having key errors, which made no sense.
I started to suspect I had massive data issues, and I was going to be rolling back months to an old update. Pretty much with nothing to lose, I started getting quite aggressive with the DB clean up.
One thing I did do, is fire up a fresh and current install of HA, as mine is 3+ years old. Immediately, I noticed foreign keys in the Event and State tables, that were not present in my production DB. Also a bunch of index’s missing.
Another tell tale of a failed SQL update in the past, is multiple State_Temp tables, empty. So I believe in the past, HA has attempted to rebuild tables, ran out of disk space and bombed out. Then as the tables were as expected, the 2024.7 update has now introduced a failure.
How I fixed it:
0. Rebooted Production HA after allocated more CPU and RAM (from 1 CPU and 2Gb Ram to 4 CPU and 12GB Ram). I noticed that it exceeded 6gb RAM usage.
0.5 You will need plenty of disk space. 150-200% of your current DB size in spare space. May need to add another data disk and perform a data disk move.
- Got a fresh copy of HA
- Grabbed the SQL Table structure for all tables, and compared against my current install. (use SQLite Web)
- Identified that Event and State tables both missing foreign keys, index’s. Also, a few columns have been removed from the new DB, that were still in my production.
- Stopped Recorder.
- Disabled Foreign Keys in DB
- Dropped the existing Index’s on State and Entity (helps with speed of the next few steps)
- Renamed tables States to States_old and entity to entity_old
- created tables again from the CREATE template given in brand new HA SQLite
8.5 removed unused columns (Event had Created and states had domain and created, all 3 columns removed) - inserted states_old to States and same with entity. This took 4 hours.
- recreated index from new HA SQL, one at a time. Each index took 10-30 mins.
- Ran recorder.purge (this took 6 hours) with repack.
- Recorder ran!!! and reduced by DB from 14gb to 2Gb.
- Re-enabled Foreign Keys
- reboot.
Good luck, this took me 3-4 weeks of research and about 3 days to repair once I had worked it out.