]> git.ipfire.org Git - thirdparty/postgresql.git/commit
pgbench: Fix error reporting in readCommandResponse().
authorFujii Masao <fujii@postgresql.org>
Tue, 30 Sep 2025 14:55:02 +0000 (23:55 +0900)
committerFujii Masao <fujii@postgresql.org>
Tue, 30 Sep 2025 14:55:02 +0000 (23:55 +0900)
commitcb21e1f92fb3b9c2208611db8c7051660fc0afb2
treed3bd89524f8bddc45f5cb4646fb6329ef23969f5
parent5816baa9bcf3db6cb98e689dabe06276aa8fb3f2
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
src/bin/pgbench/pgbench.c