Re: How to open an sqlite3 for reading without being blocked by process writing to it?

Simon Slavin <[email protected]> Mon, 9 Mar 2020 04:09:23 +0000
Newsgroups gmane.comp.db.sqlite.general
Message-ID <[email protected]>
[This explanation is much simplified for clarity.  Before filling in missing details please consider what the OP wants.  Don't just show off your exhaustive knowledge of SQLite.]

A database is normally in delete journal mode, as if you'd executed

PRAGMA journal_mode=DELETE

In this journal mode you can't read from a database which is being changed.  If one process is changing the database it has the database locked.  Another process cannot read it until it is unlocked.  Because the reading process might read some of the row before it is changed, and the rest of the row after it is changed.

To fix this, change the journal mode to WAL:

PRAGMA journal_mode=WAL

In this mode one process can read a database while another process is changing it.  The process that reads the database gets the data as it was before the change.

For further details see

<https://sqlite.org/wal.html>
_______________________________________________
sqlite-users mailing list
[email protected]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users