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);