-
-
Notifications
You must be signed in to change notification settings - Fork 30.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Database upgrade on MariaDB takes days to finish #123179
Comments
Hey there @home-assistant/core, mind taking a look at this issue as it has been labeled with an integration ( Code owner commandsCode owners of
(message by CodeOwnersMention) recorder documentation |
Normally, I'd ask Erik to take a look, but it looks like its working as designed and there isn't anything to be done but wait given the size of the database and hardware combination. InnoDB alters are slow, sometimes 2-3 orders of magnitude slower than SQLite. |
I'm also experiencing a very long time for the database upgrade to complete. I only upgraded to 2024.8.0 on the normal standard release schedule as of today and its been going for 4 hours now.. |
@mackowskim, @lexiismadd out of curiosity, how many days of retention have you configured? |
recorder: Till now I was not able to finish the upgrade. After one day HA is failing because of the "out of memory error". I have increased innodb_buffer_pool_size size to 3GB and innodb_buffer_pool_chunk_size to 128MB today and also added additional memory to HA VM itself (from 4GB to 6GB of RAM). MariaDB [homeassistant]> SHOW TABLE STATUS LIKE 'states'\G |
hello. Its no problem for me the wait. but i dont know the progress. and the speed. my database is big (60gb) |
Maybe an idea to purge recorder before the update? |
Login into mysql database and run:
It will show you alter table process running along with estimated percent done in the last column. |
thanks! EDIT: and the error is this: my database is big. more than 60GB. and have more than 300GB of free space. i will wait if other people have this problem, and keep reading the other issues because i thing im not alone :-P |
To add some additional information. Running on Yellow with 8GB RAM and NVM storage. Database migration failed, but not after HA Core OOM several times causing a cascade of other issues including HA App crashing on all my macs and IOS devices running out of memory... I view my setup as a corner case, but if the recorder could drop data if the amount of items queued up causes the system to run out of memory would probably be helpful. I will be migrating the database to a host with faster I/O to perform the upgrade as I do not want to loose my historical database. |
Mine eventually finished after a few h9urs |
You might need to increase innodb_buffer_pool_size. Check if you have enough available memory on server/VM to increase it without swapping: https://mariadb.com/docs/server/storage-engines/innodb/operations/configure-buffer-pool/ |
thanks a lot for your information. how can i check if the update is complet or if not all the MODIFY are completed? |
Login into mysql:
it should be bigint type in those columns:
|
BTW, And also that for large databases it's good to have larger buffer pool size set (at least 1GB) |
So. I had the same (or a similar) issue. After retrying again and again I logged into the DB and found out that the MariaDB got completely stuck. To solve the issue I did the following:
The final file (for me) looked like this:
|
Thanks, your steps helped me as well. My HA database is 55 GB in size, spanning historical data from two years running a large home lab with hundreds of sensors, many 10000s of datapoints per day. It didn't work with default mariadb setting taking days with very little progress. It even triggered out of memory killer on my docker host multiple times (killing homeassistant/mariadb containers) until I figured out it was this issue reported here. One of the worst HA upgrades when it comes to internal upgrade processes. For many end users a disaster. https://www.home-assistant.io/blog/2024/08/07/release-20248/
It can take days(!) or in various instances it never finishes running into out of memory problems. Regards EDIT: The db schema update process finished. Final DB size: 56 GB.
Still, it took 10 hours, 50 minutes with the buffer sizes enlarged (non defaults). I've already moved HA to a different server, separate from mariadb docker host machine due to OOM situations during db upgrade. Prometheus node exporter dashboard from the docker host running HA: CAdvisor2 dashboard: Since the DB upgrade process already finished on the other machine, I've decided to restart HA docker container after waiting another hour because HA situation didn't improve. It was looking like eating all the available RAM and SWAP again. After container restart it's back on ok-ish levels again. I would consider this as another bug. On the original machine where HA+mariadb were hosted (8GB) for years, this upgrade would never have worked. I was fortunate to have multiple machine available in my homelab so I could move docker containers/volumes around. But that's certainly not what everyone has. Repeating myself here: I think the implications of the schema upgrade in 2024.8 should have been better communicated. Depending on the db size it requires a huge amount of time and RAM. For the non tech-savvy end users this is certainly a disaster. |
Same here. ~55GB DB, after 17h only 22% completed. IMO we need those parameters to be exposed to the MariaDB Add-On UI as any config changes will be overwritten during the plugin update: https://community.home-assistant.io/t/addon-mariadb-expose-more-mariadb-config-parameters-in-addon-config/758474 |
Another observation is: The states table is the largest, therefore most of the issues are encountered during the migration of it. Export the structure of the table so you can restore the index afterwards. |
note "The total number of locks exceeds the lock table size", might be a result of https://jira.mariadb.org/browse/MDEV-34167 (note fixed versions) but a large innodb buffer pool size might avoid it. For large changes an increased innodb_log_file_size can help increase speed (Dynamicly changable on MariaDB 10.11+). Several GB matching buffer pool size is ok if sufficient storage space. |
This help me to do the upgrade, also as it is now finished the OutOfMermory of haos also stop 🥰. |
how do you do that; I tried (ha supervised): and the first thing ha does is: re-create the index .... ? |
Just for info and help: Database size: 27.1GB ...all running fine until now and will give feedback when done. Cheers, |
Had same issue on my side (HA on Ubuntu 22.04.04 LTS with MariaDB), several days and tries to upgrade database failed. Solution: increase "innodb_buffer_pool_size" Upgrade did work with 512M, 128M failed with 40%. |
I had the same problem. I do have a 80GB database directory (mariadb) on a Raspberry Pi. The upgrade script should warn more explicitely and it should offer some other options. One would be to purge old data automatically before the upgrade. Another would be to rename the table to _archive, create new ones in correct scheme and move the data to the new table over the next days. If done in blocks of 1000 lines or so from new to old it would be perfectly interruptable by reboots, restarts and so on - and won't effect the regular process - only actions and processes relying on archive data would be affected (but they could use data from the archive-tables, if really needed...). |
Ended up completely nuking my @eingemaischt is absolutely right on the proper approach to a primary key (clustered index) migration on datasets of this size. Rename, create, batch insert, and optimize (probably with some auto-increment tomfoolery in there as well). |
If your database is too big to handle the upgrade you can always rollback to previous version of HA core and run the purge before upgrading again. If you run haos you can do it by running: |
My latest update process (2024.9.1) has not gone through after waiting a whole week (home assistant yellow 8GB). Home assistant hung up twice (likely OOM). Clearing ram by stopping some add-ons fixed the OOM but still not completing. Now trying again with the This is a real end user nightmare. All the statistics im loosing bc of this in the meantime is alone unfortunate enough, but I'm worried about all the users who don't understand why this is taking days instead of the announced hours and don't have the technical background to patch some config file inside a docker container via the terminal. My db size is ~70GB, 2 years of retention. I don't really need the full 2 years for most states, but unfortunately it's not possible to specify different retention times for different sets of entities. |
I also had this fail each time my Home Assistant OS instance restarted it would try to upgrade and then fail after several hours. |
how to i allocate more ram to my mariaDB in home assistant OS ? |
@TraipZe MariaDB addon shares memory with the rest of the system (as with all docker containers). I used https://github.com/TazzerMAN/increase_swap_addon to create an additional 4GB of swap space (6GB in swap space total). Swap is like virtual ram that is stored on disk and used when physical ram is full. I also upgraded from my old 256GB nvme to 1TB. With all of this the database upgrade finally went through. This whole process took a whole month now in total. |
Oh im using x86 nuc with ha os. Not sure how I can allocate more ram. Med venlig hilsen / Best regardsThomas Hansen. Den 22. sep. 2024 kl. 20.58 skrev dominikandreas ***@***.***>:
@TraipZe I used https://github.com/TazzerMAN/increase_swap_addon to create an additional 4GB of swap space (6GB in total). Swap is like virtual ram that is stored on disk and used when physical ram is full.
I also upgraded from my old 256GB name to 1TB. With all of this the database upgrade finally went through. This whole process took a whole month now in total.
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: ***@***.***>
|
Just install the addon, the swap space acts as additional virtual ram. |
The problem
After the upgrade to 2024.8.0 beta 1 HA core is upgrading database schema on my MariaDB instance from v43 to v44.
It runs 11 hours already and just 28% is done for BIGINT column change.
Seems this is the change ongoing:
#121025
Is there any way to speed up the process?
My database sits on QNAP NAS RAID 10 disks which are not slow, but it would take another 2 days to finish the process.
Also, my "states" table is 215 M of rows.
What version of Home Assistant Core has the issue?
core-2024.8.0b1
What was the last working version of Home Assistant Core?
core-2024.7.4
What type of installation are you running?
Home Assistant OS
Integration causing the issue
database / recorder
Link to integration documentation on our website
No response
Diagnostics information
No response
Example YAML snippet
No response
Anything in the logs that might be useful for us?
Additional information
No response
The text was updated successfully, but these errors were encountered: