RE: Libpq support to connect to standby server as priority
tsunakawa.takay@fujitsu.com <tsunakawa.takay@fujitsu.com>
From: "tsunakawa.takay@fujitsu.com" <tsunakawa.takay@fujitsu.com>
To: 'Alvaro Herrera' <alvherre@2ndquadrant.com>
Cc: Greg Nancarrow <gregn4422@gmail.com>, Haribabu Kommi <kommi.haribabu@gmail.com>, Robert Haas <robertmhaas@gmail.com>, Laurenz Albe <laurenz.albe@cybertec.at>, Tom Lane <tgl@sss.pgh.pa.us>, Dave Cramer <pg@fastcrypt.com>, Jing Wang <jingwangian@gmail.com>, PostgreSQL-development <pgsql-hackers@postgresql.org>, Elvis Pranskevichus <elprans@gmail.com>
Date: 2020-01-06T01:37:46Z
Lists: pgsql-hackers
From: Alvaro Herrera <alvherre@2ndquadrant.com>
> So, we can know whether server is primary/standby by checking
> in_recovery, as opposed to knowing whether read-write which is done by
> checking transaction_read_only. So we can keep read-write as a synonym
> for "primary", and check in_recovery when used in servers that support
> the new GUC, and check transaction_read_only in older servers.
>
> It seems there's a lot of code that we can discard from the patch:
> first, we can discard checking for "read-only" altogether. Second, have
> us check transaction_read_only *only* if the server is of an older
> version.
Let me check my understanding. Are you proposing these?
* The canonical libpq connection parameter is target_session_attr = {primary | standby | prefer-standby}. Leave and document read-write as a synonym for primary.
* When the server version is 13 or later, libpq just checks in_recovery, not checking transaction_read_only or sending SHOW transaction_read_only.
* When the server version is before 13, libpq sends SHOW transaction_read_only as before.
Personally, 100% agreed, considering what we really wanted to do when target_session_attr was introduced is to tell if the server is primary or standby. The questions are:
Q1: Should we continue to use the name target_session_attr, or rename it to target_server_type and make target_session_attr a synonym for it? I'm in favor of the latter.
Q2: Can we accept the subtle incompatibility that target_session_attr=read-write and target_server_type=primary are not the same, when default_transaction_read_only is on? (I'd like to hear yes)
Q3: Can we go without supporting standby and prefer-standby for older servers? (I think yes because we can say that it's a new feature effective for new servers.)
Regards
Takayuki Tsunakawa
Commits
-
Make test_target_session_attrs more robust against connection failure.
- 3769e11a3183 14.0 landed
-
Extend the abilities of libpq's target_session_attrs parameter.
- ee28cacf619f 14.0 landed
-
Mark default_transaction_read_only as GUC_REPORT.
- d16f8c8e416d 14.0 landed
-
Introduce a new GUC_REPORT setting "in_hot_standby".
- bf8a662c9afa 14.0 landed
-
Avoid spamming the client with multiple ParameterStatus messages.
- 2432b1a04087 14.0 landed
-
Avoid harmless Valgrind no-buffer-pin errors.
- a766d6ca22ac 14.0 cited
-
Restructure libpq code to remove some duplicity
- b438e7e7a1c5 13.0 landed
-
libpq: Add target_session_attrs parameter.
- 721f7bd3cbcc 10.0 cited