HA Crashes daily, loses DB connection

Since upgrading my RPI5 to HAOS 14.0, homeassistant started losing its connection to either the database or disk in less than a day. Sometimes it would be 12 hours, and sometimes only 3-4. I switched from the default database to Mariadb in an effort to troubleshoot, and that worked for about a week, but now homeassistant is again losing connection to its database about once per day requiring a hard reboot. Homeassistant still partially functions if I’m logged in, but no database or configuration functions work at all, even the reboot function within homeassistant.

Example logs are below from the most recent occurrence. There are many more errors, but you should get the idea. I’ve tried optimizing my database to only log what I really want logged to no effect as well. I don’t know if this is a database issue or disk issue, and am not sure how to start troubleshooting.

Logger: homeassistant.components.recorder.core
Source: components/recorder/core.py:1183
integration: Recorder (documentation, issues)
First occurred: 5:23:10 PM (2513 occurrences)
Last logged: 7:20:29 PM

Database connection invalidated: Error executing query: (MySQLdb.OperationalError) (2013, ‘Lost connection to server during query’) (Background on this error at: Error Messages — SQLAlchemy 2.0 Documentation). (retrying in 3 seconds)
Error in database connectivity during commit: Error executing query: (MySQLdb.OperationalError) (2005, “Unknown server host ‘core-mariadb’ (-11)”) (Background on this error at: Error Messages — SQLAlchemy 2.0 Documentation). (retrying in 3 seconds)


Logger: homeassistant.components.recorder.util
Source: components/recorder/util.py:202
integration: Recorder (documentation, issues)
First occurred: 5:23:13 PM (3669 occurrences)
Last logged: 7:20:26 PM

Error executing query: (MySQLdb.OperationalError) (2005, “Unknown server host ‘core-mariadb’ (-11)”) (Background on this error at: Error Messages — SQLAlchemy 2.0 Documentation)


Logger: homeassistant.components.recorder.core
Source: components/recorder/core.py:882
integration: Recorder (documentation, issues)
First occurred: 5:23:13 PM (289 occurrences)
Last logged: 7:20:25 PM

