pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Fujii Masao <fujii@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: pgbench: Fix error reporting in readCommandResponse().
Date: Tue, 30 Sep 2025 14:58:17 +0000
Message-ID: <E1v3bo0-000nXw-2W@gemulon.postgresql.org> (raw)

pgbench: Fix error reporting in readCommandResponse().

pgbench uses readCommandResponse() to process server responses.
When readCommandResponse() encounters an error during a call to
PQgetResult() to fetch the current result, it attempts to report it
with an additional error message from PQerrorMessage(). However,
previously, this extra error message could be lost or become incorrect.

The cause was that after fetching the current result (and detecting
an error), readCommandResponse() called PQgetResult() again to
peek at the next result. This second call could overwrite the libpq
connection's error message before the original error was reported,
causing the error message retrieved from PQerrorMessage() to be
lost or overwritten.

This commit fixes the issue by updating readCommandResponse()
to use PQresultErrorMessage() instead of PQerrorMessage()
to retrieve the error message generated when the PQgetResult()
for the current result causes an error, ensuring the correct message
is reported.

Backpatch to all supported versions.

Author: Yugo Nagata <nagata@sraoss.co.jp>
Reviewed-by: Chao Li <lic@highgo.com>
Reviewed-by: Fujii Masao <masao.fujii@gmail.com>
Discussion: https://postgr.es/m/20250925110940.ebacc31725758ec47d5432c6@sraoss.co.jp
Backpatch-through: 13

Branch
------
REL_13_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/7d7e81d1e6b8cff9b8e6047609df2b8fbf8d76f3

Modified Files
--------------
src/bin/pgbench/pgbench.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)



view thread (7+ messages)

Message-ID: <E1v3bo0-000nXw-2W@gemulon.postgresql.org>
Permalink:  ../E1v3bo0-000nXw-2W@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1v3bo0-000nXw-2W@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: fujii@postgresql.org, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: pgbench: Fix error reporting in readCommandResponse().
  In-Reply-To: <E1v3bo0-000nXw-2W@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox