multithreading - SQLITE3 CLSQL multithreaded insert results in error -


i want use sqlite3 database multiple threads in parallel. read using connection pools makes access threadsafe still errors while inserting data.

(make-thread    #'(lambda()        (dotimes (i 100)           (with-database (db ("/path/to/db")                           :database-type :sqlite3 :pool t)             (do-stuff-with db))))) 

when using multiple threads in fashion in error

while accessing database # expression "insert ...": error 5 / database locked

is possible multi threaded insert sqlite3 database? if yes how?

sqlite not support concurrency of multiple write transactions. sqlite site:

sqlite supports unlimited number of simultaneous readers, allow 1 writer @ instant in time. many situations, not problem. writer queue up. each application database work , moves on, , no lock lasts more few dozen milliseconds. there applications require more concurrency, , applications may need seek different solution.

cl-sql has been written give "unified" interface typical client-server relational dbms, other "standardized" libraries (e.g. jdbc or odbc), sqlite "untypical" database management system: in practice library offers sql language access simple "database-in-a-file", , few other functionalities of dbmss. instance, has no real concurrency control (it uses operating systems functions lock db file), cannot considered "real" dbms, , cl-sql cannot offer nothing more functionalities of underlying system.

so, if need concurrent insertions database, should use else, instance postgresql.


Comments