2

Suppose that I have a huge SQLite file (say, 500[MB]). Can 10 different python instances access this file at the same time and update different records of it?. Note, the emphasis here is on different records.

For example, suppose that the SQLite file has say 1M rows:

instance 1 will deal with (and update) rows 0 - 100000

instance 2 will will deal with (and update) rows 100001 - 200000

.........................

instance 10 will deal with (and update) rows 900001 - 1000000


Meaning, each python instance will only be updating a unique subset of the file. Will this work, or will I have serious integrity issues?

2 Answers 2

4

Updated, thanks to André Caron.

You can do that, but only read operations supports concurrency in SQLite, since entire database is locked on any write operation. SQLite engine will return SQLITE_BUSY status in this situation (if it exceeds default timeout for access). Also consider that this heavily depends on how good file locking is implemented for given OS and file system. In general I wouldn't recommend to use proposed solution, especially considering that DB file is quite large, but you can try.

It will be better to use server process based database (MySQL, PostgreSQL, etc.) to implement desired app behaviour.

Sign up to request clarification or add additional context in comments.

3 Comments

The SQLite FAQ clearly explains that SQLite uses reader/writer locks, allowing concurrent access. Writes are serialized, but concurrency with write access is supported.
I agree, however, in general, concurrent write access to SQLite db is not very safe (depends how good is file locking is implemented for given OS and FS).
"entire database is locked on any write operation" is usually not for very long. Especially with journaling enabled, it's tens of milliseconds at most while the journal is flushed, and even then, reads should still succeed.
4

Somewhat. Only one instance can write at any single time, which means concurrent writes will block (refer to the SQLite FAQ). You won't get integrity issues, but I'm not sure you'll really benefit from concurrency, although that depends on how much you write versus how much you read.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.