Database disk image is malformed

About a month ago I moved my Home Assistant to an Intel NUC. (Native in a docker container on Ubuntu). With some help, I got everything running. It looks great.

So, since everything appears to be working, I had no reason to look at the log files. But, today I did, and was surprised to see this:

“Error adding event: (sqlite3.DatabaseError) database disk image is malformed…message first occurred at April 2, 2020… and shows up 34079 times”

Is the fix as simple as just to delete home-assistant_v2.db from the config directory and restart HA?

Yes, that is the fix.

Thanks. My limited experience with mysql told me that I don’t want to try to repair the database.

If you don’t mind lost every history data, just delete it. But if you want save as much as you can, do this
stop HA
cd ~/config
sqlite3 home-assistant_v2.db ".dump" | sed 's/ROLLBACK;/COMMIT;/g' > dump.sql
tail dump.sql
# **check last line, it should begin with COMMIT;**
sqlite3 home-assistant_v2.db.fix < dump.sql
mv home-assistant_v2.db home-assistant_v2.db.broken
mv home-assistant_v2.db.fix home-assistant_v2.db
ha core start

1 Like