Re: Libpq support to connect to standby server as priority - Mailing list pgsql-hackers

From Tatsuo Ishii
Subject Re: Libpq support to connect to standby server as priority
Date
Msg-id 20190118.152813.1590173105330561170.t-ishii@sraoss.co.jp
Whole thread Raw
In response to Re: Libpq support to connect to standby server as priority  (Dave Cramer <pg@fastcrypt.com>)
List 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


pgsql-hackers by date:

Previous
From: "Tsunakawa, Takayuki"
Date:
Subject: RE: Libpq support to connect to standby server as priority
Next
From: Surafel Temesgen
Date:
Subject: Re: pg_dump multi VALUES INSERT