Error purging history - database disk image is malformed

I’ve started to see this error in my logs. I assume it means the DB is corrupt but is there a way to restore it from a back up or something? What do I lose if I blow this away?

I’ve been looking at doing a new deployment (so I can get off Ubuntu and onto a supported OS) so I can work to make that happen but I was going to export the data from the old system into the new and I don’t want to bring the corruption with me (nor do I want to lose my setup).

Logger: homeassistant.components.recorder.purge
Source: components/recorder/purge.py:101
Integration: Recorder ([documentation](https://www.home-assistant.io/integrations/recorder), [issues](https://github.com/home-assistant/home-assistant/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+recorder%22))
First occurred: 4:12:00 AM (1 occurrences)
Last logged: 4:12:00 AM

Error purging history: (sqlite3.DatabaseError) database disk image is malformed [SQL: SELECT events.event_id AS events_event_id, events.event_type AS events_event_type, events.event_data AS events_event_data, events.origin AS events_origin, events.time_fired AS events_time_fired, events.created AS events_created, events.context_id AS events_context_id, events.context_user_id AS events_context_user_id, events.context_parent_id AS events_context_parent_id FROM events ORDER BY events.time_fired ASC LIMIT ? OFFSET ?] [parameters: (1, 0)] (Background on this error at: http://sqlalche.me/e/13/4xp6)

Did you manage to fix this? I am seeing the same error.

I installed MariaDB and tried using the recorder.purge.

Error executing query: (MySQLdb._exceptions.IntegrityError) (1451, 'Cannot delete or update a parent row: a foreign key constraint fails (`homeassistant`.`states`, CONSTRAINT `states_ibfk_2` FOREIGN KEY (`old_state_id`) REFERENCES `states` (`state_id`))') [SQL: DELETE FROM states WHERE states.last_updated < %s] [parameters: (datetime.datetime(2020, 11, 21, 17, 9, 8, 242931, tzinfo=datetime.timezone.utc),)] (Background on this error at: http://sqlalche.me/e/13/gkpj)
Error executing query: (MySQLdb._exceptions.IntegrityError) (1451, 'Cannot delete or update a parent row: a foreign key constraint fails (`homeassistant`.`states`, CONSTRAINT `states_ibfk_2` FOREIGN KEY (`old_state_id`) REFERENCES `states` (`state_id`))') [SQL: DELETE FROM states WHERE states.last_updated < %s] [parameters: (datetime.datetime(2020, 11, 21, 17, 11, 2, 247968, tzinfo=datetime.timezone.utc),)] (Background on this error at: http://sqlalche.me/e/13/gkpj)

Nope, and no one replied to me. Not sure how it happened as everything was working fine one day and then not the next. I’m also using a VM on a hard drive so it’s not a corrupt sd card (though maybe an issue with the hard drive?)