pgpool: Fix do_query to send sync rather than flush.

From: Tatsuo Ishii <ishii(at)postgresql(dot)org>
To: pgpool-committers(at)lists(dot)postgresql(dot)org
Subject: pgpool: Fix do_query to send sync rather than flush.
Date: 2026-08-02 06:34:49
Message-ID: E1wqPma-0000000DiST-3DdJ@gothos.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgpool-committers

Fix do_query to send sync rather than flush.

When in extended query mode and no explicit transaction has started
(i.e. implicit transaction), do_query issues a flush message after
execute message. But this does not close the implicit transaction and
"DISCARD ALL" in reset_query_list failed with:

"DISCARD ALL cannot run inside a transaction block"

This could happen when query cache is enabled. After an execute and
sync are issued, pgpool generates internal query in extended query
mode using do_query:

SELECT oid FROM pg_catalog.pg_database WHERE datname = 'test'

Since do_query never issued a sync for this query, the implicit
transaction opened by do_query never closed and raised the error.

To fix the issue, send a sync message, rather than a flush message.
Sync will close the unamed portal in an implicit transaction. But to
run an unnamed portal, we need to issue bind message and re-create a
unnamed portal anyway.

Also 039.log_backend_messages regression test is adjusted.

Note: the author created the patch for fixing "idle in transaction"
left in pg_stat_activity, but I failed to reproduce the
issue. However, since I found the patch solves the issue above, I
decided to commit the patch anyway.

Author: Achilleas Mantzios <a(dot)mantzios(at)cloud(dot)gatewaynet(dot)com>
Reviewed-by: Tatsuo Ishii <ishii(at)postgresql(dot)org>
Discussion: https://www.postgresql.org/message-id/25939319-d77c-4df9-9e65-dfb1637ccd33%40cloud.gatewaynet.com
Backpatch-through: v4.3

Branch
------
master

Details
-------
https://git.postgresql.org/gitweb?p=pgpool2.git;a=commitdiff;h=e4a3a0c13e4b5e1a015aca3db238b21b88e73e2f

Modified Files
--------------
src/protocol/pool_process_query.c | 26 +++++++++-------------
.../tests/039.log_backend_messages/expected.s | 1 -
2 files changed, 10 insertions(+), 17 deletions(-)

Browse pgpool-committers by date

  From Date Subject
Next Message Tatsuo Ishii 2026-08-07 10:01:08 pgpool: Test: fix regress.sh to set numeric PostgreSQL version number.
Previous Message Tatsuo Ishii 2026-08-02 06:34:44 pgpool: Fix do_query to send sync rather than flush.