Migrating home assistant database from sqlite to mariadb.. ONLY if you are VERY familiar with Database administration

Add to this, I had 3GB RAM allocated for my HassOS on intel NUC and initial try sqlite-to-mariadb got killed due to insufficient memory. Increased RAM on my HassOS instance from 3GB → 8GB temporarily after that it went fine. My sqlite DB was 1,9GB. During the migration RAM usage was little over 4GB + swap (2GB).

1 Like

Am now running the steps. De server (NUC J5005 CPU, 8 gig DDR, M2 SSD). Database is 12 gigabytes. After about 5 minutes both Homeassistant and SSH plugin went offline. Also direct SSH into host does not respond, the I/O lights on the NUC however show significant I/O actions so I will let it run for a couple of hours

Mine is NUC10i7 and it took almost an hour with my 2GB DB.

1 Like

Did your system become unresponsive too? Judging by your CPU and DB I think I need to wait at least 24 hours…

No it didn’t.

Hi can you explain how you did that? I’m getting the same error. I already had MariaDB installed because I use Nginx Proxy.

Using below command and then the migrate commands again, didn’t help:

apk add mysql-client
mysqldump -h core-mariadb -u homeassistant homeassistant -p > sqlbackup_DATE.sql

I keep getting this error:

@eddiewebb perhaps you can point me in the right direction :slight_smile: ?

Thats doesn’t look like mysqldump output (only needed for optional backup), which is the only command you shared.

What sqlite3mysql command did you run? And did you truncate/purge the Mysql tables first?

(the error is a schema compatability, and makes me thing your inserting data into an existing set of tables.)

You could try setting chunk size on the command line tool to reduce the amount of objects queried at a time. (will increase time but hopefully stay under machine limits)

c, --chunk INTEGER      Chunk reading/writing SQL records

If that works I can update the FAQ above.

1 Like

Added link to ‘new’ steps with caveats added from the comment stream.

1 Like

Sorry for the deleted posts, I had sensitive information there.

Hi, I used the commands like your post. First I did the installation part and then the migration command. Installation went fine, had no errors.

This migration command is giving the issues.


I already had MariaDB installed and running btw. I added it to configuration.yaml and restarted HA before I went through with the pre-req installation and migration.

I ran all the steps and are now stuck with “Invalid column type!”. How can I solve this?

WHat i did was i deleted the whole database and re-run everything did solve the problem.

I’m running now almost 24h without problems for 2 servers.

regards

I do see now my energy costs are not correct anymore.
and need to find a way to correct this.
really annoying

Yes, but can you detail how you deleted the database? Or do you mean the db_v2 file from Home Assistant? This wouldn’t really mean anything, since then nothing would be left to be imported.

Deleting the database in mariaDB first.

Lets say its called homeassistant delete that database and run the command again without creating that database first.

But right now there is an issue.
I did do that all, and went fine, but the energy costs from the energy database are wrong and don’t save at all…

i need to find a way to correct that and why its happening

I home anyone can help me, after the migrate i did notice there is an error with my energy dashboard, showing the wrong costs.

In the energy settings for example gas costs have an correct input, but it saves wrong.
same goes for the electricity.

The migration went without an error, so i don’t know whats causing this… otherwise i need to revert back to de default recorder and losing data for 24h…

I did revert back to default recorder, till i found out whats wrong

Having the same issue… it is really weird as all information like cost per kWh and consumption are correctly displayed.

good to hear i’m not alone having this problem.

i did revert back and still an issue.
I’m not sue but i think this is an HA problem.

As i did test this on a new system and reporting the value’s wrong.

Also i did revert back to the internal recorder, and the costs are still wrong… while i did not edit anything but started using mariaDB.

I hoped there was an easy way to edit the cost easy for a day… but there is no way now and i lost 24 hours of data. sadly.

i think i posted to soon, well i reverted back and yesterday even with reverting i got that wrong costs… but now is a new day and the costs are corrected.

So i think just wait a day and check again, it should be working

1 Like

Perfect solutions :ok_hand:
Worked like a charm.

1 Like