From SQLite FAQ I've known that:
Multiple processes can have the same database open at the same time. Multiple processes can be doing a
SELECTat the same time. But only one process can be making changes to the database at any moment in time, however.
So, as far as I understand I can:
1) Read db from multiple threads (
2) Read db from multiple threads (
SELECT) and write from single thread (
But, I read about Write-Ahead Logging that provides more concurrency as readers do not block writers and a writer does not block readers. Reading and writing can proceed concurrently.
Finally, I've got completely muddled when I found it, when specified:
Here are other reasons for getting an SQLITE_LOCKED error:
- Trying to
DROPa table or index while a
SELECTstatement is still pending.
- Trying to write to a table while a
SELECTis active on that same table.
- Trying to do two
SELECTon the same table at the same time in a multithread application, if sqlite is not set to do so.
- fcntl(3,F_SETLK call on DB file fails. This could be caused by an NFS locking issue, for example. One solution for this issue, is to mv the DB away, and copy it back so that it has a new Inode value
So, I would like to clarify for myself, it is necessary to avoid the lock? Can I read and write at the same time from two different threads? Thanks.