pgpool2.git / summary / log / commit / refs
commit 10ef9092e2e6a40650fe304270cea79ed20ece17
Author: Tatsuo Ishii <ishii@sraoss.co.jp>
Date: Wed Sep 22 00:23:02 2021 +0000
Add new config parameter "failover_on_backend_shutdown".
If set to on, admin shutdown triggers failover (existing behavior).
If set to off, admin shutdown does not trigger failover (new
behavior), and is useful to completely avoid unwanted failover caused
by pg_terminate_backend() and SIGTERM signal sent to the backend
process.
Discussion: https://www.pgpool.net/pipermail/pgpool-hackers/2021-August/003999.html
doc.ja/src/sgml/failover.sgml | 77 +++++++++++++++++++++++++++++--
doc/src/sgml/failover.sgml | 51 ++++++++++++++++++--
src/config/pool_config_variables.c | 12 ++++-
src/include/pool_config.h | 2 +
src/protocol/pool_process_query.c | 2 +-
src/sample/pgpool.conf.sample-logical | 6 +++
src/sample/pgpool.conf.sample-raw | 6 +++
src/sample/pgpool.conf.sample-replication | 6 +++
src/sample/pgpool.conf.sample-slony | 6 +++
src/sample/pgpool.conf.sample-snapshot | 6 +++
src/sample/pgpool.conf.sample-stream | 6 +++
src/utils/pool_process_reporting.c | 5 ++
12 files changed, 176 insertions(+), 9 deletions(-)
diff --git a/doc.ja/src/sgml/failover.sgml b/doc.ja/src/sgml/failover.sgml
index 1142332a5..bc1dd224a 100644
--- a/doc.ja/src/sgml/failover.sgml
+++ b/doc.ja/src/sgml/failover.sgml
@@ -670,6 +670,78 @@ if (we need to executed follow primary command)
</listitem>
</varlistentry>
+ <varlistentry id="guc-failover-on-backend-shutdown" xreflabel="failover_on_backend_shutdown">
+ <term><varname>failover_on_backend_shutdown</varname> (<type>boolean</type>)
+ <indexterm>
+<!--
+ <primary><varname>failover_on_backend_shutdown</varname> configuration parameter</primary>
+-->
+ <primary><varname>failover_on_backend_shutdown</varname>設定パラメータ</primary>
+ </indexterm>
+ </term>
+ <listitem>
+ <para>
+<!--
+ When set to on, <productname>Pgpool-II</productname> detects a
+ backend shutdown event by checking particular error code
+ <literal>57P01</literal> and <literal>57P02</literal> on a
+ session established between the client and backend. If it
+ detects those error codes, a failover is triggered on that node.
+ When this is set to off, <productname>Pgpool-II</productname>
+ only report an error and disconnect the session in case of such
+ errors. The default is off.
+-->
+ onに設定した場合、<productname>Pgpool-II</productname>は確立したクライアントとバックエンドのセッション上で特定のエラーコード:<literal>57P01</literal>と<literal>57P02</literal>をチェックすることにより、バックエンドのシャットダウンイベントを検出します。
+ それらのエラーコードを検出すると、そのノードでフェイルオーバが起動されます。
+ offに設定した場合、そのようなエラーの場合でも<productname>Pgpool-II</productname>は単にエラーをレポートしセッションが切断するのみです。
+ デフォルトはoffです。
+ </para>
+ <para>
+<!--
+ If no client is connected,
+ <productname>Pgpool-II</productname> will not detect the event
+ even if the parameter is on.
+-->
+ クライアントが接続されていなければ、このパラメータがonでも<productname>Pgpool-II</productname>はシャットダウンを検出しません。
+ </para>
+ <para>
+<!--
+ Please note that <literal>57P01</literal> is not only sent at a
+ shutdown event, but also sent when the backend currently
+ connected is killed by <function>pg_terminate_backend</function>
+ or SIGTERM signal. This is annoying because it results in
+ unwanted failover. To avoid this, turn off this parameter.
+-->
+ <literal>57P01</literal>はシャットダウンだけでなく、現在接続中のバックエンドが<function>pg_terminate_backend</function>あるいはSIGTERMシグナルによって終了させられた場合にも送られてくることに注意してください。
+ これは望まないフェイルオーバを引き起こすので困りものです。
+ これを防ぐには、このパラメータをoffにしてください。
+ </para>
+
+ <note>
+ <para>
+<!--
+ It is recommended to turn on the backend health checking
+ (see <xref linkend="runtime-config-health-check">)
+ when <varname>failover_on_backend_shutdown</varname> is set to off.
+-->
+ <varname>failover_on_backend_shutdown</varname>をoffにする場合は、バックエンドのヘルスチェックを有効にすることをお勧めします(<xref linkend="runtime-config-health-check">をご覧ください)。
+ </para>
+ </note>
+
+ <para>
+<!--
+ This parameter is available
+ in <productname>Pgpool-II</productname> 4.3 or later. This
+ parameter can be changed by reloading
+ the <productname>Pgpool-II</productname> configurations.
+-->
+ このパラメータは<productname>Pgpool-II</productname> 4.3以降で利用可能です。
+ 4.2以前では、このパラメータが常にonであるのと同じ動作をします。
+ このパラメータは<productname>Pgpool-II</>の設定を再読み込みすることで変更可能です。
+ </para>
+ </listitem>
+ </varlistentry>
+
<varlistentry id="guc-failover-on-backend-error" xreflabel="failover_on_backend_error">
<term><varname>failover_on_backend_error</varname> (<type>boolean</type>)
<indexterm>
@@ -696,11 +768,10 @@ if (we need to executed follow primary command)
when <varname>failover_on_backend_error</varname> is set to off.
Note, however, that <productname>Pgpool-II</productname> still triggers the
failover when it detects the administrative shutdown of
- <productname>PostgreSQL</> backend server.
+ <productname>PostgreSQL</> backend server if <xref linkend="guc-failover-on-backend-shutdown"> is on.
-->
<varname>failover_on_backend_error</varname>をoffにする場合は、バックエンドのヘルスチェックを有効にすることをお勧めします(<xref linkend="runtime-config-health-check">をご覧ください)。
- なお、<productname>PostgreSQL</>バックエンドサーバが管理コマンドでシャットダウンされたことを<productname>Pgpool-II</productname>が検知した場合には、依然としてフェイルオーバが起こることに注意してください。
- この場合にもフェイルオーバを避けたい場合には、<xref linkend="guc-backend-flag">でDISALLOW_TO_FAILOVERを指定してください。
+ なお、<xref linkend="guc-failover-on-backend-shutdown">がonなら、<productname>PostgreSQL</>バックエンドサーバが管理コマンドでシャットダウンされたことを<productname>Pgpool-II</productname>が検知した場合には、依然としてフェイルオーバが起こることに注意してください。
</para>
</note>
<para>
diff --git a/doc/src/sgml/failover.sgml b/doc/src/sgml/failover.sgml
index 91dca31a7..747a088b4 100644
--- a/doc/src/sgml/failover.sgml
+++ b/doc/src/sgml/failover.sgml
@@ -508,6 +508,53 @@ if (we need to executed follow primary command)
</listitem>
</varlistentry>
+ <varlistentry id="guc-failover-on-backend-shutdown" xreflabel="failover_on_backend_shutdown">
+ <term><varname>failover_on_backend_shutdown</varname> (<type>boolean</type>)
+ <indexterm>
+ <primary><varname>failover_on_backend_shutdown</varname> configuration parameter</primary>
+ </indexterm>
+ </term>
+ <listitem>
+ <para>
+ When set to on, <productname>Pgpool-II</productname> detects a
+ backend shutdown event by checking particular error code
+ <literal>57P01</literal> and <literal>57P02</literal> on a
+ session established between the client and backend. If it
+ detects those error codes, a failover is triggered on that node.
+ When this is set to off, <productname>Pgpool-II</productname>
+ only report an error and disconnect the session in case of such
+ errors. The default is off.
+ </para>
+ <para>
+ If no client is connected,
+ <productname>Pgpool-II</productname> will not detect the event
+ even if the parameter is on.
+ </para>
+ <para>
+ Please note that <literal>57P01</literal> is not only sent at a
+ shutdown event, but also sent when the backend currently
+ connected is killed by <function>pg_terminate_backend</function>
+ or SIGTERM signal. This is annoying because it results in
+ unwanted failover. To avoid this, turn off this parameter.
+ </para>
+
+ <note>
+ <para>
+ It is recommended to turn on the backend health checking
+ (see <xref linkend="runtime-config-health-check">)
+ when <varname>failover_on_backend_shutdown</varname> is set to off.
+ </para>
+ </note>
+
+ <para>
+ This parameter is available
+ in <productname>Pgpool-II</productname> 4.3 or later. This
+ parameter can be changed by reloading
+ the <productname>Pgpool-II</productname> configurations.
+ </para>
+ </listitem>
+ </varlistentry>
+
<varlistentry id="guc-failover-on-backend-error" xreflabel="failover_on_backend_error">
<term><varname>failover_on_backend_error</varname> (<type>boolean</type>)
<indexterm>
@@ -527,10 +574,6 @@ if (we need to executed follow primary command)
It is recommended to turn on the backend health checking
(see <xref linkend="runtime-config-health-check">)
when <varname>failover_on_backend_error</varname> is set to off.
- Note, however, that <productname>Pgpool-II</productname> still triggers the
- failover when it detects the administrative shutdown of
- <productname>PostgreSQL</> backend server.
- If you want to avoid a fail over even in this case, you need to specify DISALLOW_TO_FAILOVER on <xref linkend="guc-backend-flag">.
</para>
</note>
<para>
diff --git a/src/config/pool_config_variables.c b/src/config/pool_config_variables.c
index 5b96e39c4..814858cdc 100644
--- a/src/config/pool_config_variables.c
+++ b/src/config/pool_config_variables.c
@@ -4,7 +4,7 @@
* pgpool: a language independent connection pool server for PostgreSQL
* written by Tatsuo Ishii
*
- * Copyright (c) 2003-2020 PgPool Global Development Group
+ * Copyright (c) 2003-2021 PgPool Global Development Group
*
* Permission to use, copy, modify, and distribute this software and
* its documentation for any purpose and without fee is hereby
@@ -542,6 +542,16 @@ static struct config_bool ConfigureNamesBool[] =
NULL, NULL, NULL
},
+ {
+ {"failover_on_backend_shutdown", CFGCXT_RELOAD, FAILOVER_CONFIG,
+ "Triggers fail over when backend is shutdown.",
+ CONFIG_VAR_TYPE_BOOL, false, 0
+ },
+ &g_pool_config.failover_on_backend_shutdown,
+ true,
+ NULL, NULL, NULL
+ },
+
{
{"detach_false_primary", CFGCXT_RELOAD, FAILOVER_CONFIG,
"Automatically detaches false primary node.",
diff --git a/src/include/pool_config.h b/src/include/pool_config.h
index 58f0758e6..8ec4da35b 100644
--- a/src/include/pool_config.h
+++ b/src/include/pool_config.h
@@ -341,6 +341,8 @@ typedef struct
* set to false, pgpool will
* report an error and disconnect
* the session. */
+ bool failover_on_backend_shutdown; /* If true, trigger fail over
+ when backend is going down */
bool detach_false_primary; /* If true, detach false primary */
char *recovery_user; /* PostgreSQL user name for online recovery */
char *recovery_password; /* PostgreSQL user password for online
diff --git a/src/protocol/pool_process_query.c b/src/protocol/pool_process_query.c
index 0e4bfa02f..5db7c825f 100644
--- a/src/protocol/pool_process_query.c
+++ b/src/protocol/pool_process_query.c
@@ -4872,7 +4872,7 @@ SELECT_RETRY:
(errmsg("connection to postmaster on DB node %d was lost due to pg_terminate_backend", i),
errdetail("pg_terminate_backend was called on the backend")));
}
- else
+ else if (pool_config->failover_on_backend_shutdown)
{
notice_backend_error(i, REQ_DETAIL_SWITCHOVER);
sleep(5);
diff --git a/src/sample/pgpool.conf.sample-logical b/src/sample/pgpool.conf.sample-logical
index 14d5f55bc..656713780 100644
--- a/src/sample/pgpool.conf.sample-logical
+++ b/src/sample/pgpool.conf.sample-logical
@@ -536,6 +536,12 @@ failover_on_backend_error = on
# If set to off, pgpool will report an
# error and disconnect the session.
+failover_on_backend_shutdown = off
+ # Initiates failover when backend is shutdown,
+ # or backend process is killed.
+ # If set to off, pgpool will report an
+ # error and disconnect the session.
+
detach_false_primary = off
# Detach false primary if on. Only
# valid in streaming replicaton
diff --git a/src/sample/pgpool.conf.sample-raw b/src/sample/pgpool.conf.sample-raw
index 080a0329d..395726576 100644
--- a/src/sample/pgpool.conf.sample-raw
+++ b/src/sample/pgpool.conf.sample-raw
@@ -576,6 +576,12 @@ failover_on_backend_error = on
# If set to off, pgpool will report an
# error and disconnect the session.
+failover_on_backend_shutdown = off
+ # Initiates failover when backend is shutdown,
+ # or backend process is killed.
+ # If set to off, pgpool will report an
+ # error and disconnect the session.
+
detach_false_primary = off
# Detach false primary if on. Only
# valid in streaming replicaton
diff --git a/src/sample/pgpool.conf.sample-replication b/src/sample/pgpool.conf.sample-replication
index 40e288701..0bbbcbfce 100644
--- a/src/sample/pgpool.conf.sample-replication
+++ b/src/sample/pgpool.conf.sample-replication
@@ -572,6 +572,12 @@ failover_on_backend_error = on
# If set to off, pgpool will report an
# error and disconnect the session.
+failover_on_backend_shutdown = off
+ # Initiates failover when backend is shutdown,
+ # or backend process is killed.
+ # If set to off, pgpool will report an
+ # error and disconnect the session.
+
detach_false_primary = off
# Detach false primary if on. Only
# valid in streaming replicaton
diff --git a/src/sample/pgpool.conf.sample-slony b/src/sample/pgpool.conf.sample-slony
index 884cae7bc..c38072a71 100644
--- a/src/sample/pgpool.conf.sample-slony
+++ b/src/sample/pgpool.conf.sample-slony
@@ -573,6 +573,12 @@ failover_on_backend_error = on
# If set to off, pgpool will report an
# error and disconnect the session.
+failover_on_backend_shutdown = off
+ # Initiates failover when backend is shutdown,
+ # or backend process is killed.
+ # If set to off, pgpool will report an
+ # error and disconnect the session.
+
detach_false_primary = off
# Detach false primary if on. Only
# valid in streaming replicaton
diff --git a/src/sample/pgpool.conf.sample-snapshot b/src/sample/pgpool.conf.sample-snapshot
index db505d01b..8cf8ed737 100644
--- a/src/sample/pgpool.conf.sample-snapshot
+++ b/src/sample/pgpool.conf.sample-snapshot
@@ -570,6 +570,12 @@ failover_on_backend_error = on
# If set to off, pgpool will report an
# error and disconnect the session.
+failover_on_backend_shutdown = off
+ # Initiates failover when backend is shutdown,
+ # or backend process is killed.
+ # If set to off, pgpool will report an
+ # error and disconnect the session.
+
detach_false_primary = off
# Detach false primary if on. Only
# valid in streaming replicaton
diff --git a/src/sample/pgpool.conf.sample-stream b/src/sample/pgpool.conf.sample-stream
index bb6431212..34fcab6d1 100644
--- a/src/sample/pgpool.conf.sample-stream
+++ b/src/sample/pgpool.conf.sample-stream
@@ -575,6 +575,12 @@ failover_on_backend_error = on
# If set to off, pgpool will report an
# error and disconnect the session.
+failover_on_backend_shutdown = off
+ # Initiates failover when backend is shutdown,
+ # or backend process is killed.
+ # If set to off, pgpool will report an
+ # error and disconnect the session.
+
detach_false_primary = off
# Detach false primary if on. Only
# valid in streaming replicaton
diff --git a/src/utils/pool_process_reporting.c b/src/utils/pool_process_reporting.c
index 1bfc2e4a4..33a8544e7 100644
--- a/src/utils/pool_process_reporting.c
+++ b/src/utils/pool_process_reporting.c
@@ -659,6 +659,11 @@ get_config(int *nrows)
StrNCpy(status[i].desc, "failover on backend error", POOLCONFIG_MAXDESCLEN);
i++;
+ StrNCpy(status[i].name, "failover_on_backend_shutdown", POOLCONFIG_MAXNAMELEN);
+ snprintf(status[i].value, POOLCONFIG_MAXVALLEN, "%d", pool_config->failover_on_backend_shutdown);
+ StrNCpy(status[i].desc, "failover on backend shutdown", POOLCONFIG_MAXDESCLEN);
+ i++;
+
StrNCpy(status[i].name, "detach_false_primary", POOLCONFIG_MAXNAMELEN);
snprintf(status[i].value, POOLCONFIG_MAXVALLEN, "%d", pool_config->detach_false_primary);
StrNCpy(status[i].desc, "detach false primary", POOLCONFIG_MAXDESCLEN);
[parent: a874078de54f]