[pgpool-committers: 9307] pgpool: Allow to use multiple statements extensively.

Tatsuo Ishii ishii at sraoss.co.jp
Wed Apr 19 10:56:35 JST 2023


Allow to use multiple statements extensively.

This commit tries to eliminate pgpool's long standing limitations
regarding multiple statements (multi-statements).

Previously

BEGIN;SELECT;
SAVEPOINT foo;

will fail in streaming replication mode because "BEGIN" was sent to
the primar node, but "SAVEPOINT" will be sent to both the primary and
standbys, and standbys will complain "SAVEPOINT can only be used in
transaction blocks".

Basic idea to solve the problem is, tracking explicit transactions
started by multi-statement queries so that all commands including
PREPARE, EXECUTE, DEALLOCATE, SAVEPOINT and COMMIT/ROLLBACK are sent
to the primary node in streaming replication mode or logical
replication mode.  In native replication or snapshot isolation mode,
those queries are sent to all of the backend nodes.

For this purpose new member: is_tx_started_by_multi_statement is added
to session context and also support functions are added.

extern bool is_tx_started_by_multi_statement_query(void);
extern void set_tx_started_by_multi_statement_query(void);
extern void unset_tx_started_by_multi_statement_query(void);

Discussion: https://www.pgpool.net/pipermail/pgpool-hackers/2023-February/004287.html
Back-patch-through: master, 4.4, 4.3, 4.2 and 4.1.

Branch
------
V4_1_STABLE

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

Modified Files
--------------
src/Makefile.am                            |  2 --
src/context/pool_query_context.c           | 31 +++++++++++++++++++--
src/context/pool_session_context.c         | 44 +++++++++++++++++++++++++++++-
src/include/context/pool_session_context.h | 14 +++++++++-
src/protocol/CommandComplete.c             | 39 +++++++++++++++++++++++++-
src/protocol/pool_process_query.c          | 33 ++++++++++++++++++++++
src/protocol/pool_proto_modules.c          |  2 +-
7 files changed, 156 insertions(+), 9 deletions(-)



More information about the pgpool-committers mailing list