Home Assistant recorder database is never able to be created

Hi community,

I’ve been searching the forums and yet to find something to help.
In short, my SQLITE db is never able to be created. Every fresh restart, after clearing all corrupt .db files and the current .db file, always creates a new blank file and a bunch of corrupted ones.

The first error shown is
2024-12-23 13:23:01.282 ERROR (Recorder) [homeassistant.components.recorder.core] Error during connection setup: (retrying in 3 seconds)

Followed by the db is locked.
sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) database is locked

2024-12-23 13:23:04.349 ERROR (Recorder) [homeassistant.components.recorder.util] The database at //config/home-assistant_v2.db is corrupt or malformed

sqlite3.OperationalError: no such table: states

2024-12-23 13:23:04.353 ERROR (Recorder) [homeassistant.components.recorder.util] The system will rename the corrupt database file //config/home-assistant_v2.db to //config/home-assistant_v2.db.corrupt.2024-12-23T13:23:04.353189+00:00 in order to allow startup to proceed

I have no data currently to ingest into the db. I just need a blank fresh working db.

All the current guidance is to clear the files and fresh restart but this always results in the same log output errors. Is there something else I need to do to get this to work?

Any help would be greatly appreciated.

Thanks,
Rob

What kind of installation do you use? If HA in container - stop the HA container, delete db-files, start HA container.
Also, comment your “recorder” settings (if not default).
Also, start HA in a safe mode.

Yes its HA Core in container.

This is what I do each time. Stop HA, delete and start again.
My recorder settings are default.

I haven’t tried starting in safe mode.
I’ll try now and see if that helps.

Are you sure it has write permissions to the folder.

I’m pretty sure as I’m using a NAS shared folder and HA can write config changes to the directory ok. It creates the corrupted db files in there too.

Restarting in safe mode produces the same result unfortunately.

Just in case - check if the HDD is not corrupted.

Thank you for the continued help!

My NAS is not reporting any corruption and managing files from HA and other sources that access it seem to be ok from what I can tell.

I would try re-installing HA ))))
(using HA in docker myself, see no sense to use HA core honestly, but this is beyond the topic)

May I ask what image you are using please.
I’m on this one
https://hub.docker.com/r/homeassistant/home-assistant 2024.12.

I thought container and core were the same to be honest.

sudo docker pull homeassistant/home-assistant:stable

This image is also giving me the same issue. :slightly_frowning_face:

Does anyone know if there is a default schema somewhere I can try putting in.

Grasping at straws but might it be that you have accessed the db from another tool and that one is still running? What docker command did you run to create the lot. As @Ildar_Gabdullin says, delete all config and restart?

Erm, I did not suggest to “delete all config & restart”, I finally suggested to reinstall HA ))). (of course with keeping the config except *.db)

I wouldn’t delete the config but I would create another folder and create/run a defaulted HA container.

Verify that works

Stop it and move your config over minus db or restore a backup

Doing this might help point out the issue or completely fix it

Also. How are you running db? Is it standard db or you run seperate container/service?

I am under the assumption that, since it is the OP’s first post, that there is nothing to be saved and starting 100% clean may be of added value.

Thanks for the reply!

Let me try that. As it is a container, there is no fresh install really. But I can run a clean container with no previous configs and see if I can get the db files that way.

I am just trying to run the default db.