Re: Understanding updates and deadlocks more clearly

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Wells Oliver <wells(dot)oliver(at)gmail(dot)com>
Cc: pgsql-admin <pgsql-admin(at)postgresql(dot)org>
Subject: Re: Understanding updates and deadlocks more clearly
Date: 2022-09-02 21:55:57
Message-ID: CAKFQuwa=H+t0Hk5+fCmfAwW1RPwHoRDUMavRO_OiuCLSrKQbpw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

On Friday, September 2, 2022, Wells Oliver <wells(dot)oliver(at)gmail(dot)com> wrote:

> Hey folks: I want to clarify a few things about locks on updates:
>
> 1- can two processes update the same table if they are updating different
> rows?
>
> 2- in the event of two processes trying to update the same row, does this
> always result in a deadlock?
>
> 3- is there a way to create a system whereby potentially concurrent
> processes can update the same row in a given table, can the server be made
> to queue those updates, etc?
>
> Is it just a no-go to try and have a situation where concurrent processes
> are trying to update the same record?
>
>

Processes wait to acquire the lock necessary for updating a row. While
they are waiting they still retain any locks they already hold. Deadlock
means someone who holds a lock you are waiting for presently is waiting for
a lock that the first someone holds. Thus they will wait forever unable to
acquire the lock held by the other.

It thus requires trying to update at least two different records arrived at
from different directions.

David J.

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Ron 2022-09-03 00:28:17 Re: Understanding updates and deadlocks more clearly
Previous Message Wells Oliver 2022-09-02 21:15:16 Understanding updates and deadlocks more clearly