Re: Deadlocks and transactions

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: JORGE MALDONADO <jorgemal1960(at)gmail(dot)com>
Cc: pgsql-novice <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Deadlocks and transactions
Date: 2018-03-19 22:18:37
Message-ID: CAKFQuwb3ZUnXhrdsm556tGZpEEL+J=cOqj+1MDh+VZb9fazrNA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

On Mon, Mar 19, 2018 at 2:46 PM, JORGE MALDONADO <jorgemal1960(at)gmail(dot)com>
wrote:

> I have a process that inserts a record in one table and, after that, a
> record in another table is updated. Because there are 2 DB operations, I
> decided to perform both of them in a transaction.
>
> Can a deadlock take place even if transactions are used?
>

Its impossible to deadlock without transactions​.

Simplistically, a deadlock happens when there are two processes - one holds
lock A and wants lock B while the other wants lock A while holding lock B.

Your choice to use a transaction here is good but you will have at least
some risk of deadlock with others parts of the system. Other processes
running this same exact code, however, should not pose a risk since the
locking order would be consistent.

David J.

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Lætitia Avrot 2018-03-20 09:01:03 Re: Deadlocks and transactions
Previous Message JORGE MALDONADO 2018-03-19 21:46:20 Deadlocks and transactions