Unhandled database error while processing task KeepAliveTask()
Unhandled database error while processing task CommitTask()
Traceback (most recent call last):
File “/usr/local/lib/python3.13/site-packages/sqlalchemy/engine/base.py”, line 146, in init
File “/usr/local/lib/python3.13/site-packages/sqlalchemy/engine/base.py”, line 3302, in raw_connection
File “/usr/local/lib/python3.13/site-packages/sqlalchemy/pool/base.py”, line 449, in connect
File “/usr/local/lib/python3.13/site-packages/sqlalchemy/pool/base.py”, line 1263, in _checkout
File “/usr/local/lib/python3.13/site-packages/sqlalchemy/pool/base.py”, line 717, in checkout
File “/usr/local/lib/python3.13/site-packages/sqlalchemy/util/langhelpers.py”, line 146, in exit
File “/usr/local/lib/python3.13/site-packages/sqlalchemy/pool/base.py”, line 715, in checkout
File “/usr/local/lib/python3.13/site-packages/sqlalchemy/pool/base.py”, line 866, in get_connection
File “/usr/local/lib/python3.13/site-packages/sqlalchemy/pool/base.py”, line 900, in __connect
File “/usr/local/lib/python3.13/site-packages/sqlalchemy/util/langhelpers.py”, line 146, in exit
File “/usr/local/lib/python3.13/site-packages/sqlalchemy/pool/base.py”, line 896, in __connect
File “/usr/local/lib/python3.13/site-packages/sqlalchemy/engine/create.py”, line 643, in connect
File “/usr/local/lib/python3.13/site-packages/sqlalchemy/engine/default.py”, line 621, in connect
File “/usr/local/lib/python3.13/site-packages/MySQLdb/init.py”, line 121, in Connect
File “/usr/local/lib/python3.13/site-packages/MySQLdb/connections.py”, line 199, in init
MySQLdb.OperationalError: (2005, “Unknown server host ‘core-mariadb’ (-11)”)

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 882, in _process_one_task_or_event_or_recover
File “/usr/src/homeassistant/homeassistant/components/recorder/tasks.py”, line 286, in run
File “/usr/src/homeassistant/homeassistant/components/recorder/core.py”, line 1281, in _send_keep_alive
File “/usr/local/lib/python3.13/site-packages/sqlalchemy/orm/session.py”, line 2090, in connection
File “/usr/local/lib/python3.13/site-packages/sqlalchemy/orm/session.py”, line 2106, in _connection_for_bind
File “”, line 2, in _connection_for_bind
File “/usr/local/lib/python3.13/site-packages/sqlalchemy/orm/state_changes.py”, line 139, in _go
File “/usr/local/lib/python3.13/site-packages/sqlalchemy/orm/session.py”, line 1189, in _connection_for_bind
File “/usr/local/lib/python3.13/site-packages/sqlalchemy/engine/base.py”, line 3278, in connect
File “/usr/local/lib/python3.13/site-packages/sqlalchemy/engine/base.py”, line 148, in init
File “/usr/local/lib/python3.13/site-packages/sqlalchemy/engine/base.py”, line 2442, in _handle_dbapi_exception_noconnection
File “/usr/local/lib/python3.13/site-packages/sqlalchemy/engine/base.py”, line 146, in init
File “/usr/local/lib/python3.13/site-packages/sqlalchemy/engine/base.py”, line 3302, in raw_connection
File “/usr/local/lib/python3.13/site-packages/sqlalchemy/pool/base.py”, line 449, in connect
File “/usr/local/lib/python3.13/site-packages/sqlalchemy/pool/base.py”, line 1263, in _checkout
File “/usr/local/lib/python3.13/site-packages/sqlalchemy/pool/base.py”, line 717, in checkout
File “/usr/local/lib/python3.13/site-packages/sqlalchemy/util/langhelpers.py”, line 146, in exit
File “/usr/local/lib/python3.13/site-packages/sqlalchemy/pool/base.py”, line 715, in checkout
File “/usr/local/lib/python3.13/site-packages/sqlalchemy/pool/base.py”, line 866, in get_connection
File “/usr/local/lib/python3.13/site-packages/sqlalchemy/pool/base.py”, line 900, in __connect
File “/usr/local/lib/python3.13/site-packages/sqlalchemy/util/langhelpers.py”, line 146, in exit
File “/usr/local/lib/python3.13/site-packages/sqlalchemy/pool/base.py”, line 896, in __connect
File “/usr/local/lib/python3.13/site-packages/sqlalchemy/engine/create.py”, line 643, in connect
File “/usr/local/lib/python3.13/site-packages/sqlalchemy/engine/default.py”, line 621, in connect
File “/usr/local/lib/python3.13/site-packages/MySQLdb/init.py”, line 121, in Connect
File “/usr/local/lib/python3.13/site-packages/MySQLdb/connections.py”, line 199, in init
sqlalchemy.exc.OperationalError: (MySQLdb.OperationalError) (2005, “Unknown server host ‘core-mariadb’ (-11)”)
(Background on this error at: Error Messages — SQLAlchemy 2.0 Documentation)


Logger: homeassistant.components.hassio
Source: components/hassio/websocket_api.py:135
integration: Home Assistant Supervisor (documentation, issues)
First occurred: 7:15:32 PM (1 occurrences)
Last logged: 7:15:32 PM

Failed to to call /backups -


Logger: homeassistant.components.recorder.core
Source: components/recorder/core.py:874
integration: Recorder (documentation, issues)
First occurred: 5:23:13 PM (1219 occurrences)
Last logged: 7:20:26 PM

