DB Migration error in 2022.4 update

I got this error when updating.
I have the recorder configured in a external MariaDB DB.

Log Details (ERROR)

Logger: homeassistant.components.recorder
Source: components/recorder/migration.py:110
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: 8:11:16 AM (1 occurrences)
Last logged: 8:11:16 AM

Database error during schema migration

Traceback (most recent call last): File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1808, in _execute_context self.dialect.do_execute( File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/default.py", line 732, in do_execute cursor.execute(statement, parameters) File "/usr/local/lib/python3.9/site-packages/MySQLdb/cursors.py", line 206, in execute res = self._query(query) File "/usr/local/lib/python3.9/site-packages/MySQLdb/cursors.py", line 319, in _query db.query(q) File "/usr/local/lib/python3.9/site-packages/MySQLdb/connections.py", line 254, in query _mysql.connection.query(self, query) MySQLdb._exceptions.OperationalError: (2013, 'Lost connection to MySQL server during query') 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 992, in _migrate_schema_and_setup_run migration.migrate_schema(self, current_version) File "/usr/src/homeassistant/homeassistant/components/recorder/migration.py", line 79, in migrate_schema _apply_update(instance, new_version, current_version) File "/usr/src/homeassistant/homeassistant/components/recorder/migration.py", line 648, in _apply_update _create_index(instance, "states", "ix_states_attributes_id") File "/usr/src/homeassistant/homeassistant/components/recorder/migration.py", line 112, in _create_index raise_if_exception_missing_str(err, ["already exists", "duplicate"]) File "/usr/src/homeassistant/homeassistant/components/recorder/migration.py", line 44, in raise_if_exception_missing_str raise ex File "/usr/src/homeassistant/homeassistant/components/recorder/migration.py", line 110, in _create_index index.create(connection) File "/usr/local/lib/python3.9/site-packages/sqlalchemy/sql/schema.py", line 4287, in create bind._run_ddl_visitor(ddl.SchemaGenerator, self, checkfirst=checkfirst) File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 2119, in _run_ddl_visitor visitorcallable(self.dialect, self, **kwargs).traverse_single(element) File "/usr/local/lib/python3.9/site-packages/sqlalchemy/sql/visitors.py", line 524, in traverse_single return meth(obj, **kw) File "/usr/local/lib/python3.9/site-packages/sqlalchemy/sql/ddl.py", line 936, in visit_index self.connection.execute(CreateIndex(index)) File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1295, in execute return meth(self, multiparams, params, _EMPTY_EXECUTION_OPTS) File "/usr/local/lib/python3.9/site-packages/sqlalchemy/sql/ddl.py", line 80, in _execute_on_connection return connection._execute_ddl( File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1387, in _execute_ddl ret = self._execute_context( File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1851, in _execute_context self._handle_dbapi_exception( File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 2032, in _handle_dbapi_exception util.raise_( File "/usr/local/lib/python3.9/site-packages/sqlalchemy/util/compat.py", line 207, in raise_ raise exception File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 1808, in _execute_context self.dialect.do_execute( File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/default.py", line 732, in do_execute cursor.execute(statement, parameters) File "/usr/local/lib/python3.9/site-packages/MySQLdb/cursors.py", line 206, in execute res = self._query(query) File "/usr/local/lib/python3.9/site-packages/MySQLdb/cursors.py", line 319, in _query db.query(q) File "/usr/local/lib/python3.9/site-packages/MySQLdb/connections.py", line 254, in query _mysql.connection.query(self, query) sqlalchemy.exc.OperationalError: (MySQLdb._exceptions.OperationalError) (2013, 'Lost connection to MySQL server during query') [SQL: CREATE INDEX ix_states_attributes_id ON states (attributes_id)] (Background on this error at: https://sqlalche.me/e/14/e3q8)
1 Like

No one?

After three restart, it takes more than an hour to fail during the DB Upgrade, but it is unable to finish.
The server is fairly powerful. But never ends the migration.

The size of the DB is over 10GB.

quite sad.
I had to drop my tables to perform the update

Same here. Although my error message is shorter.

Logger: homeassistant.components.recorder.util
Source: components/recorder/util.py:90
Integration: Recorder (documentation, issues)
First occurred: 1:43:39 PM (1 occurrences)
Last logged: 1:43:39 PM

Error executing query: (MySQLdb._exceptions.OperationalError) (2013, ‘Lost connection to MySQL server during query’) [SQL: CREATE INDEX ix_states_attributes_id ON states (attributes_id)] (Background on this error at: Error Messages — SQLAlchemy 1.4 Documentation)

Maybe some kind of timeout issue specific to external DBs?
My hardware is ample. It’s one of those cheap fanless micro PCs running HA supervised on latest Debian minimal. It’s considerably better than an RPI anyway and load/performance has been good so I don’t think that’s the problem. I wonder how to tweak the timeout value for these long queries. Anyone?

I think you should open a GitHub issue on this.

1 Like

HA 2022.4 database migration stuck with MariaDB · Issue #69620 · home-assistant/core (github.com)

looks like there already is one.

Till now the same problem not solved

Could not fix it in HassOS - there is no tools for it. On HassOS you can only delete the whole DB and install new one. So if the DB is for example corrupted you can do nothing at all!!!

Anyone figured out a way to get the DB to upgrade successfully without loosing all your data and needing to build your Hass setup from scratch again?

having same issue since 2022.5.5 with MariaDB
maybe it is from a sql timeout , not sure why Home Assistant is running on a PC with
AMD Ryzen 9 3900X 12-Core Processor
64Gig RAM
and db is stored on a 206.5 TB ZFS Array that has 12Gbs read / write
and all of the cores barely go over 10% apart from occasional thread that is 100%

if I export and then empty the db then do the update then import in small chunks I can get it done using phpmyadmin that 64M limit is a killer however PLB - SQLDumpSplitter3