SQLite – Fix for “Result: database disk image is malformed”

The database for my hot tub was returning IO errors and when I tried to use the VACUUM command, it returned an error:

Result: database disk image is malformed

Let’s fix this!

This is caused by some write corruption of the database. Easiest fix is to export all the data, recreate a new database and then copy over the old database. We can do this in two lines on the command:

  1. cd into the location of the database
  2. Backup your database
  3. Run this series of commands

sqlite3 databasename.db '.dump' | sqlite3 databasename.db.new
mv databasename.db.new databasename.db

That’s it!

Related posts