Re: libpq async duplicate error results

From: Peter Eisentraut <peter(dot)eisentraut(at)enterprisedb(dot)com>
To: Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: libpq async duplicate error results
Date: 2022-01-27 09:40:18
Message-ID: f9c3ea51-ae67-358b-6e50-f52ed8142bf8@enterprisedb.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 26.01.22 14:52, Fabien COELHO wrote:
>
>> command = SELECT pg_terminate_backend(pg_backend_pid());
>> result 1 status = PGRES_FATAL_ERROR
>> error message = "FATAL:  terminating connection due to administrator
>> command
>> "
>> result 2 status = PGRES_FATAL_ERROR
>> error message = "FATAL:  terminating connection due to administrator
>> command
>> server closed the connection unexpectedly
>>     This probably means the server terminated abnormally
>>     before or while processing the request.
>> "
>
>> Also, why are there multiple results being generated in the first place?
>
> My interpretation is that the first message is a close message issued by
> the server before actually severing the connection, and the second
> message is generated by libpq when it notices that the connection has
> been closed, so there is some sense in having to results to report these
> two consecutive errors, and the question might be about when the buffer
> should be reset.

I see. If we stipulate for a moment that getting two results is what we
want here, I see a conceptual problem. Users of PQexec() don't care
whether the error message they are ultimately getting is a concatenation
of two messages from two internal results (old behavior) or just an
appropriately accumulated message from the last internal result (new
behavior). But users of PQgetResult() don't have a principled way to
deal with this anymore. They can't just ignore one or the other result,
because they could after all be two separate errors from two separate
commands. So the only proper behavior is to show all errors from all
results. But that results in this misbehavior because the last error
message must include the messages from the previous messages in order to
accommodate PQexec() users.

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Sergey Dudoladov 2022-01-27 09:53:32 Re: Is there a way (except from server logs) to know the kind of on-going/last checkpoint?
Previous Message Kyotaro Horiguchi 2022-01-27 08:50:25 Re: pgbench: using prepared BEGIN statement in a pipeline could cause an error