Prior to version 4.6, the online recovery database was hardcoded to "template1".
This commit introduces a new configuration parameter, "recovery_database",
which allows users to specify the database used for online recovery.
The default value is "postgres".
<sect3 id="example-cluster-pgpool-config-online-recovery">
<title>オンラインリカバリの設定</title>
<para>
- 続いて、オンラインリカバリを実行する<productname>PostgreSQL</productname>ユーザ及びオンラインリカバリ時に呼び出されるスクリプトを設定します。
+ 続いて、オンラインリカバリ(<xref linkend="runtime-online-recovery">)を実行する<productname>PostgreSQL</productname>ユーザ及びオンラインリカバリ時に呼び出されるスクリプトを設定します。
オンラインリカバリで実行される<function>pgpool_recovery</function>関数は
<productname>PostgreSQL</productname>のスーパーユーザ権限が必要なため、<varname>recovery_user</varname>に<emphasis>スーパーユーザ</emphasis>を指定しなければなりません。
ここでは、<literal>postgres</literal>ユーザを指定します。
</programlisting>
<para>
- また、オンラインリカバリ機能を使用するには、<function>pgpool_recovery</function>、
- <function>pgpool_remote_start</function>、<function>pgpool_switch_xlog</function>という関数が必要になるので、
- <literal>server1</literal>のtemplate1に<function>pgpool_recovery</function>をインストールしておきます。
+ また、オンラインリカバリ機能を使用するには、<function>pgpool_recovery</function>、<function>pgpool_remote_start</function>、<function>pgpool_switch_xlog</function>の各関数をあらかじめ<xref linkend="guc-recovery-database">で指定されたデータベース(デフォルトは<literal>'postgres'</literal>です)に作成しておく必要があります。
+ <literal>server1</literal>上で以下のコマンドを実行し、これらの関数を<literal>postgres</literal>に作成します。
+ <xref linkend="guc-recovery-database">にデフォルト以外の値が設定されている場合は、<literal>postgres</literal>をその設定値に置き換えてください。
</para>
<programlisting>
-[root@server1 ~]# psql -U postgres template1 -c "CREATE EXTENSION pgpool_recovery"
+[root@server1 ~]# psql -U postgres postgres -c "CREATE EXTENSION pgpool_recovery"
</programlisting>
<note>
<para>
</programlisting>
<para>
- また、オンラインリカバリ機能を使用するには、<function>pgpool_recovery</function>、
- <function>pgpool_remote_start</function>、<function>pgpool_switch_xlog</function>という関数が必要になるので、
- <literal>server1</literal>のtemplate1に<function>pgpool_recovery</function>をインストールしておきます。
+ また、オンラインリカバリ機能を使用するには、<function>pgpool_recovery</function>、<function>pgpool_remote_start</function>、<function>pgpool_switch_xlog</function>の各関数をあらかじめ<xref linkend="guc-recovery-database">で指定されたデータベース(デフォルトは<literal>'postgres'</literal>です)に作成しておく必要があります。
+ <literal>server1</literal>上で以下のコマンドを実行し、これらの関数を<literal>postgres</literal>に作成します。
+ <xref linkend="guc-recovery-database">にデフォルト以外の値が設定されている場合は、<literal>postgres</literal>をその設定値に置き換えてください。
</para>
<programlisting>
-[server1]# su - postgres
-[server1]$ psql template1 -c "CREATE EXTENSION pgpool_recovery"
+[server1]# psql -U postgres postgres -c "CREATE EXTENSION pgpool_recovery"
</programlisting>
<note>
<para>
when you use the online recovery that describes latter.
Also pgpoolAdmin of management tool, stop, restart or reload a
<productname>PostgreSQL </productname> on the screen by use <function>pgpool_pgctl<function>.
- It is enough, if these function installed in template1 first. These
- function do not needed that install in all databases.
-->
- 後述の オンラインリカバリ の機能を使う場合には、 pgpool_recovery, pgpool_remote_start, pgpool_switch_xlog という関数が必要です。
+ 後述のオンラインリカバリの機能を使う場合には、 <function>pgpool_recovery</function>、<function>pgpool_remote_start</function>、および<function>pgpool_switch_xlog</function>という関数が必要です。
また管理ツールである pgpoolAdmin の画面上から、バックエンドノードの PostgreSQL を停止・再起動・設定再読み込みを行なうことができますが、これには pgpool_pgctl という関数が使われます。
- これらの関数は、すべてのデータベースにインストールされている必要はなく、template1 にだけで 構いません。
</para>
<para>
$ make install
</programlisting>
<!--
- After this:
+ After this, execute the following command to create the functions
+ <function>pgpool_recovery</function>, <function>pgpool_remote_start</function>
+ and <function>pgpool_switch_xlog</function> in the database specified in
+ <xref linkend="guc-recovery-database">
+ (The default is <literal>'postgres'</literal>).
+ If a value other than the default is configured for
+ <xref linkend="guc-recovery-database">, replace <literal>"postgres"</literal>
+ with the setting of <xref linkend="guc-recovery-database">.
-->
- この後に以下か、
+ この後、以下のコマンドを実行して、<xref linkend="guc-recovery-database">で指定されたデータベースに(デフォルトは<literal>'postgres'</literal>です)<function>pgpool_recovery</function>、<function>pgpool_remote_start</function>および<function>pgpool_switch_xlog</function>関数を作成します。
+ <xref linkend="guc-recovery-database">にデフォルト以外の値が設定されている場合は、<literal>"postgres"</literal>をその設定値に置き換えてください。
<programlisting>
-$ psql template1
+$ psql postgres
=# CREATE EXTENSION pgpool_recovery;
</programlisting>
-->
または
<programlisting>
-$ psql -f pgpool-recovery.sql template1
+$ psql -f pgpool-recovery.sql postgres
</programlisting>
を実行します。
</listitem>
</varlistentry>
+ <varlistentry id="guc-recovery-database" xreflabel="recovery_database">
+ <term><varname>recovery_database</varname> (<type>string</type>)
+ <indexterm>
+ <!--
+ <primary><varname>recovery_database</varname> configuration parameter</primary>
+ -->
+ <primary><varname>recovery_database</varname> 設定パラメータ</primary>
+ </indexterm>
+ </term>
+ <listitem>
+ <para>
+ <!--
+ Specifies the PostgreSQL database name to be used for online recovery.
+ The default is <literal>'postgres'</literal>. If not specified,
+ <productname>Pgpool-II</productname> will attempt to use the
+ <literal>"postgres"</literal> database.
+ -->
+ オンラインリカバリを行うための<productname>PostgreSQL</>データベースです。
+ デフォルトは<literal>'postgres'</literal>です。
+ 空文字('')が指定された場合、<productname>Pgpool-II</>は
+ <literal>「postgres」</literal>データベースの使用を試みます。
+ </para>
+ <para>
+ <!--
+ This parameter can be changed by reloading the <productname>Pgpool-II</> configurations.
+ -->
+ このパラメータは<productname>Pgpool-II</>の設定を再読み込みすることで変更可能です。
+ </para>
+ <note>
+ <para>
+ <!--
+ To perform online recovery, the functions <varname>pgpool_recovery</varname>,
+ <varname>pgpool_remote_start</varname> and
+ <varname>pgpool_switch_xlog</varname> must be created in the database
+ specified by the <xref linkend="guc-recovery-database"> parameter.
+ To install these functions in the default database
+ <literal>"postgres"</literal>, execute the following command
+ (<emphasis>if a value other than the default is configured, replace
+ <literal>"postgres"</literal> with the setting of
+ <varname>recovery_database</varname></emphasis>):
+ -->
+ オンラインリカバリを実行するには、<xref linkend="guc-recovery-database">パラメータで指定されたデータベースに、pgpool_recovery、pgpool_remote_start、および pgpool_switch_xlog 関数を作成しておく必要があります。
+ これらの関数をデフォルトのデータベース<literal>postgres</literal>に作成するには、以下のコマンドを実行してください。
+ (デフォルト値以外が設定されている場合は、<literal>postgres</literal>を<xref linkend="guc-recovery-database">に設定された値に置き換えてください)
+ <programlisting>
+$ psql postgres -c "CREATE EXTENSION pgpool_recovery"
+ </programlisting>
+ </para>
+ </note>
+ </listitem>
+ </varlistentry>
+
<varlistentry id="guc-recovery-1st-stage-command" xreflabel="recovery_1st_stage_command">
<term><varname>recovery_1st_stage_command</varname> (<type>string</type>)
<indexterm>
<sect3 id="example-cluster-pgpool-config-online-recovery">
<title>Pgpool-II Online Recovery Configurations</title>
<para>
- Next, configure the required parameters to perform online recovery.
+ Next, configure the required parameters to perform online recovery
+ (<xref linkend="runtime-online-recovery">).
Because <emphasis>Superuser</emphasis> privilege in <productname>PostgreSQL</productname>
is required for performing online recovery, we specify <literal>postgres</literal>
user in <xref linkend="GUC-RECOVERY-USER">. In this example, we leave
</programlisting>
<para>
- In order to use the online recovery functionality, the functions of
- <function>pgpool_recovery</function>, <function>pgpool_remote_start</function>,
- <function>pgpool_switch_xlog</function> are required, so we need to install
- <function>pgpool_recovery</function> on template1 of <productname>PostgreSQL</productname> server
- <literal>server1</literal>.
+ In addition, to perform online recovery, the functions
+ <function>pgpool_recovery</function>, <function>pgpool_remote_start</function>
+ and <function>pgpool_switch_xlog</function> must be created in advance
+ in the database specified by <xref linkend="guc-recovery-database">
+ (the default is <literal>'postgres'</literal>).
+ Execute the following command to create these functions in
+ <literal>postgres</literal> on <literal>server1</literal>.
+ If a value other than the default is configured for
+ <xref linkend="guc-recovery-database">, replace <literal>postgres</literal>
+ with the configured value.
</para>
<programlisting>
-[root@server1 ~]# psql -U postgres template1 -c "CREATE EXTENSION pgpool_recovery"
+[root@server1 ~]# psql -U postgres postgres -c "CREATE EXTENSION pgpool_recovery"
</programlisting>
<note>
<para>
</programlisting>
<para>
- In order to use the online recovery functionality, the functions of
- <function>pgpool_recovery</function>, <function>pgpool_remote_start</function>,
- <function>pgpool_switch_xlog</function> are required, so we need to install
- <function>pgpool_recovery</function> on template1 of <productname>PostgreSQL</productname> server
- <literal>server1</literal>.
+ In addition, to perform online recovery, the functions
+ <function>pgpool_recovery</function>, <function>pgpool_remote_start</function>
+ and <function>pgpool_switch_xlog</function> must be created in advance
+ in the database specified by <xref linkend="guc-recovery-database">
+ (the default is <literal>'postgres'</literal>).
+ Execute the following command to create these functions in
+ <literal>postgres</literal> on <literal>server1</literal>.
+ If a value other than the default is configured for
+ <xref linkend="guc-recovery-database">, replace <literal>postgres</literal>
+ with the configured value.
</para>
<programlisting>
-[server1]# su - postgres
-[server1]$ psql template1 -c "CREATE EXTENSION pgpool_recovery"
+[server1]# psql -U postgres postgres -c "CREATE EXTENSION pgpool_recovery"
</programlisting>
<note>
<para>
when you use the online recovery that describes latter.
Also pgpoolAdmin of management tool, stop, restart or reload a
<productname>PostgreSQL</productname> on the screen by use <function>pgpool_pgctl</function>.
- It is enough, if these function installed in template1 first. These
- function do not needed that install in all databases.
</para>
<para>
$ make
$ make install
</programlisting>
- After this:
+ After this, execute the following command to create the functions
+ <function>pgpool_recovery</function>, <function>pgpool_remote_start</function>
+ and <function>pgpool_switch_xlog</function> in the database specified in
+ <xref linkend="guc-recovery-database">
+ (The default is <literal>'postgres'</literal>).
+ If a value other than the default is configured for
+ <xref linkend="guc-recovery-database">, replace <literal>"postgres"</literal>
+ with the setting of <xref linkend="guc-recovery-database">.
<programlisting>
-$ psql template1
+$ psql postgres
=# CREATE EXTENSION pgpool_recovery;
</programlisting>
or
<programlisting>
-$ psql -f pgpool-recovery.sql template1
+$ psql -f pgpool-recovery.sql postgres
</programlisting>
</para>
</listitem>
</varlistentry>
+ <varlistentry id="guc-recovery-database" xreflabel="recovery_database">
+ <term><varname>recovery_database</varname> (<type>string</type>)
+ <indexterm>
+ <primary><varname>recovery_database</varname> configuration parameter</primary>
+ </indexterm>
+ </term>
+ <listitem>
+ <para>
+ Specifies the PostgreSQL database name to be used for online recovery.
+ The default is <literal>'postgres'</literal>. If an empty string ('')
+ is specified, <productname>Pgpool-II</productname> will attempt to use
+ the <literal>"postgres"</literal> database.
+ </para>
+ <para>
+ This parameter can be changed by reloading the <productname>Pgpool-II</> configurations.
+ </para>
+ <note>
+ <para>
+ To perform online recovery, the functions <varname>pgpool_recovery</varname>,
+ <varname>pgpool_remote_start</varname> and
+ <varname>pgpool_switch_xlog</varname> must be created in the database
+ specified by the <xref linkend="guc-recovery-database"> parameter.
+ To install these functions in the default database
+ <literal>"postgres"</literal>, execute the following command
+ (<emphasis>if a value other than the default is configured, replace
+ <literal>"postgres"</literal> with the setting of
+ <varname>recovery_database</varname></emphasis>):
+ <programlisting>
+$ psql postgres -c "CREATE EXTENSION pgpool_recovery"
+ </programlisting>
+ </para>
+ </note>
+ </listitem>
+ </varlistentry>
+
<varlistentry id="guc-recovery-1st-stage-command" xreflabel="recovery_1st_stage_command">
<term><varname>recovery_1st_stage_command</varname> (<type>string</type>)
<indexterm>
NULL, NULL, NULL, NULL
},
+ {
+ {"recovery_database", CFGCXT_RELOAD, RECOVERY_CONFIG,
+ "The database name for online recovery.",
+ CONFIG_VAR_TYPE_STRING, false, 0
+ },
+ &g_pool_config.recovery_database,
+ "postgres",
+ NULL, NULL, NULL, NULL
+ },
+
{
{"recovery_1st_stage_command", CFGCXT_RELOAD, RECOVERY_CONFIG,
"Command to execute in first stage recovery.",
int health_check_period; /* health check period */
char *health_check_user; /* PostgreSQL user name for health check */
char *health_check_password; /* password for health check username */
- char *health_check_database; /* database name for health check
- * username */
+ char *health_check_database; /* database name for health check */
int health_check_max_retries; /* health check max retries */
int health_check_retry_delay; /* amount of time to wait between
* retries */
int health_check_period; /* health check period */
char *health_check_user; /* PostgreSQL user name for health check */
char *health_check_password; /* password for health check username */
- char *health_check_database; /* database name for health check
- * username */
+ char *health_check_database; /* database name for health check */
int health_check_max_retries; /* health check max retries */
int health_check_retry_delay; /* amount of time to wait between
* retries */
char *recovery_user; /* PostgreSQL user name for online recovery */
char *recovery_password; /* PostgreSQL user password for online
* recovery */
+ char *recovery_database; /* Database name for recovery */
char *recovery_1st_stage_command; /* Online recovery command in 1st
* stage */
char *recovery_2nd_stage_command; /* Online recovery command in 2nd
{
char port_str[16];
PGconn *conn;
+ char *dbname;
char *password = get_pgpool_config_user_password(pool_config->recovery_user,
pool_config->recovery_password);
snprintf(port_str, sizeof(port_str),
"%d", backend->backend_port);
+ /*
+ * If database is not specified, "postgres" database is assumed.
+ */
+ if (*pool_config->recovery_database == '\0')
+ dbname = "postgres";
+ else
+ dbname = pool_config->recovery_database;
+
conn = PQsetdbLogin(backend->backend_hostname,
port_str,
NULL,
NULL,
- "template1",
+ pool_config->recovery_database,
pool_config->recovery_user,
password ? password : "");
# Leaving it empty will make Pgpool-II to first look for the
# Password in pool_passwd file before using the empty password
+#recovery_database = 'postgres'
+ # Database name for online recovery
+
#recovery_1st_stage_command = ''
# Executes a command in first stage
#recovery_2nd_stage_command = ''
echo "sr_check_password = ''" >> $CONF
echo "recovery_user = '$WHOAMI'" >> $CONF
echo "recovery_password = ''" >> $CONF
+ echo "recovery_database = 'template1'" >> $CONF
echo "recovery_1st_stage_command = 'basebackup.sh'" >> $CONF
if [ $MODE = "r" -o $MODE = "i" ];then
echo "sr_check_user = '$WHOAMI'" >> $CONF
echo "recovery_user = '$WHOAMI'" >> $CONF
echo "recovery_password = ''" >> $CONF
+ echo "recovery_database = 'template1'" >> $CONF
echo "recovery_1st_stage_command = 'basebackup.sh'" >> $CONF
if [ $MODE = "r" || $MODE = "i" ];then
StrNCpy(status[i].desc, "online recovery user", POOLCONFIG_MAXDESCLEN);
i++;
+ StrNCpy(status[i].name, "recovery_database", POOLCONFIG_MAXNAMELEN);
+ snprintf(status[i].value, POOLCONFIG_MAXVALLEN, "%s", pool_config->recovery_database);
+ StrNCpy(status[i].desc, "database name for online recovery", POOLCONFIG_MAXDESCLEN);
+ i++;
+
StrNCpy(status[i].name, "recovery_1st_stage_command", POOLCONFIG_MAXNAMELEN);
snprintf(status[i].value, POOLCONFIG_MAXVALLEN, "%s", pool_config->recovery_1st_stage_command);
StrNCpy(status[i].desc, "execute a command in first stage.", POOLCONFIG_MAXDESCLEN);