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:24
Message-ID: E1wqPmB-0000000Dgmy-3YqQ@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.

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
------
V4_3_STABLE

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

Modified Files
--------------
src/protocol/pool_process_query.c | 22 ++++++++++------------
1 file changed, 10 insertions(+), 12 deletions(-)

Browse pgpool-committers by date

  From Date Subject
Next Message Tatsuo Ishii 2026-08-02 06:34:29 pgpool: Fix do_query to send sync rather than flush.
Previous Message Tatsuo Ishii 2026-07-31 07:28:22 pgpool: Feature: add new command 's' to pgproto.