Problem with error response message

Lists: pgsql-hackers
From: Tatsuo Ishii <ishii(at)postgresql(dot)org>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Problem with error response message
Date: 2012-05-22 11:59:57
Message-ID: 20120522.205957.2166675381012052857.t-ishii@sraoss.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hi,

ErrorResponse message from backend has some field type codes include:

S
Severity: the field contents are ERROR, FATAL, or PANIC (in an
error message), or WARNING, NOTICE, DEBUG, INFO, or LOG (in a
notice message), or a localized translation of one of
these. Always present.

C
Code: the SQLSTATE code for the error (see Appendix A). Not
localizable. Always present.

If severity is ERROR, current transaction is aborted but existing
session is continued. If it is FATAL or worse, backend disconnects the
current session, or even postmaster restarts all backends (which
results in session disconnection anyway). Cluster management tools
such as pgpool-II has to carefully handle the message because there's
big difference between just adborting transaction and disconnecting
session. In the former, pgpool just forwards the error message to
frontend, but for later, it should disconnect the session. For this
purpose, pgpool-II examines SQLSTAE code. Unfortunately some error
codes such as 40001(serialization_failure) comes with different
severities ERROR or FATAL.

Here are some examples:

./tcop/postgres.c- ereport(FATAL,
./tcop/postgres.c: (errcode(ERRCODE_T_R_SERIALIZATION_FAILURE),
./tcop/postgres.c- errmsg("terminating connection due to conflict with recovery"),
./tcop/postgres.c- errdetail_recovery_conflict()));

./commands/trigger.c- ereport(ERROR,
./commands/trigger.c: (errcode(ERRCODE_T_R_SERIALIZATION_FAILURE),
./commands/trigger.c- errmsg("could not serialize access due to concurrent update")));
./commands/trigger.c- if (!ItemPointerEquals(&update_ctid, &tuple.t_self))

So I tried to look into severity code to find if it is a fatal error
or not. Unfortunately it is almost impossible because it could be
localized. My question is, why we need to localize this? It shouldn't
be computer recognizable message?

Also I wonder why "conflict with recovery" generates same error code
as serialization error. For me it seems not very consistent
choice. IMO, we should assign different error code for at least brings
totally different effect to frontend: aborting transactions or
sessions.
--
Tatsuo Ishii
SRA OSS, Inc. Japan
English: http://www.sraoss.co.jp/index_en.php
Japanese: http://www.sraoss.co.jp


From: Simon Riggs <simon(at)2ndQuadrant(dot)com>
To: Tatsuo Ishii <ishii(at)postgresql(dot)org>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Problem with error response message
Date: 2012-05-22 17:55:41
Message-ID: CA+U5nMJdWPc=mOULf7Wf7GJfAfiPdN7FB8BC1ZU7kJiM+tq8Bg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 22 May 2012 12:59, Tatsuo Ishii <ishii(at)postgresql(dot)org> wrote:

> Also I wonder why "conflict with recovery" generates same error code
> as serialization error. For me it seems not very consistent
> choice. IMO, we should assign different error code for at least brings
> totally different effect to frontend: aborting transactions or
> sessions.

Some conflicts cause ERROR, some cause FATAL. So there is not a
distinct difference.

--
 Simon Riggs                   http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training & Services