pgpool: Fix premature Sync during extended-query pipelines

From: Taiki Koshino <koshino(at)sraoss(dot)co(dot)jp>
To: pgpool-committers(at)lists(dot)postgresql(dot)org
Subject: pgpool: Fix premature Sync during extended-query pipelines
Date: 2026-09-18 07:18:20
Message-ID: E1x7SrT-0000000FABl-3CYE@gothos.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgpool-committers

Fix premature Sync during extended-query pipelines

Pgpool-II could send an internal Sync before receiving the terminating
Sync from the frontend while processing an extended-query pipeline.

Because ReadyForQuery is not returned until Sync is processed, the
backend transaction state may still indicate idle while an implicit
transaction is in progress. A later Parse could therefore cause
Pgpool-II to send an internal Sync based on the stale transaction state,
prematurely ending the implicit transaction.

Track whether Pgpool-II is waiting for a frontend Sync and prevent Parse
from sending an internal Sync while processing the same pipeline.

Additional handling is required when statements in the pipeline are
sent to different backend nodes.

In native replication and snapshot isolation modes, send a SELECT
following a non-SELECT in the same pipeline to all backend nodes. This
ensures that an error aborts the implicit transaction on every node.
In snapshot isolation mode, also close the internal transaction when
the frontend Sync is processed.

In streaming replication mode, defer Sync to the primary when the
pipeline has executed statements on both the primary and a standby.
Process the standby result first and, if it reports an error, raise an
intentional error on the primary before sending the deferred Sync.
This prevents the primary from committing changes before the standby
result is known.

This fixes pipelines such as:

CREATE TABLE test(i int);
SELECT * FROM missing_table;

If the SELECT fails, the implicit transaction is rolled back and the
table created earlier in the pipeline does not remain.

The fix was verified in raw, native replication, snapshot isolation,
and streaming replication modes.

Author: Taiki Koshino <koshino(at)sraoss(dot)co(dot)jp>
Discussion: https://github.com/pgpool/pgpool2/issues/174
Backpatch-through: v4.3

Branch
------
V4_3_STABLE

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

Modified Files
--------------
src/context/pool_session_context.c | 101 +++++++++++++++++
src/include/context/pool_session_context.h | 32 ++++++
src/include/protocol/pool_proto_modules.h | 2 +-
src/protocol/pool_process_query.c | 8 ++
src/protocol/pool_proto_modules.c | 170 ++++++++++++++++++++++++++++-
5 files changed, 307 insertions(+), 6 deletions(-)

Browse pgpool-committers by date

  From Date Subject
Next Message Tatsuo Ishii 2026-09-18 21:22:12 pgpool: Fix compiler error.
Previous Message Taiki Koshino 2026-09-18 07:17:31 pgpool: Fix premature Sync during extended-query pipelines