pgpoolのマニュアルに「health_check_max_retreisを有効にする場合は、failover_on_backend_errorを無効にするのが望ましいです。 」と書いてあります。
failover_on_backend_errorをoffにすると、pgpoolがフェイルオーバーの処理をしてくれなくなるので、別の仕組みでフェイルオーバーの仕組みを実装する必要があります。
health_check_max_retreisを有効にするのは、ネットワークが不安定になることがあるので、health_checkのリトライをしたい場合であって、pgpoolのフェイルオーバーは依然として必要だと思いますので、onのままにすることが多いのでは無いかと思います。
※「health_check_max_retreisを有効にする場合は、failover_on_backend_errorを無効にするのが望ましい」理由が分かりませんでした…
※「health_check_max_retreisを有効にする場合は、failover_on_backend_errorを無効にするのが望ましい」理由が分かりませんでした…
あまり考えずにfailover_on_backend_errorをoffに設定したら、以下の事象が発生しサービスが中断しました。
以下pgpoolのログです。
May 31 23:10:44 erogamescape13 pgpool[12780]: [313206-1] 2019-05-31 23:10:44: pid 12780: LOG: trying connecting to PostgreSQL server on "192.168.0.14:5432" by INET socket May 31 23:10:44 erogamescape13 pgpool[12780]: [313206-2] 2019-05-31 23:10:44: pid 12780: DETAIL: timed out. retrying... May 31 23:10:54 erogamescape13 pgpool[12780]: [313207-1] 2019-05-31 23:10:54: pid 12780: LOG: trying connecting to PostgreSQL server on "192.168.0.14:5432" by INET socket May 31 23:10:54 erogamescape13 pgpool[12780]: [313207-2] 2019-05-31 23:10:54: pid 12780: DETAIL: timed out. retrying... May 31 23:11:04 erogamescape13 pgpool[12780]: [313208-1] 2019-05-31 23:11:04: pid 12780: LOG: trying connecting to PostgreSQL server on "192.168.0.14:5432" by INET socket May 31 23:11:04 erogamescape13 pgpool[12780]: [313208-2] 2019-05-31 23:11:04: pid 12780: DETAIL: timed out. retrying... May 31 23:11:14 erogamescape13 pgpool[12780]: [313209-1] 2019-05-31 23:11:14: pid 12780: LOG: trying connecting to PostgreSQL server on "192.168.0.14:5432" by INET socket May 31 23:11:14 erogamescape13 pgpool[12780]: [313209-2] 2019-05-31 23:11:14: pid 12780: DETAIL: timed out. retrying... May 31 23:11:24 erogamescape13 pgpool[12780]: [313210-1] 2019-05-31 23:11:24: pid 12780: LOG: trying connecting to PostgreSQL server on "192.168.0.14:5432" by INET socket May 31 23:11:24 erogamescape13 pgpool[12780]: [313210-2] 2019-05-31 23:11:24: pid 12780: DETAIL: timed out. retrying... May 31 23:11:34 erogamescape13 pgpool[12780]: [313211-1] 2019-05-31 23:11:34: pid 12780: LOG: trying connecting to PostgreSQL server on "192.168.0.14:5432" by INET socket May 31 23:11:34 erogamescape13 pgpool[12780]: [313211-2] 2019-05-31 23:11:34: pid 12780: DETAIL: timed out. retrying... May 31 23:11:37 erogamescape13 pgpool[12780]: [313212-1] 2019-05-31 23:11:37: pid 12780: LOG: failed to connect to PostgreSQL server on "192.168.0.14:5432", getsockopt() detected error "Connection timed out" May 31 23:11:37 erogamescape13 pgpool[12780]: [313213-1] 2019-05-31 23:11:37: pid 12780: LOG: failed to create a backend 0 connection May 31 23:11:37 erogamescape13 pgpool[12780]: [313213-2] 2019-05-31 23:11:37: pid 12780: DETAIL: skip this backend because because failover_on_backend_error is off and we are in streaming replication mode and node is standby node May 31 23:11:37 erogamescape13 pgpool[12780]: [313214-1] 2019-05-31 23:11:37: pid 12780: LOG: master node 0 is down. Update master node to 1 May 31 23:11:37 erogamescape13 pgpool[12780]: [313215-1] 2019-05-31 23:11:37: pid 12780: LOG: failback event detected May 31 23:11:37 erogamescape13 pgpool[12780]: [313215-2] 2019-05-31 23:11:37: pid 12780: DETAIL: restarting myself May 31 23:11:38 erogamescape13 pgpool[13944]: [313288-1] 2019-05-31 23:11:38: pid 13944: ERROR: unable to read message kind May 31 23:11:38 erogamescape13 pgpool[13944]: [313288-2] 2019-05-31 23:11:38: pid 13944: DETAIL: kind does not match between master(0) slot[0] (52)
health_check_max_retreisを3に設定していたのに、どうしてconnectingが6回timeoutしているのか分からないのですが、6回timeoutして、failed to create a backend 0 connectionと判定しています。
※ちなみにbackend0のPostgreSQLはprimaryでした。
ここで、backend 0を切り離して、事前に用意したフェイルオーバーのためのスクリプトをpgpoolが起動して、backend 1を昇格させる必要があるのですが、failover_on_backend_errorがoffなので、pgpoolは何もせず(skip this backend because because failover_on_backend_error is off)、でもpgpoolとしては、backend 1がprimaryだと判断して動き始めます(Update master node to 1)。
しかし、実際はbackend 1はstandbyのままなので、kind does not match between master(0) slot[0]となってPostgreSQLに接続出来ず、サービスが中断しました。