Database corruption - Unrecoverable sqlite3 database corruption detected

Hi folks - I have a big problem.

Woke up this morning and I see that recorder database had a big problem. Resulted in a corrupt HA database that could not recover.

HA then created a new empty database so I have lost my entire HA history!

I also had a similar but not as fatal issue a few days ago. Recorder database would not load so I did a restored from a backup.

So it looks like I have something in my config/integrations that is causing this corruption and I need to find it or it will keep on happening.

The good news is that I have 3 days of HA backups plus a full offline (rsync) backup from a week ago. So it will be quite easy to get HA back up and running with most of my history.

I think it is best to identify where the issue is coming from so I will try to recreate the problem.

I have saved my HA log files from the last couple of days so hope this is helpful.

Anyone have some suggestions or can help me look through the logs?

Check your storage media, it may have issues. SSDs (nvme) are notorious for dying unexpectedly

Here is my log at around the time this happened

2025-06-14 04:05:10.109 INFO (Recorder) [homeassistant.components.sensor.recorder] Detected new cycle for sensor.st_00124050_precipitation, last_reset set to 2025-06-13T18:00:09+00:00 (old last_reset 2025-06-13T17:59:09+00:00)
2025-06-14 04:05:10.109 INFO (Recorder) [homeassistant.components.sensor.recorder] Detected new cycle for sensor.st_00124050_precipitation, last_reset set to 2025-06-13T18:01:09+00:00 (old last_reset 2025-06-13T18:00:09+00:00)
2025-06-14 04:05:10.110 INFO (Recorder) [homeassistant.components.sensor.recorder] Detected new cycle for sensor.st_00124050_precipitation, last_reset set to 2025-06-13T18:02:08+00:00 (old last_reset 2025-06-13T18:01:09+00:00)
2025-06-14 04:05:10.110 INFO (Recorder) [homeassistant.components.sensor.recorder] Detected new cycle for sensor.st_00124050_precipitation, last_reset set to 2025-06-13T18:03:08+00:00 (old last_reset 2025-06-13T18:02:08+00:00)
2025-06-14 04:05:10.110 INFO (Recorder) [homeassistant.components.sensor.recorder] Detected new cycle for sensor.st_00124050_precipitation, last_reset set to 2025-06-13T18:04:08+00:00 (old last_reset 2025-06-13T18:03:08+00:00)
2025-06-14 04:07:15.253 ERROR (SyncWorker_0) [custom_components.icloud3] HTTPSConnectionPool(host='p44-fmipweb.icloud.com', port=443): Max retries exceeded with url: /fmipservice/client/web/refreshClient?clientBuildNumber=2021Project52&clientMasteringNumber=2021B29&ckjsBuildVersion=17DProjectDev77&clientId=a765f026-215a-11f0-9a86-d83adde87ccf&dsid=292370073 (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7fffaa879090>: Failed to establish a new connection: [Errno -3] Try again'))
Traceback (most recent call last):
  File "/usr/local/lib/python3.13/site-packages/urllib3/connection.py", line 174, in _new_conn
    conn = connection.create_connection(
        (self._dns_host, self.port), self.timeout, **extra_kw
    )
  File "/usr/local/lib/python3.13/site-packages/urllib3/util/connection.py", line 72, in create_connection
    for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
               ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/socket.py", line 977, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
               ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
socket.gaierror: [Errno -3] Try again

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.13/site-packages/urllib3/connectionpool.py", line 716, in urlopen
    httplib_response = self._make_request(
        conn,
    ...<5 lines>...
        chunked=chunked,
    )
  File "/usr/local/lib/python3.13/site-packages/urllib3/connectionpool.py", line 404, in _make_request
    self._validate_conn(conn)
    ~~~~~~~~~~~~~~~~~~~^^^^^^
  File "/usr/local/lib/python3.13/site-packages/urllib3/connectionpool.py", line 1061, in _validate_conn
    conn.connect()
    ~~~~~~~~~~~~^^
  File "/usr/local/lib/python3.13/site-packages/urllib3/connection.py", line 363, in connect
    self.sock = conn = self._new_conn()
                       ~~~~~~~~~~~~~~^^
  File "/usr/local/lib/python3.13/site-packages/urllib3/connection.py", line 186, in _new_conn
    raise NewConnectionError(
        self, "Failed to establish a new connection: %s" % e
    )
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPSConnection object at 0x7fffaa879090>: Failed to establish a new connection: [Errno -3] Try again

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.13/site-packages/requests/adapters.py", line 667, in send
    resp = conn.urlopen(
        method=request.method,
    ...<9 lines>...
        chunked=chunked,
    )
  File "/usr/local/lib/python3.13/site-packages/urllib3/connectionpool.py", line 802, in urlopen
    retries = retries.increment(
        method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
    )
  File "/usr/local/lib/python3.13/site-packages/urllib3/util/retry.py", line 594, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='p44-fmipweb.icloud.com', port=443): Max retries exceeded with url: /fmipservice/client/web/refreshClient?clientBuildNumber=2021Project52&clientMasteringNumber=2021B29&ckjsBuildVersion=17DProjectDev77&clientId=a765f026-215a-11f0-9a86-d83adde87ccf&dsid=292370073 (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7fffaa879090>: Failed to establish a new connection: [Errno -3] Try again'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/config/custom_components/icloud3/apple_acct/pyicloud_session.py", line 192, in request
    response = Session.request(self, method, url, **kwargs)
  File "/usr/local/lib/python3.13/site-packages/requests/sessions.py", line 589, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python3.13/site-packages/requests/sessions.py", line 703, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python3.13/site-packages/requests/adapters.py", line 700, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='p44-fmipweb.icloud.com', port=443): Max retries exceeded with url: /fmipservice/client/web/refreshClient?clientBuildNumber=2021Project52&clientMasteringNumber=2021B29&ckjsBuildVersion=17DProjectDev77&clientId=a765f026-215a-11f0-9a86-d83adde87ccf&dsid=292370073 (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7fffaa879090>: Failed to establish a new connection: [Errno -3] Try again'))
2025-06-14 04:07:15.259 ERROR (SyncWorker_0) [custom_components.icloud3] iCloud3 Error > An error occurred connecting to the Internet, Home Assistant may be Offline > Error-HTTPSConnectionPool(host='p44-fmipweb.icloud.com', port=443): Max retries exceeded with url: /fmipservice/client/web/refreshClient, Failed to establish a new connection: [Errno -3] Try again'))
2025-06-14 04:07:28.955 ERROR (MainThread) [custom_components.weatherflow_forecast] Error fetching weatherflow_forecast data: Update failed: Cannot connect to host swd.weatherflow.com:443 ssl:default [Timeout while contacting DNS servers]
2025-06-14 04:10:10.124 INFO (Recorder) [homeassistant.components.sensor.recorder] Detected new cycle for sensor.st_00124050_lightning_count, last_reset set to 2025-06-13T18:05:08+00:00 (old last_reset 2025-06-13T18:04:08+00:00)
2025-06-14 04:10:10.125 INFO (Recorder) [homeassistant.components.sensor.recorder] Detected new cycle for sensor.st_00124050_lightning_count, last_reset set to 2025-06-13T18:07:08+00:00 (old last_reset 2025-06-13T18:05:08+00:00)
2025-06-14 04:10:10.125 INFO (Recorder) [homeassistant.components.sensor.recorder] Detected new cycle for sensor.st_00124050_lightning_count, last_reset set to 2025-06-13T18:08:08+00:00 (old last_reset 2025-06-13T18:07:08+00:00)
2025-06-14 04:10:10.125 INFO (Recorder) [homeassistant.components.sensor.recorder] Detected new cycle for sensor.st_00124050_lightning_count, last_reset set to 2025-06-13T18:09:08+00:00 (old last_reset 2025-06-13T18:08:08+00:00)
2025-06-14 04:10:10.125 INFO (Recorder) [homeassistant.components.sensor.recorder] Detected new cycle for sensor.st_00124050_precipitation, last_reset set to 2025-06-13T18:05:08+00:00 (old last_reset 2025-06-13T18:04:08+00:00)
2025-06-14 04:10:10.125 INFO (Recorder) [homeassistant.components.sensor.recorder] Detected new cycle for sensor.st_00124050_precipitation, last_reset set to 2025-06-13T18:07:08+00:00 (old last_reset 2025-06-13T18:05:08+00:00)
2025-06-14 04:10:10.125 INFO (Recorder) [homeassistant.components.sensor.recorder] Detected new cycle for sensor.st_00124050_precipitation, last_reset set to 2025-06-13T18:08:08+00:00 (old last_reset 2025-06-13T18:07:08+00:00)
2025-06-14 04:10:10.125 INFO (Recorder) [homeassistant.components.sensor.recorder] Detected new cycle for sensor.st_00124050_precipitation, last_reset set to 2025-06-13T18:09:08+00:00 (old last_reset 2025-06-13T18:08:08+00:00)
2025-06-14 04:10:30.495 INFO (MainThread) [custom_components.weatherflow_forecast] Fetching weatherflow_forecast data recovered
2025-06-14 04:12:29.612 ERROR (Recorder) [homeassistant.helpers.recorder] Error executing query
Traceback (most recent call last):
  File "/usr/local/lib/python3.13/site-packages/sqlalchemy/engine/base.py", line 1964, in _exec_single_context
    self.dialect.do_execute(
    ~~~~~~~~~~~~~~~~~~~~~~~^
        cursor, str_statement, effective_parameters, context
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/usr/local/lib/python3.13/site-packages/sqlalchemy/engine/default.py", line 945, 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/helpers/recorder.py", line 96, in session_scope
    yield session
  File "/usr/src/homeassistant/homeassistant/components/recorder/purge.py", line 88, in purge_old_data
    has_more_to_purge |= _purge_states_and_attributes_ids(
                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        instance, session, states_batch_size, purge_before
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/usr/src/homeassistant/homeassistant/components/recorder/purge.py", line 206, in _purge_states_and_attributes_ids
    _purge_unused_attributes_ids(instance, session, attributes_ids_batch)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/recorder/purge.py", line 330, in _purge_unused_attributes_ids
    _purge_batch_attributes_ids(instance, session, unused_attribute_ids_set)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/recorder/purge.py", line 481, in _purge_batch_attributes_ids
    deleted_rows = session.execute(
        delete_states_attributes_rows(attributes_ids_chunk)
    )
  File "/usr/local/lib/python3.13/site-packages/sqlalchemy/orm/session.py", line 2365, in execute
    return self._execute_internal(
           ~~~~~~~~~~~~~~~~~~~~~~^
        statement,
        ^^^^^^^^^^
    ...<4 lines>...
        _add_event=_add_event,
        ^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/usr/local/lib/python3.13/site-packages/sqlalchemy/orm/session.py", line 2251, in _execute_internal
    result: Result[Any] = compile_state_cls.orm_execute_statement(
                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        self,
        ^^^^^
    ...<4 lines>...
        conn,
        ^^^^^
    )
    ^
  File "/usr/local/lib/python3.13/site-packages/sqlalchemy/orm/bulk_persistence.py", line 2021, in orm_execute_statement
    return super().orm_execute_statement(
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        session, statement, params, execution_options, bind_arguments, conn
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/usr/local/lib/python3.13/site-packages/sqlalchemy/orm/context.py", line 306, in orm_execute_statement
    result = conn.execute(
        statement, params or {}, execution_options=execution_options
    )
  File "/usr/local/lib/python3.13/site-packages/sqlalchemy/engine/base.py", line 1416, in execute
    return meth(
        self,
        distilled_parameters,
        execution_options or NO_OPTIONS,
    )
  File "/usr/local/lib/python3.13/site-packages/sqlalchemy/sql/lambdas.py", line 597, in _execute_on_connection
    return connection._execute_clauseelement(
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        self, distilled_params, execution_options
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/usr/local/lib/python3.13/site-packages/sqlalchemy/engine/base.py", line 1638, in _execute_clauseelement
    ret = self._execute_context(
        dialect,
    ...<8 lines>...
        cache_hit=cache_hit,
    )
  File "/usr/local/lib/python3.13/site-packages/sqlalchemy/engine/base.py", line 1843, in _execute_context
    return self._exec_single_context(
           ~~~~~~~~~~~~~~~~~~~~~~~~~^
        dialect, context, statement, parameters
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/usr/local/lib/python3.13/site-packages/sqlalchemy/engine/base.py", line 1983, in _exec_single_context
    self._handle_dbapi_exception(
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        e, str_statement, effective_parameters, cursor, context
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/usr/local/lib/python3.13/site-packages/sqlalchemy/engine/base.py", line 2352, in _handle_dbapi_exception
    raise sqlalchemy_exception.with_traceback(exc_info[2]) from e
  File "/usr/local/lib/python3.13/site-packages/sqlalchemy/engine/base.py", line 1964, in _exec_single_context
    self.dialect.do_execute(
    ~~~~~~~~~~~~~~~~~~~~~~~^
        cursor, str_statement, effective_parameters, context
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/usr/local/lib/python3.13/site-packages/sqlalchemy/engine/default.py", line 945, in do_execute
    cursor.execute(statement, parameters)
    ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
sqlalchemy.exc.DatabaseError: (sqlite3.DatabaseError) database disk image is malformed
[SQL: DELETE FROM state_attributes WHERE state_attributes.attributes_id IN (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,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53229787, 53229788, 53229789, 53229790, 53229791, 53229792, 53229793, 53229794, 53229795, 53229796, 53229797, 53229798, 53229799, 53229800, 53229801, 53229802, 53229803, 53229804, 53229805, 53229806, 53229807, 53229808, 53229809, 53229810, 53232784, 53229811, 53229812, 53229813, 53229814, 53232785, 53229815, 53229816, 53229817, 53229818, 53229819, 53229820, 53229822, 53229823, 53229824, 53229825, 53229826, 53229827, 53229828, 53229829, 53229830, 53229831, 53229832, 53229833, 53229834, 53229835 ... 3900 parameters truncated ... 53233830, 53233831, 53233832, 53233833, 53233834, 53233835, 53233836, 53233837, 53233838, 53233839, 53233840, 53233841, 53233842, 53233843, 53233844, 53233845, 53233846, 53233847, 53233848, 53233849, 53233850, 53233851, 53233852, 53233853, 53233854, 53233855, 53233856, 53233857, 53233858, 53233859, 53233860, 53233861, 53233862, 53233863, 53233864, 53233865, 53233866, 53233867, 53233868, 53233869, 53233870, 53233871, 53233872, 53233873, 53233874, 53233875, 53233876, 53233877, 53233878, 53233879)]
(Background on this error at: https://sqlalche.me/e/20/4xp6)

(Background on this error at: https://sqlalche.me/e/20/4xp6)
Traceback (most recent call last):
  File "/usr/local/lib/python3.13/site-packages/sqlalchemy/engine/base.py", line 1964, in _exec_single_context
    self.dialect.do_execute(
    ~~~~~~~~~~~~~~~~~~~~~~~^
        cursor, str_statement, effective_parameters, context
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/usr/local/lib/python3.13/site-packages/sqlalchemy/engine/default.py", line 945, 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/core.py", line 907, in _process_one_task_or_event_or_recover
    task.run(self)
    ~~~~~~~~^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/recorder/tasks.py", line 120, in run
    if purge.purge_old_data(
       ~~~~~~~~~~~~~~~~~~~~^
        instance, self.purge_before, self.repack, self.apply_filter
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ):
    ^
  File "/usr/src/homeassistant/homeassistant/components/recorder/util.py", line 642, in wrapper
    return job(*args, **kwargs)
  File "/usr/src/homeassistant/homeassistant/components/recorder/purge.py", line 88, in purge_old_data
    has_more_to_purge |= _purge_states_and_attributes_ids(
                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        instance, session, states_batch_size, purge_before
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/usr/src/homeassistant/homeassistant/components/recorder/purge.py", line 206, in _purge_states_and_attributes_ids
    _purge_unused_attributes_ids(instance, session, attributes_ids_batch)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/recorder/purge.py", line 330, in _purge_unused_attributes_ids
    _purge_batch_attributes_ids(instance, session, unused_attribute_ids_set)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/recorder/purge.py", line 481, in _purge_batch_attributes_ids
    deleted_rows = session.execute(
        delete_states_attributes_rows(attributes_ids_chunk)
    )
  File "/usr/local/lib/python3.13/site-packages/sqlalchemy/orm/session.py", line 2365, in execute
    return self._execute_internal(
           ~~~~~~~~~~~~~~~~~~~~~~^
        statement,
        ^^^^^^^^^^
    ...<4 lines>...
        _add_event=_add_event,
        ^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/usr/local/lib/python3.13/site-packages/sqlalchemy/orm/session.py", line 2251, in _execute_internal
    result: Result[Any] = compile_state_cls.orm_execute_statement(
                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        self,
        ^^^^^
    ...<4 lines>...
        conn,
        ^^^^^
    )
    ^
  File "/usr/local/lib/python3.13/site-packages/sqlalchemy/orm/bulk_persistence.py", line 2021, in orm_execute_statement
    return super().orm_execute_statement(
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        session, statement, params, execution_options, bind_arguments, conn
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/usr/local/lib/python3.13/site-packages/sqlalchemy/orm/context.py", line 306, in orm_execute_statement
    result = conn.execute(
        statement, params or {}, execution_options=execution_options
    )
  File "/usr/local/lib/python3.13/site-packages/sqlalchemy/engine/base.py", line 1416, in execute
    return meth(
        self,
        distilled_parameters,
        execution_options or NO_OPTIONS,
    )
  File "/usr/local/lib/python3.13/site-packages/sqlalchemy/sql/lambdas.py", line 597, in _execute_on_connection
    return connection._execute_clauseelement(
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        self, distilled_params, execution_options
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/usr/local/lib/python3.13/site-packages/sqlalchemy/engine/base.py", line 1638, in _execute_clauseelement
    ret = self._execute_context(
        dialect,
    ...<8 lines>...
        cache_hit=cache_hit,
    )
  File "/usr/local/lib/python3.13/site-packages/sqlalchemy/engine/base.py", line 1843, in _execute_context
    return self._exec_single_context(
           ~~~~~~~~~~~~~~~~~~~~~~~~~^
        dialect, context, statement, parameters
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/usr/local/lib/python3.13/site-packages/sqlalchemy/engine/base.py", line 1983, in _exec_single_context
    self._handle_dbapi_exception(
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        e, str_statement, effective_parameters, cursor, context
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/usr/local/lib/python3.13/site-packages/sqlalchemy/engine/base.py", line 2352, in _handle_dbapi_exception
    raise sqlalchemy_exception.with_traceback(exc_info[2]) from e
  File "/usr/local/lib/python3.13/site-packages/sqlalchemy/engine/base.py", line 1964, in _exec_single_context
    self.dialect.do_execute(
    ~~~~~~~~~~~~~~~~~~~~~~~^
        cursor, str_statement, effective_parameters, context
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/usr/local/lib/python3.13/site-packages/sqlalchemy/engine/default.py", line 945, in do_execute
    cursor.execute(statement, parameters)
    ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
sqlalchemy.exc.DatabaseError: (sqlite3.DatabaseError) database disk image is malformed
[SQL: DELETE FROM state_attributes WHERE state_attributes.attributes_id IN (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)]
[parameters: (53229787, 53229788, 53229789, 53229790, 53229791, 53229792, 53229793, 53229794, 53229795, 53229796, 53229797, 53229798, 53229799, 53229800, 53229801, 53229802, 53229803, 53229804, 53229805, 53229806, 53229807, 53229808, 53229809, 53229810, 53232784, 53229811, 53229812, 53229813, 53229814, 53232785, 53229815, 53229816, 53229817, 53229818, 5322919, 53229820, 53229822, 53229823, 53229824, 53229825, 53229826, 53229827, 53229828, 53229829, 53229830, 53229831, 53229832, 53229833, 53229834, 53229835 ... 3900 parameters truncated ... 53233830, 53233831, 53233832, 53233833, 53233834, 53233835, 53233836, 53233837, 53233838, 53233839, 53233840, 53233841, 53233842, 53233843, 53233844, 53233845, 53233846, 53233847, 53233848, 53233849, 53233850, 53233851, 53233852, 53233853, 53233854, 53233855, 53233856, 53233857, 53233858, 53233859, 53233860, 53233861, 53233862, 53233863, 53233864, 53233865, 53233866, 53233867, 53233868, 53233869, 53233870, 53233871, 53233872, 53233873, 53233874, 53233875, 53233876, 53233877, 53233878, 53233879)]
(Background on this error at: https://sqlalche.me/e/20/4xp6)
2025-06-14 04:12:29.807 INFO (Recorder) [homeassistant.components.recorder.pool.RecorderPool] Pool recreating
2025-06-14 04:12:29.808 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.2025-06-13T18:12:29.808038+00:00 in order to allow startup to proceed
2025-06-14 04:15:10.088 INFO (Recorder) [homeassistant.components.sensor.recorder] Compiling initial sum statistics for sensor.tap_front_daily_volume, zero point set to 0.0

everything fine on storage. It’s a USB SSD with smart monitoring on and all smart stats are good

Actually not a bad idea for me to setup HA on a different server for testing. I have two systems (rpi5 and minipc) so easy to do this…

Hello jata,

If it’s a PI, make sure it’s connected to a powered USB hub, in case you are getting power glitching by powering thru the PI itself. It’s a known problem that is often solved with supplying power external of the PI’s power to the usb devices.

If not, then I don’t know.

Power supply and setup is fine but thanks for the suggestion.

My gut is telling me that the root cause is related to data coming from my weather station (st_00124050_precipitation)

I will be looking at this next to see if I can trigger the issue on my prod system. Might as well start here as it currently has a empty database!

I would like to restore just my ha database from a HA backup.

I have the encryption key so is there a way to do this?

The error message indicates the file is corrupted. This can be caused by

a) bad media
b) power glitch or power outage
c) failure to properly shut the system down

OK thanks everyone.

A bit worrying for sure as the disk seems totally fine and everything has run fine for a couple of years but I guess these things do happen.

I have restored the database file from a week old offline backup and I know the issue started after this time so it is a reasonable restore point and I only have lost 6 days history data.

I will monitor and hope it doesn’t happen again.

Given this might be related to a disk/data issue on my rpi5, I have moved my HA setup from the rpi5 with usb ssd to a minipc with internal nvme storage.

So hopefully this is now resolved.

Very bad news. Same issue has happened again overnight.

This is on a different server disk with one week old db backup that i know was good. So it I don’t think this is a one off file corruption issue.

Happened at exactly the same time as yesterday so I think this is a big clue.

  • On both days it happened at around 4.10 - 4.15am.
  • I think at this time the recorder for long term statistics does maintenance
  • looks like recorder is purging old data for short term statistics

It’s this following part of the error that looks bonkers…

I really don’t know what to do but I will start by seeing if i can see anything obvious in the db (use DB browser on a copy of the db)

My other idea is to delete any new entities that I have setup in the last week that have any associated LTS.

[SQL: DELETE FROM statistics_short_term WHERE statistics_short_term.id IN (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 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245157, 35245158, 35245159, 35245160, 35245161, 35245162, 35245163, 35245164, 35245165, 35245166, 35245167, 35245168, 35245169, 35245170, 35245171, 35245172, 35245173, 35245174, 35245175, 35245176, 35245177, 35245178, 35245179, 35245180, 35245181, 35245182, 35245183, 35245184, 35245185, 35245186, 35245187, 35245188, 35245189, 35245190, 35245191, 35245192, 35245193, 35245194, 35245195, 35245196, 35245197, 35245198, 35245199, 35245200 ... 3900 parameters truncated ... 35249101, 35249102, 35249103, 35249104, 35249105, 35249106, 35249107, 35249108, 35249109, 35249110, 35249111, 35249112, 35249113, 35249114, 35249115, 35249116, 35249117, 35249118, 35249119, 35249120, 35249121, 35249122, 35249123, 35249124, 35249125, 35249126, 35249127, 35249128, 35249129, 35249130, 35249131, 35249132, 35249133, 35249134, 35249135, 35249136, 35249137, 35249138, 35249139, 35249140, 35249141, 35249142, 35249143, 35249144, 35249145, 35249146, 35249147, 35249148, 35249149, 35249150)]
(Background on this error at: https://sqlalche.me/e/20/4xp6)

You may want to open a bug report.

HA bug? relating to what? short term statistics? recorder?

I have opened both the corrupted db and my backup db (before the error started) using DB browser and I can’t find anything wrong with the database.

They both open fine using DB browser and i am looking through the data and everything looks fine. Nothing obvious at all.

I can confirm that happens then.

Well, you installed a week-old backup and it didn’t help.
Pull a month old backup.
If it stills corrupts, I would suspect some of the hardware you moved over.

You need to look at /var/log/syslog or /var/log/messages and see if you had errors from any of the /dev/sdX devices around the time of the corruption. Post the lines here.
Looking at SMART logs for the drive is very unlikely to tell you much, if anything at all (vendor dependent).

I don’t have an older backup than I have already tried.

No hardware has been moved. What do you mean by this?

I personally think this is an error created by an integration/config and it has only started causing the corruption in the last few days.

I am now running two HA instances in parallel on different servers. (test and prod). I am going to delete sensors and associated LTS each day to see if I can find it.

Thanks for this.

Should I check logs on the host sever as my HA is a docker container or logs inside the container?

I have found something.

The issue occurs when the recorder purge action occurs with the repack setting enabled. I can create the error on demand using the purge recorder action with repack enabled.

After a bit more research I found that there is a bug report (no resolution) for recorder

This all now stacks up as the daily recorder maintenance occurs at 4.12am!

But there seems to be no solution so it looks like I will loose all of my HA history from the last couple of years!