Re: algo for canceling a deadlocked transaction

From: Thomas Poty <thomas(dot)poty(at)gmail(dot)com>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: algo for canceling a deadlocked transaction
Date: 2018-04-09 14:33:29
Message-ID: CAN_ctniAhCaDdTdmtvr9u37dsp7W9nt49bOS6uGoMV7Z4g9tJg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello Stephen,

> The short answer is "it's whichever one detected the deadlock." The
> deadlock timeout fires after a lock has been held that long and if a
> deadlock is detected then the process detecting it will be canceled.

ok, and long answer ? is it random?

> I'd strongly recommend reviewing your application and addressing
> deadlocks by changing how the application acquires locks to be
> consistent and to avoid lock escalation instead of worrying about how to
> predict a deadlock- a properly designed and written application
> shouldn't be causing deadlocks to happen in the first place.

I didn't want to predict the deadlock happening. I only want to know if it
is predictable to know which transaction will be canceled.

Thank you

2018-04-09 15:51 GMT+02:00 Stephen Frost <sfrost(at)snowman(dot)net>:

> Greetings,
>
> * Thomas Poty (thomas(dot)poty(at)gmail(dot)com) wrote:
> > My question is : In case of a deadlock between 2 transaction, how to
> know
> > which transaction will be canceled? Is it predictable?
>
> The short answer is "it's whichever one detected the deadlock." The
> deadlock timeout fires after a lock has been held that long and if a
> deadlock is detected then the process detecting it will be canceled.
>
> I'd strongly recommend reviewing your application and addressing
> deadlocks by changing how the application acquires locks to be
> consistent and to avoid lock escalation instead of worrying about how to
> predict a deadlock- a properly designed and written application
> shouldn't be causing deadlocks to happen in the first place.
>
> Thanks!
>
> Stephen
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Christophe Pettus 2018-04-09 14:42:24 Re: algo for canceling a deadlocked transaction
Previous Message David G. Johnston 2018-04-09 14:33:12 Re: Conflict between JSON_AGG and COPY