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:39
Message-ID: E1wqPmQ-0000000Dhji-3BOq@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_6_STABLE

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

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:44 pgpool: Fix do_query to send sync rather than flush.
Previous Message Tatsuo Ishii 2026-08-02 06:34:34 pgpool: Fix do_query to send sync rather than flush.