🌐
GitHub
github.com › prisma › prisma › issues › 3088
Allow for locking of the database. · Issue #3088 · prisma/prisma
July 20, 2020 - Problem I need to be able to create a row in a table based on information of whether a similar row exists or not: Lock table for creation Check if similar row exists If similar row exists, create it and mark it as similar. Else, create i...
Author   prisma
🌐
GitHub
github.com › prisma › prisma › issues › 17136
Row locking support in `find*()` queries (via `FOR UPDATE`) · Issue #17136 · prisma/prisma
January 4, 2023 - If we could avoid it by locking the row, that would be great. function deactivate() { const user = await prisma.$transaction(async tx => { const user = await tx.user.findUnique({ where: { id: user.id } }); if (user.status !== 'ACTIVE') { throw new Error('User not active ...'); } // some business processing (not long transaction) return tx.user.update({ where: { id: user.id } }, data: { status: 'DELETED' }); }); await doAfterCommitProcessing(user); }
Author   prisma
Discussions

node.js - Row level locking with Prisma and PostgreSQL - Stack Overflow
I’m building an anonymous chat app for learning purpose where users are matched based on gender preferences. The application allows users to go online and be matched with another online user if their More on stackoverflow.com
🌐 stackoverflow.com
Row update with DB Row Lock (SELECT FOR UPDATE)
Problem There's an entire class of DB mutations that can be affected by race conditions. An example is incrementing a value by one. So when updating a row, we need a way to acquire a DB row loc... More on github.com
🌐 github.com
9
March 24, 2020
postgresql - supabase: `prisma migrate dev` sometimes times out (postgres advisory lock) - Stack Overflow
Prisma uses a PostgreSQL advisory lock with the magic number ID 72707369 that blocks a new migration if the previous one is still connected and idle. This kind of lock only releases when the connection is fully closed and removed from the table pg_stat_activity (an internal PostgreSQL table ... More on stackoverflow.com
🌐 stackoverflow.com
sql - Does Prisma support select with "with (nolock)"? - Stack Overflow
If your ORM doesn't directly support ... applying locking hints (and I don't know if it doesn't, but it would not be surprising) you can also start a transaction under isolation level READ UNCOMMITTED, which has largely the same effect (except that it applies to all tables used in the transaction). ... No, Prisma doesn't support ... More on stackoverflow.com
🌐 stackoverflow.com
July 14, 2022
🌐
Stack Overflow
stackoverflow.com › questions › 75827244 › how-to-use-postgres-prisma-as-a-queue-preventing-workers-from-selecting-alrea
postgresql - How to use Postgres / Prisma as a queue, preventing workers from selecting already selected rows - Stack Overflow
I'm using Prisma so I'm not sure of the underlying SQL in Postgres but I'm doing all of my calls inside a transaction and setting the transaction isolation level to 'Serialized', which correctly fails due to a write conflict. I've looked into 'ACCESS EXCLUSIVE' lock in Postgres but doesn't this lock the entire table ...
🌐
Stack Overflow
stackoverflow.com › questions › 78962255 › row-level-locking-with-prisma-and-postgresql
node.js - Row level locking with Prisma and PostgreSQL - Stack Overflow
Database Table: model User { id String @id @default(uuid()) currentChatPartner String? gender String? preferGender String? lastMatch String? currentCountry String? ageRange String? createdAt DateTime @default(now()) report Int @default(0) online Boolean? } Matching Algorithm: async findMatch(id: string): Promise<User[] | null> { return await prisma.$transaction(async (tx) => { // Lock the current user const [user] = await tx.$queryRaw<User[]>` SELECT * FROM "User" WHERE "id" = ${id} FOR UPDATE `; // Ensure the user exists if (!user) throw new Error("User not found"); // Lock the potential matc
🌐
Medium
medium.com › @mgoku0707 › concurrency-control-in-node-js-and-prisma-managing-simultaneous-updates-56b9f17859e5
Concurrency Control in Node.js and Prisma: Managing Simultaneous Updates | by Gokul Mahendiran | Medium
March 7, 2024 - await prisma.$executeRaw`BEGIN; LOCK TABLE your_model_name IN SHARE MODE; UPDATE your_model_name SET /* updated fields */ WHERE id = recordId; COMMIT;`;
🌐
GitHub
github.com › prisma › prisma › issues › 1918
Row update with DB Row Lock (SELECT FOR UPDATE) · Issue #1918 · prisma/prisma
March 24, 2020 - So when updating a row, we need a way to acquire a DB row lock to prevent these types of race conditions. I think this could be a good solution. If data is a function, then SELECT FOR UPDATE is used. await prisma.counter.update({where: {id: 1}, data: counter => ({value: counter.value + 1})}) Or accept the above arguments with a new API like prisma.count.updateWithLock() Reactions are currently unavailable ·
Author   prisma
🌐
Prisma
prisma.io › home › transactions and batch queries › transactions and batch queries › transactions and batch queries › transactions and batch queries
Transactions and batch queries (Reference) | Prisma Documentation
December 22, 2022 - Avoiding locks in an application with a high number of concurrent requests makes the application more resilient to load and more scalable overall. Although locking is not inherently bad, locking in a high concurrency environment can lead to unintended consequences - even if you are locking individual rows, and only for a short amount of time.
🌐
Stack Overflow
stackoverflow.com › questions › 72982002 › does-prisma-support-select-with-with-nolock
sql - Does Prisma support select with "with (nolock)"? - Stack Overflow
July 14, 2022 - If your ORM doesn't directly support ... applying locking hints (and I don't know if it doesn't, but it would not be surprising) you can also start a transaction under isolation level READ UNCOMMITTED, which has largely the same effect (except that it applies to all tables used in the transaction). ... No, Prisma doesn't support ...
Find elsewhere
🌐
Answer Overflow
answeroverflow.com › m › 1299770877004746764
Row locking on prisma suggestions - Prisma
October 26, 2024 - Hi, I have been using Prisma to develop a text based game, this has been going very smooth. However I have been stumbling on some very big issues for concurrent updates on certain rows e.g. auction, withdraw, depositing, where my players can get under their balance if they click very fast, which results in a - balance and offcourse unwanted results. I was able to solve this with raw sql row locking, see picture.
🌐
Medium
medium.com › @connect.hashblock › 10-prisma-transaction-patterns-that-avoid-deadlocks-4f52a174760b
10 Prisma Transaction Patterns That Avoid Deadlocks | by Hash Block | Medium
October 14, 2025 - Limit blast radius with timeouts, and consider advisory locks for cross-table invariants. Deadlocks aren’t a moral failing; they’re a coordination tax. Prisma gives us a great API, but the patterns above decide whether your service queues politely or snaps under pressure.
🌐
OneUptime
oneuptime.com › home › blog › how to implement optimistic locking with prisma in node.js
How to Implement Optimistic Locking with Prisma in Node.js
January 25, 2026 - When multiple users or processes try to update the same database record simultaneously, you can end up with lost updates or inconsistent data. Optimistic locking solves this by detecting conflicts at write time rather than holding locks during the entire transaction. In this guide, we will implement optimistic locking with Prisma in a Node.js application.
🌐
GitHub
github.com › prisma › migrate › issues › 425
Feature request: In-Database migration lock · Issue #425 · prisma/migrate
April 19, 2020 - Consider deploying a Node.js server twice (because of horizontal scaling; maybe load balancing), and both of them would call a prisma migrate up while deploying. What could happen now is that Node.js server 1 tries to migrate while Node.js server 2 also tries the same. This could maybe result in conflicts within the database. A "In-Database" migration lock on a table designed specifically for locking.
Author   prisma
🌐
Saigon Technology
saigontechnology.com › home › blog › database transaction and how to handle it in nodejs with prisma
Database Transaction And How To Handle It In NodeJS With Prisma
June 13, 2025 - This mechanism involves acquiring and releasing locks on database objects such as tables, rows, or columns to control access by concurrent transactions.
🌐
GitHub
github.com › prisma › prisma › issues › 5983
Add support for row-level locking (via `FOR UPDATE SKIP LOCKED`) · Issue #5983 · prisma/prisma
March 4, 2021 - I have a table that acts as a job queue. I want to read the first row where processed_at is null. There can be multiple workers reading from the same table. To ensure only a single worker is processing one job, I can use row-level lockin...
Author   prisma
🌐
Calderon Textiles
calderontextiles.com › products › prisma-table-cloth-black-8
Prisma® Table Cloth | Calderon Textiles
Prisma combines your most valued features: durability, colorfastness, and stain resistance. It is manufactured with a heavier fabric weight which enhances product life, and its Color Lock dyeing technology keeps fabric bright.
Top answer
1 of 2
1

I realized, that for your specific usecase you could also increment your incrementalReportNumber with an atomic number operation

This avoids the need for a stricter transaction isolation level, because you only run update queries and avoid all read queries:

 const report = await prisma.$transaction(async (prisma) => {
      const school = await prisma.school.update({
        where: { id: schoolId },
        data: {
          incrementalReportNumber: {
            // increment the report number here
            increment: 1,
          },
        },
      });

      const newReport = await prisma.report.create({
        data: {
          publicId: school.incrementalReportNumber,
          schoolId: school.id,
          name: reportName,
        },
      });

      return newReport;
    });
2 of 2
1

I think the issue here is with the transaction isolation level used by Prisma when running the query.

The default transaction isolation level in Postgres is "read committed", this is what Prisma uses and it does not prevent non-repeatable reads.

Non-Repeatable Reads

If you're not sure what non-repeatable reads are, I am adding a good explanation taken from here

"A non-repeatable read is one in which data read twice inside the same transaction cannot be guaranteed to contain the same value. Depending on the isolation level, another transaction could have nipped in and updated the value between the two reads.

Non-repeatable reads occur because at lower isolation levels reading data only locks the data for the duration of the read, rather than for the duration of the transaction"

In your case, the following race condition might be happening due to non-repeatable reads.

  1. Transaction B: Read school data with report number x and increment to x + 1.
  2. Transaction A: Read school data with report number x and increment to x + 1.
  3. Transaction B: Commit report number x + 1 to database.
  4. Transaction A: Attempt to create report with x+1 report number and fail.

Unfortunately, Prisma does not currently support changing the transaction isolation level. So, you might need to come to some other workaround for this issue (possibly even writing raw SQL code).

We have a feature request for exactly this and I would really urge you to comment your problem over there. That way it would help us track demand for this feature and incentivize adding it quickly.