Re: Libpq support to connect to standby server as priority
Tatsuo Ishii <ishii@sraoss.co.jp>
From: Tatsuo Ishii <ishii@sraoss.co.jp>
To: pg@fastcrypt.com
Cc: ishii@sraoss.co.jp, tsunakawa.takay@jp.fujitsu.com, tgl@sss.pgh.pa.us,
robertmhaas@gmail.com, laurenz.albe@cybertec.at, kommi.haribabu@gmail.com,
jingwangian@gmail.com, pgsql-hackers@postgresql.org
Date: 2019-01-18T06:28:13Z
Lists: pgsql-hackers
>> If you need some input from me regarding finding a primary node,
>> please say so. While working on Pgpool-II project, I learned the
>> necessity in a hard way.
>>
>>
> I would really like to have a consistent way of doing this, and consistent
> terms for the connection parameters.
>
> that said yes, I would like input from you.
Sure, no problem.
- Upon Pgpool-II starting up or recieving failover event or switch
over event, primary node finding is executed.
- It repeats following until timeout parameter
("search_primary_node_timeout" is expired)
do until the timeout is expired
{
for all_live_backends
{
connect to the backend.
execute "SELECT pg_is_in_recovery()".
if it returns false, the we find the primary node. Assume
other backend as standbys and we are done.
disconnect to the backend
}
sleep 1 second;
}
If no primary node was found, all backends are regarded as standbys.
In addition to above, recent Pgpool-II versions does optional checking
to verify backend status, for example, finding a case where there
are two primary nodes.
- If there are two primaries, check the connectivity between each
primary and standbys using pg_stat_wal_receiver() (so this can not
be executed with PostgreSQL version 9.5 or before)
- If there's a primary (call it "A") which is not connected to any of
standbys while there's a primary (call it "B") which is connected to
all of standbys, then A is regarded as a "false primary" (and
Pgpool-II detaches it from the streaming replication cluster managed
by Pgpool-II if detach_false_primary is enabled).
See Pgpool-II manual "detach_false_primary" section in
http://tatsuo-ishii.github.io/pgpool-II/current/runtime-config-failover.html for more details.
Best regards,
--
Tatsuo Ishii
SRA OSS, Inc. Japan
English: http://www.sraoss.co.jp/index_en.php
Japanese:http://www.sraoss.co.jp
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