Comments (7)
@benbjohnson I have something you can try and that should work:
Try setting the following environment variable PRISMA_SCHEMA_DISABLE_ADVISORY_LOCK=1
? (any truthy value will do)
Since PRAGMA main.locking_mode=EXCLUSIVE
is only set for the advisory locking, disabling it should do the trick.
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!
from prisma-engines.
Hi @benbjohnson!
Thanks for the question and investigation ✨
I'll add a reference to the SQLite docs about the locking_mode
for some context, which is quite good!: https://www.sqlite.org/pragma.html#pragma_locking_mode
In NORMAL locking-mode (the default unless overridden at compile-time using SQLITE_DEFAULT_LOCKING_MODE), a database connection unlocks the database file at the conclusion of each read or write transaction. When the locking-mode is set to EXCLUSIVE, the database connection never releases file-locks. The first time the database is read in EXCLUSIVE mode, a shared lock is obtained and held. The first time the database is written, an exclusive lock is obtained and held.
Database locks obtained by a connection in EXCLUSIVE mode may be released either by closing the database connection, or by setting the locking-mode back to NORMAL using this pragma and then accessing the database file (for read or write). Simply setting the locking-mode to NORMAL is not enough - locks are not released until the next time the database file is accessed.
There are three reasons to set the locking-mode to EXCLUSIVE.
- The application wants to prevent other processes from accessing the database file. - The number of system calls for filesystem operations is reduced, possibly resulting in a small performance increase. - [WAL](https://www.sqlite.org/wal.html) databases can be accessed in EXCLUSIVE mode without the use of shared memory. ([Additional information](https://www.sqlite.org/wal.html#noshm))
About why, we added advisory locking is because we wanted to have a safe / reliable execution of migrations. By default, multiple processes like prisma migrate dev
or prisma migrate deploy
could be running at the same time, as a result the migrations could be unpredictable and fail, and if that happens on a "production" database, that can cause some problems.
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!
from prisma-engines.
hey @Jolg42
I tried adding PRISMA_SCHEMA_DISABLE_ADVISORY_LOCK=1
and running LiteFS 0.5.11, it does resolve fuse: write(): wal error: wal header: cannot write to WAL header without WRITE lock, exclusive locking not allowed
issue.
But I'm not sure what the consequence of disabling that is; if I run those prisma
commands one at a time and only have one CI pipeline running at a time, it should be fine, right?
thank you!
from prisma-engines.
The advisory lock mechanism is only there to prevent concurrent use of Prisma Migrate (so prisma db push
& prisma migrate *
commands).
If you set the env var to disable the advisory locking, and you know that these commands will not run concurrently on your SQLite database, it will be fine!
from prisma-engines.
By the way, it looks like the error message is from superfly/litefs#426
So you can try using PRISMA_SCHEMA_DISABLE_ADVISORY_LOCK=1
and running this SQL once
PRAGMA locking_mode = NORMAL
from prisma-engines.
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 😎
from prisma-engines.
That request is being tracked here: prisma/prisma#3786 Leave a 👍 reaction on the issue if you haven't.
from prisma-engines.
Related Issues (20)
- [DA] Planetscale engine tests: oids HOT 1
- [DA] Planetscale engine tests: prisma_17103::regression HOT 3
- [DA] Planetscale engine tests: nested_createmany_fail_dups HOT 1
- [DA] Planetscale engine tests: one2m_mix_required_writable_readable HOT 2
- [DA] Planetscale engine tests: gracefully_fails_when_uniq_violation HOT 1
- [DA] Planetscale engine tests: create_many_error_dups HOT 1
- [DA] Planetscale engine tests: apply_number_ops HOT 1
- [DA] Planetscale engine tests: upsert_fails_if_filter_dont_match HOT 1
- psl: Can not get documentation from model when these is a empty line. HOT 5
- Using `createMany` with SQLite in tests results in a panic with JSON protocol HOT 4
- `expected value at line 1 column 1` on overriden datasources with some connection strings HOT 4
- GraphQL playground equivalent for JSON protocol
- Binary engine: `--enable-playground` should imply `--engine-protocol graphql`
- Publish crates to crates.io HOT 13
- Avoid intermediary reads when doing nested updates
- How to start prisma engine
- Unify `native` and `all` features naming
- can we support batch updateManyX interface?
- How to support other databases, such as Dameng? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from prisma-engines.