Re: ERRCODE_T_R_DEADLOCK_DETECTED

From: Kevin Grittner <kgrittn(at)ymail(dot)com>
To: Tatsuo Ishii <ishii(at)postgresql(dot)org>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: ERRCODE_T_R_DEADLOCK_DETECTED
Date: 2015-03-19 12:50:09
Message-ID: 648070815.508448.1426769409322.JavaMail.yahoo@mail.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Tatsuo Ishii <ishii(at)postgresql(dot)org> wrote:

> ereport(ERROR,
> (errcode(ERRCODE_T_R_DEADLOCK_DETECTED),
> errmsg("canceling statement due to conflict with recovery"),
> errdetail("User transaction caused buffer deadlock with recovery.")));
>
> ereport(ERROR,
> (errcode(ERRCODE_T_R_DEADLOCK_DETECTED),
> errmsg("deadlock detected"),
> errdetail_internal("%s", clientbuf.data),
> errdetail_log("%s", logbuf.data),
> errhint("See server log for query details.")));
>
> The latter is a normal deadlock and can be obseved by stats
> because pgstat_report_deadlock() is called.
>
> The former is using the same error code but the meaning is pretty
> different and users might be confused IMO.
>
> I am not sure sharing the same error code is the best idea here.

That SQLSTATE value is intended to be used where the transaction
has failed because it was run concurrently with some other
transaction, rather than before or after it; and it is intended to
suggest that the transaction may succeed if run after the competing
transaction has completed. If those apply, it seems like the right
SQLSTATE. A user can certainly distinguish between the conditions
by looking at the error messages.

For me the big question is whether software written to retry a
transaction from the beginning when it gets this SQLSTATE would be
doing something dumb to retry transactions (perhaps after a brief
delay) for the conflict with recovery. If using the same automated
recovery techniques is sane, then IMO it makes sense to use the
same SQLSTATE.

--
Kevin Grittner
EDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2015-03-19 13:09:22 Re: ERRCODE_T_R_DEADLOCK_DETECTED
Previous Message Robert Haas 2015-03-19 12:18:45 Re: Variable referencing itself in example of pgbench.sgml