How to fix a corrupted Lightroom catalog

I've had my Lightroom (latest version at the time, Lighroom CC 2015.12) catalog corrupted several (dozens) of times already. Usually the built-in repair dialogs saved me, but 2 times even that failed me. I already backup my catalog almost every single day (have set backup option to "Every time Lightroom exists", but cancel the backup when I don't actually change anything), but having a couple hundred edits lost was not acceptable for me, especially since I export and publish on this very site at least one photo every single day, and I wouldn't be able to reproduce it perfectly. So I looked for alternatives on the internet, and found this nice post. It was written for Mac, but I adopted it for Windows use and added one step to make it work for me. It shouldn't be too hard to adopt it for use on any other system.

Prerequisites: you will need Sqlite, you can get it from http://www.sqlite.org/download.html. I installed it under c:\Program Files\sqlite, if you install it somewhere else, change the path to it in the instructions below. I used version 3.19.3, any newer should do the trick.

  1. Open command prompt and navigate to your Lightroom catalog folder (usually C:\Users\username\Pictures\Lightroom, replace username with your actual username).
  2. Run
    echo .dump | "c:\Program Files\sqlite\sqlite3.exe" catalog.lrcat > catalog.sql
  3. open resulting catalog.sql in a serious text editor (not like Notepad, more like open source Notepad++), scroll to the very end and, if you find this line, remove it
    ROLLBACK -- due to errors
    and replace it with
    COMMIT; -- I want my catalog back, I don't care about errors
  4. Run
    "c:\Program Files\sqlite\sqlite3.exe" catalog_restored_again.lrcat < catalog.sql
  5. Open your freshly restored catalog in Lightroom and enjoy.

NOTE that on the third step (which was missing from the original instructions) you are ignoring any errors that occured during the exporting from your corrupted catalog, which means some data might have been lost. It might be prudent to export all your changes since the last backup in a temporary catalog and import that one into your last backed-up catalog, but I never bothered with that, only kept the last backup around just in case.