SQLite Forum

Option to open a database as read-only despite locked.
Login

Option to open a database as read-only despite locked.

(1) By gordon on 2022-05-04 22:04:13 [link] [source]

Sometimes, I would like to browse the "places.sqlite" file of my web browser, but if the browser is running, I get "Error: database is locked".

One could copy the database file somewhere else, but that is less convenient.

I suggest SQLite to at least attempt to read the data while still warning the user that the database is locked.

(2) By Ben Harris (bjh21.me.uk) on 2022-05-08 15:12:09 in reply to 1 [source]

You can do this using a URI filename:

sqlite3 'file:places.sqlite?mode=ro&nolock=1'

That opens the file places.sqlite in read-only mode with locking disabled. This isn't safe, in that changes to the database made by other corrections are likely to cause this connection to return incorrect results or crash. Read-only mode should at least mean that you don't corrupt the database in the process.

(3) By Simon Willison (simonw) on 2022-05-17 19:48:17 in reply to 2 [link] [source]

Thanks for this! Just added a --nolock feature to my Datasette application for browsing SQLite databases thanks to your tip, issue here: https://github.com/simonw/datasette/issues/1744

So now this works:

datasette ~/Library/Application\ Support/Google/Chrome/Default/History --nolock