Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to open a locked sqlite database in read only mode?

I'd like to open the chromium site data (in ~/.config/chromium/Default) with python-sqlite3 but it gets locked whenever chromium is running, which is understandable since transactions may be made. Is there a way to open it in read-only mode, ensuring that I can't corrupt the integrity of the db while chromium is using it?

like image 616
ladaghini Avatar asked Oct 22 '11 06:10

ladaghini


2 Answers

I believe it depends on the lock set by the transaction.

http://www.sqlite.org/lockingv3.html#shared_lock http://www.sqlite.org/lang_transaction.html

SQLite exclusive transactions lock both read and write where immediate and deferred transactions will still allow readers.

So it really depends on the transactions used by Chromium.

like image 102
NtscCobalt Avatar answered Sep 22 '22 00:09

NtscCobalt


Chromium is holding a database lock for long periods of time? Yuck! That's really not a very good idea at all. Still, not your fault…

You could try just copying the database file (e.g., with the system utility cp) and using that snapshot for reading purposes; SQLite keeps all its committed state in a single file per database. Yes, there's a chance of seeing a partial transaction, but you will definitely not have lock problems on Unix as SQLite definitely doesn't use mandatory locks. (This might well not work on Windows due to the different locking scheme there.)

like image 42
Donal Fellows Avatar answered Sep 24 '22 00:09

Donal Fellows