Unhandled database error while processing task <Event state_changed[L]: entity_id=sensor.temp4_6227_humidity, old_state=<state sensor.temp4_6227_humidity=63.67; state_class=measurement, unit_of_measurement=%, device_class=humidity, friendly_name=temp4 6227 Humidity @ 2024-12-28T17:42:45.378655-08:00>, new_state=<state sensor.temp4_6227_humidity=63.75; state_class=measurement, unit_of_measurement=%, device_class=humidity, friendly_name=temp4 6227 Humidity @ 2024-12-28T17:43:15.384211-08:00>>
Unhandled database error while processing task <Event state_changed[L]: entity_id=sensor.mysa_8fddc8_current_temperature, old_state=<state sensor.mysa_8fddc8_current_temperature=51.3; state_class=measurement, unit_of_measurement=°F, device_class=temperature, friendly_name=Mysa-8fddc8 Current Temperature @ 2024-12-28T17:43:13.338404-08:00>, new_state=<state sensor.mysa_8fddc8_current_temperature=51.4; state_class=measurement, unit_of_measurement=°F, device_class=temperature, friendly_name=Mysa-8fddc8 Current Temperature @ 2024-12-28T17:43:18.339429-08:00>>
Unhandled database error while processing task <Event state_changed[L]: entity_id=sensor.temp6_c4cb_temperature, old_state=<state sensor.temp6_c4cb_temperature=51.24; state_class=measurement, unit_of_measurement=°F, device_class=temperature, friendly_name=temp6 C4CB Temperature @ 2024-12-28T17:42:19.463295-08:00>, new_state=<state sensor.temp6_c4cb_temperature=51.3; state_class=measurement, unit_of_measurement=°F, device_class=temperature, friendly_name=temp6 C4CB Temperature @ 2024-12-28T17:43:19.492541-08:00>>
Unhandled database error while processing task <Event state_changed[L]: entity_id=sensor.temp6_c4cb_humidity, old_state=<state sensor.temp6_c4cb_humidity=62.65; state_class=measurement, unit_of_measurement=%, device_class=humidity, friendly_name=temp6 C4CB Humidity @ 2024-12-28T17:42:19.463412-08:00>, new_state=<state sensor.temp6_c4cb_humidity=62.61; state_class=measurement, unit_of_measurement=%, device_class=humidity, friendly_name=temp6 C4CB Humidity @ 2024-12-28T17:43:19.492660-08:00>>
Unhandled database error while processing task <Event state_changed[L]: entity_id=sensor.temp10_4fca_humidity, old_state=<state sensor.temp10_4fca_humidity=67.52; state_class=measurement, unit_of_measurement=%, device_class=humidity, friendly_name=temp10 4FCA Humidity @ 2024-12-28T17:41:42.664706-08:00>, new_state=<state sensor.temp10_4fca_humidity=67.63; state_class=measurement, unit_of_measurement=%, device_class=humidity, friendly_name=temp10 4FCA Humidity @ 2024-12-28T17:43:20.045988-08:00>>
Traceback (most recent call last):
File “/usr/local/lib/python3.13/site-packages/sqlalchemy/engine/base.py”, line 146, in init
File “/usr/local/lib/python3.13/site-packages/sqlalchemy/engine/base.py”, line 3302, in raw_connection
File “/usr/local/lib/python3.13/site-packages/sqlalchemy/pool/base.py”, line 449, in connect
File “/usr/local/lib/python3.13/site-packages/sqlalchemy/pool/base.py”, line 1263, in _checkout
File “/usr/local/lib/python3.13/site-packages/sqlalchemy/pool/base.py”, line 717, in checkout
File “/usr/local/lib/python3.13/site-packages/sqlalchemy/util/langhelpers.py”, line 146, in exit
File “/usr/local/lib/python3.13/site-packages/sqlalchemy/pool/base.py”, line 715, in checkout
File “/usr/local/lib/python3.13/site-packages/sqlalchemy/pool/base.py”, line 837, in get_connection
File “/usr/local/lib/python3.13/site-packages/sqlalchemy/pool/base.py”, line 900, in __connect
File “/usr/local/lib/python3.13/site-packages/sqlalchemy/util/langhelpers.py”, line 146, in exit
File “/usr/local/lib/python3.13/site-packages/sqlalchemy/pool/base.py”, line 896, in __connect
File “/usr/local/lib/python3.13/site-packages/sqlalchemy/engine/create.py”, line 643, in connect
File “/usr/local/lib/python3.13/site-packages/sqlalchemy/engine/default.py”, line 621, in connect
File “/usr/local/lib/python3.13/site-packages/MySQLdb/init.py”, line 121, in Connect
File “/usr/local/lib/python3.13/site-packages/MySQLdb/connections.py”, line 199, in init
MySQLdb.OperationalError: (2005, “Unknown server host ‘core-mariadb’ (-11)”)

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 874, in _process_one_task_or_event_or_recover
File “/usr/src/homeassistant/homeassistant/components/recorder/core.py”, line 1020, in _process_one_event
File “/usr/src/homeassistant/homeassistant/components/recorder/core.py”, line 1115, in _process_state_changed_event_into_session
File “/usr/src/homeassistant/homeassistant/components/recorder/table_managers/states_meta.py”, line 63, in get
File “/usr/src/homeassistant/homeassistant/components/recorder/table_managers/states_meta.py”, line 113, in get_many
File “/usr/src/homeassistant/homeassistant/components/recorder/util.py”, line 195, in execute_stmt_lambda_element
File “/usr/local/lib/python3.13/site-packages/sqlalchemy/orm/session.py”, line 2362, in execute
File “/usr/local/lib/python3.13/site-packages/sqlalchemy/orm/session.py”, line 2237, in _execute_internal
File “/usr/local/lib/python3.13/site-packages/sqlalchemy/orm/session.py”, line 2106, in _connection_for_bind
File “”, line 2, in _connection_for_bind
File “/usr/local/lib/python3.13/site-packages/sqlalchemy/orm/state_changes.py”, line 139, in _go
File “/usr/local/lib/python3.13/site-packages/sqlalchemy/orm/session.py”, line 1189, in _connection_for_bind
File “/usr/local/lib/python3.13/site-packages/sqlalchemy/engine/base.py”, line 3278, in connect
File “/usr/local/lib/python3.13/site-packages/sqlalchemy/engine/base.py”, line 148, in init
File “/usr/local/lib/python3.13/site-packages/sqlalchemy/engine/base.py”, line 2442, in _handle_dbapi_exception_noconnection
File “/usr/local/lib/python3.13/site-packages/sqlalchemy/engine/base.py”, line 146, in init
File “/usr/local/lib/python3.13/site-packages/sqlalchemy/engine/base.py”, line 3302, in raw_connection
File “/usr/local/lib/python3.13/site-packages/sqlalchemy/pool/base.py”, line 449, in connect
File “/usr/local/lib/python3.13/site-packages/sqlalchemy/pool/base.py”, line 1263, in _checkout
File “/usr/local/lib/python3.13/site-packages/sqlalchemy/pool/base.py”, line 717, in checkout
File “/usr/local/lib/python3.13/site-packages/sqlalchemy/util/langhelpers.py”, line 146, in exit
File “/usr/local/lib/python3.13/site-packages/sqlalchemy/pool/base.py”, line 715, in checkout
File “/usr/local/lib/python3.13/site-packages/sqlalchemy/pool/base.py”, line 837, in get_connection
File “/usr/local/lib/python3.13/site-packages/sqlalchemy/pool/base.py”, line 900, in __connect
File “/usr/local/lib/python3.13/site-packages/sqlalchemy/util/langhelpers.py”, line 146, in exit
File “/usr/local/lib/python3.13/site-packages/sqlalchemy/pool/base.py”, line 896, in __connect
File “/usr/local/lib/python3.13/site-packages/sqlalchemy/engine/create.py”, line 643, in connect
File “/usr/local/lib/python3.13/site-packages/sqlalchemy/engine/default.py”, line 621, in connect
File “/usr/local/lib/python3.13/site-packages/MySQLdb/init.py”, line 121, in Connect
File “/usr/local/lib/python3.13/site-packages/MySQLdb/connections.py”, line 199, in init
sqlalchemy.exc.OperationalError: (MySQLdb.OperationalError) (2005, “Unknown server host ‘core-mariadb’ (-11)”)
(Background on this error at: Error Messages — SQLAlchemy 2.0 Documentation)

In the MariaDb case, it seems to be a network issue.
Cannot tell where, though, RPI loosing network altogether, MariaDB, DNS, …

First debugging step would be to use the DB Host IP rather than name, to discard a DNS issue

Ah, MariaDB addon…
Have a look at the addon log for pointers, maybe

I have no experience with mariadb on haos but I do on docker, I had similar issues when the mysql container was not yet fully ready.
Other question/remark, a while ago the whole approach around sqlite was improved, not sure if you really need a mysql :slight_smile:

I only switched to Mariadb after homeassistant started losing its stock sqlite connection regularly every few hours. Homeassistant can’t keep running for more than a day or so using either sqlite or Mariadb

That cannot really happen. Sqlite DBs are just a plain file.
There must be an underlying problem, maybe disk related, indeed.

Ok that’s what I was leaning towards. Once I get the errors, I believe that homeassistant loses its disk access, how can I try to see what is going on? I can’t ssh or anything in that state, and I can’t open the pages for any of the add-ons to see their logs. I guess does that of itself mean it is a disk issue?