Sqlalchemy.exc DatabaseError

I am getting this error in my Core Log. I’ve deleted the home-assistant_v2.db file and it’s recreated after a reboot but I still get this error. Can anyone shed light on what this could be caused by and how to remedy it?

sqlalchemy.exc.DatabaseError: (sqlite3.DatabaseError) database disk image is malformed
[SQL: INSERT INTO events (event_type, event_data, origin, time_fired, created, context_id, context_user_id, context_parent_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?)]
[parameters: ('state_changed', '{}', 'LOCAL', '2021-01-21 21:21:54.446642', '2021-01-21 21:21:54.446642', '613e1d1f5676bef9ca235d6d797772e5', None, None)]
(Background on this error at: http://sqlalche.me/e/13/4xp6)
2021-01-21 18:01:00 ERROR (Recorder) [homeassistant.components.recorder] Error executing query: (sqlite3.DatabaseError) database disk image is malformed
[SQL: INSERT INTO events (event_type, event_data, origin, time_fired, created, context_id, context_user_id, context_parent_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?)]
[parameters: ('state_changed', '{}', 'LOCAL', '2021-01-21 21:21:56.465140', '2021-01-21 21:21:56.465140', '72e1b3da3413fb99da94ab835c654e77', None, None)]
(Background on this error at: http://sqlalche.me/e/13/4xp6)
2021-01-21 18:01:00 ERROR (Recorder) [homeassistant.components.recorder] Error saving events: (sqlite3.DatabaseError) database disk image is malformed
[SQL: INSERT INTO events (event_type, event_data, origin, time_fired, created, context_id, context_user_id, context_parent_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?)]
[parameters: ('state_changed', '{}', 'LOCAL', '2021-01-21 21:21:56.465140', '2021-01-21 21:21:56.465140', '72e1b3da3413fb99da94ab835c654e77', None, None)]
(Background on this error at: http://sqlalche.me/e/13/4xp6)
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1276, in _execute_context
    self.dialect.do_execute(
  File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/default.py", line 593, in do_execute
    cursor.execute(statement, parameters)
sqlite3.DatabaseError: database disk image is malformed
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/recorder/__init__.py", line 454, in _commit_event_session_or_retry
    self._commit_event_session()

Delete it, restart HA

Delete what? I’ve deleted the home-assistant_v2.db file and it’s recreated after a reboot but I still get this error. There is no change. Are there other database files? or is the home-assistant_v2.db file the only one?

That’s the only one. Maybe your SD card is failing…

I’ve same error’s, the ssd it’s new, connected on Raspberry Pi 4 through USB 3.0.

this is the error. the problem is that is totally random, once after 3 days, sometimes after less 24h.

So it’s the ssd?

Maybe check the kernel log for problems with the external storage?

It’s possible your cable or the case is malfunctioning. I had a bad USB case once that was disconnecting the drive at the slightest touch. This caused the Pi to hang and could possibly damage some files.

Another thing to check is the power supply. If it’s too weak, this could also cause reboots of your external drive.

For the power supply, I bought the original one, but seems now nothing is changes. I tried also a mechanical hard disk, and it lasted less than 24 hours. At this point I think the problem could be the case for ssd/hdd. I’ll buy one with external supply, so the USB will be used only for data exchange. Thanks!