Search code examples
rubysqlitesequel

How to unlock sqlite3 DB after a power off / hard crash?


sqlite 3.8.5 on OSX.

I had a Ruby program inserting rows into a sqlite3 database when the power went out. The directory now has the database, journal, and a lock file. When I use the console to access the DB, all commands are rejected with "error: database is locked" so I can't access it.

According to all of my googling, the next time the DB is opened by a sqlite3 process then the journal should be replayed or rolled back. However, this is clearly not happening (the journal size doesn't change and the lock file remains).

How can I get this DB back?


Solution

  • When you have configured SQLite to use dot-file locking (instead of the default POSIX advisory locks), the locks cannot be cleaned up by the OS automatically, because the lock files look like normal files to the OS.

    If you're sure that the application that created the lock is no longer running, just delete the lock file.

    (Never ever delete the journal file manually.)