Re: target_session_attrs

From: Bo Peng <pengbo(at)sraoss(dot)co(dot)jp>
To: Tatsuo Ishii <ishii(at)postgresql(dot)org>, "pgpool-hackers(at)lists(dot)postgresql(dot)org" <pgpool-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: target_session_attrs
Date: 2026-10-22 09:41:03
Message-ID: OSOP286MB78060B85C22A8679C57240A9F2652@OSOP286MB7806.JPNP286.PROD.OUTLOOK.COM
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgpool-hackers

Ishii-san,

Thank you for the detailed explanation and the patch!

Looks good to me.
I think the patche is ready to be committed.

---
Bo Peng <pengbo(at)sraoss(dot)co(dot)jp>
SRA OSS K.K.
URL: https://www.sraoss.co.jp/

________________________________________
差出人: Tatsuo Ishii <ishii(at)postgresql(dot)org>
送信: 2026 年 10 月 17 日 (土曜日) 18:21
宛先: pgpool-hackers(at)lists(dot)postgresql(dot)org <pgpool-hackers(at)lists(dot)postgresql(dot)org>
件名: target_session_attrs

libpq's target_session_attrs is to select backend by certain
properties to be acceptable [1]. Currently possible value for it are
"any", "read-write", "read-only", "primary", "standby" and
"prefer-standby" as of PostgreSQL 19.

Unfortunately other than "any", target_session_attrs will not work as
expected if used against Pgpool-II. The reason is, because Pgpool-II
is a proxy which manages multiple backends. IMO there's no way to
avoid the issue. So I decided to add this as a new restriction
qentry. Attached is the patches for it. For your convenience, a text
version in English is shown below. Comments are welcome.
------------------------------------------------------------
target_session_attrs

Do not set libpq's connection parameter target_session_attrs to other
than any to connect to Pgpool-II. target_session_attrs is a libpq's
feature to select PostgreSQL to connect to by specifying its kind. For
example, if target_session_attrs is set to primary, libpq will check
in_hot_standby ParameterStatus value while connecting to Pgpool-II to
make sure that it is off. Pgpool-II always returns the value of the
main server (the smallest node id server which is not in down
status). If the node 0 is the main server and it's a standby by
chance, libpq will receive in_hot_standby = on, which is not the
expected value (in_hot_standby = off). Therefore it's treated as an
error in libpq side.

What happens if target_session_attrs = read-only and the node 0 is the
main server and it's a standby? In this case libpq can connects to
Pgpool-II normally. However, even if a write query is sent, it does
not raise an error as Pgpool-II redirects the query to primary. This
may be an unexpected behavior for libpq applications.
------------------------------------------------------------

[1] https://www.postgresql.org/docs/19/libpq-connect.html#LIBPQ-CONNECT-TARGET-SESSION-ATTRS

Regards,
--
Tatsuo Ishii
SRA OSS K.K.
English: http://www.sraoss.co.jp/index_en/
Japanese:http://www.sraoss.co.jp

In response to

Responses

Browse pgpool-hackers by date

  From Date Subject
Next Message Tatsuo Ishii 2026-10-22 12:32:38 Re: target_session_attrs
Previous Message Bo Peng 2026-10-22 09:22:53 Re: Segfault when a watchdog sync changes the primary under running children