-
Notifications
You must be signed in to change notification settings - Fork 243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Why use exclusive locking mode in SQLite? #4675
Comments
Hi @benbjohnson! Thanks for the question and investigation ✨ I'll add a reference to the SQLite docs about the
About why, we added advisory locking is because we wanted to have a safe / reliable execution of migrations. By default, multiple processes like So by making sure that only one process can actually run migrations, we can guarantee a default safety. Now, I don't think all use cases were thought of regarding SQLite at the time, the thinking at the time was how to manage a local SQLite database (without any replication), so your questions are great! |
@benbjohnson I have something you can try and that should work: Try setting the following environment variable See https://www.prisma.io/docs/orm/prisma-migrate/workflows/development-and-production#advisory-locking I'm curious if that works well for you or not, let us know! |
hey @Jolg42 I tried adding But I'm not sure what the consequence of disabling that is; if I run those thank you! |
The advisory lock mechanism is only there to prevent concurrent use of Prisma Migrate (so |
By the way, it looks like the error message is from superfly/litefs#426 PRAGMA locking_mode = NORMAL |
Thank you for asking this @benbjohnson, just saved me from being stuck unable to migrate with prisma on litefs cloud :) All I had to do was set that env variable and now prisma migrations work on my primary node. It would be super awesome if prisma added json support to sqlite now that it can run migrations and everything else without issues on fly 😎 |
That request is being tracked here: prisma/prisma#3786 Leave a 👍 reaction on the issue if you haven't. |
Hello! I'm the author of a tool called LiteFS which does real-time SQLite replication and it uses the SQLite locking protocol to detect transaction boundaries. Because of this, we prevent use of the WAL journaling mode while exclusive locking mode is enabled since it removes intermediate locking during transactions.
I was surprised to find that Prisma always uses exclusive locking mode and I was wondering why? I tried to do some digging and it seems like it was added in PR #1479 which fixes issue #1118 (advisory locking). However, in the issue itself it states that SQLite is a single writer and doesn't need to do advisory locking.
Beyond my specific use case, exclusive locking can cause other issues such as blocking migrations while other processes are using the SQLite database.
Would you consider removing exclusive locking mode or making optional?
Thank you.
The text was updated successfully, but these errors were encountered: