Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8221143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T13:48:07+00:00 2026-06-07T13:48:07+00:00

Recently, we encountered a dead lock problem. Two part of our system will update

  • 0

Recently, we encountered a dead lock problem. Two part of our system will update the same table in similar time, one update (name it “UP1”) several rows in a transaction, and the other(name it “UP2”) use a sql like “update … where id in (…)”.

It seems like it’s because that, the ids in sql “update … where id in (…)” are out of order,e.g. “5,6,2,3,4,1”; and in the transaction, update action will act in this order “1,2,3,4,5,6”. When “UP1” update the id “1,2,3,4” and the “UP2” update id “5,6”, the “UP1” want the id 5 which is locked by “UP2”, and the “UP2” want the id 2 which is locked by the “UP1”, so the dead lock comes out.

My question is, is the db lock rows one by one, and only release them when the sql or transaction is done? If not, why can not lock all the rows at the beginning of transaction or the “where id in (…)” sql, and why can not they release the updated row one by one?

Look forward to any helpful replies, thx.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T13:48:09+00:00Added an answer on June 7, 2026 at 1:48 pm

    You are pretty much on the right track. With the default Read Committed Isolation Level PostgreSQL acquires locks along the way and releases them when the transaction is committed or rolled back.

    If you can make sure that all UPDATE operations update rows in the same order you will never run into deadlocks. Have you tried to making UP1 update rows in ascending order and sorting the IN list for UP2 the same way?

    If you cannot guarantee synchronized updates, you may be interested in the Serializable Isolation Level. It is the strictest isolation level and may slow down your queries a bit, especially under heavy concurrency. But it should prevent the errors you see. Also, be prepared to retry transactions due to serialization failures.

    For this, start your transaction with:

    BEGIN ISOLATION LEVEL SERIALIZABLE;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've recently encountered a problem, and despite coming across similar questions here alreadt, none
I recently encountered a problem with my Profile provider: it wouldn't retrieve profiles correctly
I've recently encountered a problem designing a web page. I needed to have rounded
I've recently begun learning C# but have encountered an annoying problem. Every variable I
We recently encountered a problem where a merge somehow led to all the changes
I recently encountered a strange problem on my website. Images with æ ø and
I recently encountered a problem in my production database due to MySQL bug. The
I've recently encountered the error: System.Data.SqlClient.SqlException: The transaction log for database 'mydatabase' is full.
I recently encountered very strange behaviour with the UIImagePickerController. On our main view we
I recently encountered a problem in my website - some users do not have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.