Fix A Corrupt SQLite Database

I have a Photoprism instance inside a standard Docker container that’s been throwing errors:

Error: database disk image is malformed

First, shut down the application you’re attempting to repair:

#docker-compose stop

To let SQLite 3 attempt a fix, find your index.db file (or whatever it’s named for whatever application you’re having issues with) and run:

# sqlite3 index.db ".recover" | sqlite3 new.db

The script will automatically parse and attempt to recover the data from the original database and dump it to “new.db”.

Just rename the old database and move the new one into it’s place:

# mv broken.db broken.db.old
# mv new.db index.db

Bring the app back up:

# docker-compose -d up

References:

https://stackoverflow.com/questions/18259692/how-to-recover-a-corrupt-sqlite3-database