While I was importing photos from a SD card in Shotwell, my laptop has crashed (shutdown because of over-heating). Now, I can no longer launch Shotwell:

$ shotwell
ERROR:x86_64-linux-gnu/db/VersionTable.c:104:version_table_construct: assertion failed: (res == SQLITE_OK)

If I move the .db file ~/.shotwell/data/photo.db elsewhere so it is no longer present (but backed-up), shotwell will launch, but will rebuild its library, which will be empty. I can re-import the folders shotwell creates, but I lose nearly all meta-data (most importantly the "folders", or events, and their main picture)

Is there a way to repair/rebuild/restore photo.db? How can I see what's inside? how bad it's damaged?

Or is there another way to get back my events and imports?

  • What version of Shotwell are you using? – MrEricSir Aug 23 '11 at 0:35
  • eric-yorba: Shotwell 0.9.3 – Yann Dìnendal Aug 23 '11 at 19:45

Shotwell's database can be corrupted due to kernel panics and loss of power.

With Shotwell 0.10 or above, the database is automatically backed up every time the program exits; in the worst case, you'd end up losing any work since you started the program.

Unfortunately, older versions of Shotwell don't have this feature and it's unlikely that you can recover from a corrupted database.

  • Ok, thank you. If I re-import from the folders created by Shotwell, what will I have lost? Only the events created? Is there something else in photo.db? I will keep the tags, meta-data and modifications made to the photos? – Yann Dìnendal Aug 24 '11 at 22:02
  • 1
    If you have Shotwell set to write metadata to your files, then you may have only lost events and modifications to photos made inside Shotwell. You can delete your ~/.shotwell directory to get rid of the database, then start all over by opening Shotwell again and reimporting everything from the Pictures directory (or wherever you keep your photos.) – MrEricSir Aug 24 '11 at 22:40
  • On more recent Ubuntu versions, the database photo.db will be located in "~/.local/share/shotwell/data". – rosch Nov 21 '15 at 21:56

You can find the backup database in your .shotwell folder in "home". There will be a photo.db.bak.

Just rename it to photo.db and delete the corrupt old "photo.db" and you should be fine again.


You can check the integrity of your database with the following command:

$ sqlite3 photo.db
SQLite version 3.7.4
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> pragma integrity_check;

If it reports an error, you may be able to recover the contents by dumping the data and restoring it into a new database:

$ echo .dump | sqlite3 photo.db > photo_dump.sql
$ sqlite3 new_photo.db < photo_dump.sql

Back up the original database and then move the new one into place and see how things go.

  • Thanks for your answer, but it didn't work. :/ sqlite> pragma integrity_check; Error: database disk image is malformed sqlite> – Yann Dìnendal Aug 23 '11 at 19:42
  • photo_dump.sql is nearly empty: PRAGMA foreign_keys=OFF; BEGIN TRANSACTION; COMMIT; – Yann Dìnendal Aug 23 '11 at 20:29
  • 1
    In that case, you probably won't be able to recover data from the file. You can find more information here: sqlite.org/faq.html#q21 . Starting over with a new database might be the only option at this point unfortunately. – James Henstridge Aug 24 '11 at 0:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.