DB image malformed. How to fix it?

this gives me a “line xy database or filesystem full” error.
However, filesystem got 10g free space and db size is 1,2g so there should be plenty of space.
any idea?

I came to this error after moving from supervised installation to hassos and restoring from a snapshot. its a bit sad, if i need to expect this after each restore.

@Filoni Thanks for the info. Working like a charm.
I had to compile sqlite3.30 (since I’m on Buster on my RaspberryPi3) from source but after that initial effort, I could go from a 1.2GB (broken) to a 500MB (working fine) DB.

Great!! Working like a charm!!

“.recover” worked well for me! However, I had to copy it down to my Windows machine and do it there, because on my RPi:
“.dump” threw these errors (despite having 6.2GB free):
Error: near line 1877906: database or disk is full
and “.recover” said this:
SQL error: no such table: sqlite_dbpage

Thx again!!

2 Likes

Hi Filoni, thanks for the hint. Worked for me after restoring a snapshot gave me tons of errors in the logs.

Thanks, I referenced your post on Fix corrupted / malformed SQLite database (home-assistant_v2.db) :+1:

Hi! Just saw this in my logs too…
Is it safe to just delete the db?

The db is just for storing values right? No settings and other stuff get delete?

Same here! After restoring a snapshot it works initially until you reboot.

If your history is sooooooo important, why don’t you use what you need to keep to an influxdb?? I have lost count of the number of times I have had to delete my database for one reason or another… It’s just history anyway…

:rofl:

Some care, some don´t :man_shrugging:

Hey now, we can all play nice here! It’s only Wednesday…looks like if people are bothering to try to keep their data, then they’re probably doing something with it. I’ve learned the hard way that capturing data with SQLite default unfortunately usually always fails… This sucks because the data science integration use

In my career I have analyzed a lot of data, and I’ll occasionally work with including large sqlite databases of cleaned up and/or transformed data subsets and ready for modeling, and have rarely had problems with them.

Out of curiosity do you happen to know why in HA this happens (excluding things like power failures causing corruption, etc).?

Well I think people are playing nice! I did say if you want to keep data you need to use something like influxdb. The standard database does seem to need to be deleted whenever you for example restore a snapshot. I chose to delete mine this week because I missed that the mariadb had changed the encoding… last week I found lots of entities were not updating probably because of that etc… anyway my database has nothing I NEED otherwise I’d be using influxdb to read in stuff I care about.

I tend to think it’s because it doesn’t shut down recorder when you make snapshots etc so you get a corrupted db but that’s just a guess. They also update and change the database schema a fair bit as well so maybe that can lead to corruption as well…

1 Like

all these people complaining about corrupt database… SQLite has BEGIN TANSACTION and COMMIT. EXT4 Filesystem is transactional and known good. The only problem could be improper SQLite transactions, eg. some atomic transfer is not being done atomically. Someone should figure out which transaction is causing the error, then look at the code that made that transaction.

1 Like

Thanks allot for this, worked perfect after migrating from Debian10 to HassioOS but my database from the snapshot got corrupted. Life saver!

Thanks, this was the trick that worked for me! :wink:

Thanks for the solution! It seems to work over here, my pi doesn’t disappear every 2 days…

:woman_cartwheeling:

You should change the last line of dump: ROLLBACK --> COMMIT
Without this action you get a new empty database.

Worked for me.
Thanks.

How to do it? How do I stop the supervised HA Docker and performe these commands?
Can you help me?

I just did as instructed in this thread.
Prior to do anything I downloaded sqlite CLI for windows from https://www.sqlite.org/download.html
Then I followed these steps :

  1. Stop HA via the SSH CLI using hassio core stop (I used a display and keyboard connected to the RPI4, login root, empty psswd))
  2. Move home-assistant_v2.db to my windows computer using samba (Windows 10 \HOMEASSISTANT\config)
  3. perform sqlite3 ./home-assistant_v2.db “.recover” | sqlite3 ./home-assistant_v2.db.fix (Windows 10 CMD)
  4. move home-assistant_v2.db.fix back using samba (Windows 10)
  5. rename the db-file (remove the .fix part)
  6. re-start HA via the SSH CLI using hassio ha start (RPI4)

Hope this helps.

1 Like