3 ms·
My experience is that it is only safe to have one connection to a SQLite database. Having multiple connections mostly works, however if the database is stored o
by tyilo 5y ago
My experience is that it is only safe to have one connection to a SQLite database.
Having multiple connections mostly works, however if the database is stored on a slow medium, such as an SD-card, concurrent queries will fail.
- stavros 5y agoHmm, fail completely, or just block?
- tyilo 5y agoOne the queries will fail with something like SQLITE_BUSY
- benbjohnson 5y agoYou need to explicitly set the “busy_timeout” PRAGMA to allow concurrent write queries to block under WAL mode. Otherwise the query will return a BUSY error. I wrote up some tips/caveats on the Litestream site with more explanation. https://litestream.io/tips/ https://litestream.io/tips/ Generally there’s just a few settings you want to set when developing with SQLite: PRAGMA journal_mode = wal; PRAGMA busy_timeout = 5000; Also worth setting STRICT mode and setting SYNCHRONOUS to NORMAL but those are less important.