Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple SQLite database instances open at the same time on different Threads (QT)

Is there any problem on using many open connections at the same time from different threads?

From what I've read it's thread safe by default, but, can this be hurting performance rather than improving it?

like image 267
Stephen H. Anderson Avatar asked Oct 19 '22 06:10

Stephen H. Anderson


1 Answers

Having multiple connection is not a problem, the only thing to keep in mind is that SQLite does not support concurrency of multiple write transactions. From the SQlite site:

SQLite supports an unlimited number of simultaneous readers, but it will only allow one writer at any instant in time. For many situations, this is not a problem. Writer queue up. Each application does its database work quickly and moves on, and no lock lasts for more than a few dozen milliseconds. But there are some applications that require more concurrency, and those applications may need to seek a different solution.

SQLite is an "untypical" database management system: in practice it is a library that offers SQL as language to access a simple "database-in-a-file", and a few other functionalities of DBMSs. For instance, it has no real concurrency control (it uses the Operating Systems functions to lock the db file).

So, if you need concurrent insertions into a database, you should use something else, for instance PostgreSQL.

like image 71
Renzo Avatar answered Nov 17 '22 12:11

Renzo