Support setting a timeout for SQLite
See original GitHub issueProblem
SQLite queries fail immediately if the DB is locked.
I blindly tried passing arguments similarly to how the docs show for PostgreSQL, needless to say, it didn’t work.
datasource db {
provider = "sqlite"
url = "file:../db.sqlite?timeout=5000"
}
Issue Analytics
- State:
- Created 3 years ago
- Reactions:9
- Comments:73 (31 by maintainers)
Top Results From Across the Web
Set A Busy Timeout - SQLite
This routine sets a busy handler that sleeps for a specified amount of time when a table is locked. The handler will sleep...
Read more >Increase the lock timeout with sqlite, and what is the default ...
The sqlite3 command line shell has the normal Sqlite default of 0; that is to say, no timeout. If the database is locked,...
Read more >How do I specify a timeout in sqlite3 from the command-line?
You can do this by using an init file. init.sql (note that the timeout value is in milliseconds - 1 is rather short):...
Read more >.timeout - Using SQLite [Book] - O'Reilly
The .timeout command is used to set a retry timer. If a timer value is set and a locked database is encountered, rather...
Read more >SQLite3::busyTimeout - Manual - PHP
The milliseconds to sleep. Setting this value to a value less than or equal to zero, will turn off an already set timeout...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@pimeys thank you for taking the time to respond.
Agreed. But let me preface our future discussion by saying I’m not just using SQLite for the fun of it. I’ve used it in the past and have studied it’s capabilities and limitations.
That is not entirely correct, SQLite can handle multiple readers quite well.
I think you might be mistaken here. SQLite directly supports a “busy timeout”. See docs
Also the sqlite3 npm package supports the timeout as well. See docs
I can only assume that prisma could do something similar.
I work with small companies, usually developing in-house software to be used by at most 5-10 people. SQLite is more than capable of keeping up. And in “production” prisma is the only process that will be communicating with the DB in the vast majority of all cases.
However, if I need to do any maintenance of any kind. I can cause the DB to start throwing BUSY errors. It’s not a problem for the DB to just wait a few seconds. Hence, why I am trying to set a timeout.
The program having to wait is very acceptable in this case, but the busy errors are troublesome.
Is there any other way I can set the timeout?
I also thought it worth sharing that I’ve found this issue as well through a different path. I tried out Blitz on the weekend and spun up a demo project with SQLite and it was mostly a really good experience.
However the first thing I did was set up a database seed file per their guide here
And of course, I had a few dozen things to create to I wrapped them in an
await Promise.all(...)
statement, which would have tried to run multiple concurrent operations through the same Prisma Client (this is all in a single thread running on my dev machine)And as soon as you get to about three things happening in parallel (specifically, create statements) the database throws with
Operation timed out (SQLite database is busy)
I mention this mainly because it’s a weird/hard block to hit in the first experience, given I was following the documented “happy path” for both Prisma and Blitz.
I was able to work around the problem by rewriting my code to create entries in the database sequentially (using a
for ...
loop and asyncawait db.thing.create()
call in each iteration) but ideally either Prisma Client or the SQLite settings would sort this out for me.cc/ @flybayer because it impacts Blitz getting started experience