diff --git a/doc/src/sgml/online-recovery.sgml b/doc/src/sgml/online-recovery.sgml
index ba1af959..32fe030e 100644
--- a/doc/src/sgml/online-recovery.sgml
+++ b/doc/src/sgml/online-recovery.sgml
@@ -291,6 +291,29 @@
Port number to be recovered (Pgpool-II 4.1 or after)
+
+
+ Hostname of the main (primary) node
+ (Pgpool-II 4.3 or after). Before
+ the hostname of the main (primary) node was obtained by
+ using hostname command. This is mostly ok
+ since the script runs on the main (primary) node
+ anyway. However in some systems the hostname obtained
+ by hostname command is different from the
+ hostname defined in backend_hostname configuration parameter.
+ This could cause a trouble
+ in because it checks
+ connectivity between primary and standby node by
+ using host parameter
+ in primary_conninfo parameter, which is
+ generated
+ by recovery_1st_stage_command. Thus it is
+ strongly recommended to use this parameter instead of
+ using hostname command to obtain the
+ hostname of the primary node
+ in recovery_1st_stage_command.
+
+
diff --git a/src/pcp_con/recovery.c b/src/pcp_con/recovery.c
index b8ef7c97..088826b7 100644
--- a/src/pcp_con/recovery.c
+++ b/src/pcp_con/recovery.c
@@ -5,7 +5,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
@@ -232,6 +232,9 @@ exec_checkpoint(PGconn *conn)
/*
* Call pgpool_recovery() function.
+ *
+ * "main_backend" is either primary backend node (in streaming replication
+ * mode) or main backend node (in other mode).
*/
static void
exec_recovery(PGconn *conn, BackendInfo * main_backend, BackendInfo * recovery_backend, char stage, int recovery_node)
@@ -239,12 +242,18 @@ exec_recovery(PGconn *conn, BackendInfo * main_backend, BackendInfo * recovery_b
PGresult *result;
char *hostname;
char *script;
+ char *main_hostname;
if (strlen(recovery_backend->backend_hostname) == 0 || *(recovery_backend->backend_hostname) == '/')
hostname = "localhost";
else
hostname = recovery_backend->backend_hostname;
+ if (strlen(main_backend->backend_hostname) == 0 || *(main_backend->backend_hostname) == '/')
+ main_hostname = "localhost";
+ else
+ main_hostname = main_backend->backend_hostname;
+
script = (stage == FIRST_STAGE) ?
pool_config->recovery_1st_stage_command : pool_config->recovery_2nd_stage_command;
@@ -259,13 +268,14 @@ exec_recovery(PGconn *conn, BackendInfo * main_backend, BackendInfo * recovery_b
*/
snprintf(recovery_command,
sizeof(recovery_command),
- "SELECT pgpool_recovery('%s', '%s', '%s', '%d', %d, '%d')",
+ "SELECT pgpool_recovery('%s', '%s', '%s', '%d', %d, '%d', '%s')",
script,
hostname,
recovery_backend->backend_data_directory,
main_backend->backend_port,
recovery_node,
- recovery_backend->backend_port
+ recovery_backend->backend_port,
+ main_hostname
);
ereport(LOG,
diff --git a/src/sql/pgpool-recovery/Makefile b/src/sql/pgpool-recovery/Makefile
index c6fdf9a8..55c8644f 100644
--- a/src/sql/pgpool-recovery/Makefile
+++ b/src/sql/pgpool-recovery/Makefile
@@ -3,7 +3,9 @@ DATA_built = pgpool-recovery.sql
DATA = uninstall_pgpool-recovery.sql
EXTENSION = pgpool_recovery
-DATA = pgpool_recovery--1.1.sql pgpool_recovery--1.2.sql pgpool_recovery--1.1--1.2.sql pgpool_recovery--1.3.sql pgpool_recovery--1.2--1.3.sql
+DATA = pgpool_recovery--1.1.sql pgpool_recovery--1.2.sql pgpool_recovery--1.1--1.2.sql \
+ pgpool_recovery--1.3.sql pgpool_recovery--1.2--1.3.sql \
+ pgpool_recovery--1.4.sql pgpool_recovery--1.3--1.4.sql
# if you are using PostgreSQL 8.0 or later,
# using pg_config is recommended.
diff --git a/src/sql/pgpool-recovery/pgpool-recovery.c b/src/sql/pgpool-recovery/pgpool-recovery.c
index f02a2091..515a2ee2 100644
--- a/src/sql/pgpool-recovery/pgpool-recovery.c
+++ b/src/sql/pgpool-recovery/pgpool-recovery.c
@@ -80,7 +80,23 @@ pgpool_recovery(PG_FUNCTION_ARGS)
elog(ERROR, "must be superuser to use pgpool_recovery function");
#endif
- if (PG_NARGS() >= 6) /* Pgpool-II 4.1 or later */
+ if (PG_NARGS() >= 7) /* Pgpool-II 4.3 or later */
+ {
+ char *primary_port = DatumGetCString(DirectFunctionCall1(textout,
+ PointerGetDatum(PG_GETARG_TEXT_P(3))));
+ int remote_node = PG_GETARG_INT32(4);
+
+ char *remote_port = DatumGetCString(DirectFunctionCall1(textout,
+ PointerGetDatum(PG_GETARG_TEXT_P(5))));
+
+ char *primary_host = DatumGetCString(DirectFunctionCall1(textout,
+ PointerGetDatum(PG_GETARG_TEXT_P(6))));
+
+ snprintf(recovery_script, sizeof(recovery_script), "\"%s/%s\" \"%s\" \"%s\" \"%s\" \"%s\" %d \"%s\" \"%s\"",
+ DataDir, script, DataDir, remote_host,
+ remote_data_directory, primary_port, remote_node, remote_port, primary_host);
+ }
+ if (PG_NARGS() >= 6) /* Pgpool-II 4.1 or 4.2 */
{
char *primary_port = DatumGetCString(DirectFunctionCall1(textout,
PointerGetDatum(PG_GETARG_TEXT_P(3))));
diff --git a/src/sql/pgpool-recovery/pgpool-recovery.sql.in b/src/sql/pgpool-recovery/pgpool-recovery.sql.in
index 64d3cbbd..1600de93 100644
--- a/src/sql/pgpool-recovery/pgpool-recovery.sql.in
+++ b/src/sql/pgpool-recovery/pgpool-recovery.sql.in
@@ -1,3 +1,14 @@
+CREATE FUNCTION pgpool_recovery(IN script_name text,
+ IN remote_host text,
+ IN remote_data_directory text,
+ IN primary_port text,
+ IN remote_node integer,
+ IN remote_port text)
+ IN primary_host text,
+RETURNS bool
+AS 'MODULE_PATHNAME', 'pgpool_recovery'
+LANGUAGE C STRICT;
+
CREATE FUNCTION pgpool_recovery(IN script_name text,
IN remote_host text,
IN remote_data_directory text,
diff --git a/src/sql/pgpool-recovery/pgpool_recovery--1.3--1.4.sql b/src/sql/pgpool-recovery/pgpool_recovery--1.3--1.4.sql
new file mode 100644
index 00000000..9db78a0d
--- /dev/null
+++ b/src/sql/pgpool-recovery/pgpool_recovery--1.3--1.4.sql
@@ -0,0 +1,9 @@
+/* contrib/pgpool_recovery/pgpool_recovery--1.3--1.4.sql */
+
+-- complain if script is sourced in psql, rather than via ALTER EXTENSION
+\echo Use "ALTER EXTENSION pgpool_recovery UPDATE TO '1.4'" to load this file. \quit
+
+create FUNCTION pgpool_recovery(script_name text, remote_host text, remote_data_directory text, primary_port text, remote_node integer, remote_port text, primary_host text)
+RETURNS bool
+AS 'MODULE_PATHNAME', 'pgpool_recovery'
+LANGUAGE C STRICT;
diff --git a/src/sql/pgpool-recovery/pgpool_recovery--1.4.sql b/src/sql/pgpool-recovery/pgpool_recovery--1.4.sql
new file mode 100644
index 00000000..b82d827d
--- /dev/null
+++ b/src/sql/pgpool-recovery/pgpool_recovery--1.4.sql
@@ -0,0 +1,52 @@
+-- complain if script is sourced in psql, rather than via CREATE EXTENSION
+\echo Use "CREATE EXTENSION pgpool_recovery" to load this file. \quit
+
+CREATE FUNCTION pgpool_recovery(IN script_name text,
+ IN remote_host text,
+ IN remote_data_directory text,
+ IN primary_port text,
+ IN remote_node integer,
+ IN remote_port text,
+ IN primary_host text)
+RETURNS bool
+AS 'MODULE_PATHNAME', 'pgpool_recovery'
+LANGUAGE C STRICT;
+
+CREATE FUNCTION pgpool_recovery(IN script_name text,
+ IN remote_host text,
+ IN remote_data_directory text,
+ IN primary_port text,
+ IN remote_node integer)
+RETURNS bool
+AS 'MODULE_PATHNAME', 'pgpool_recovery'
+LANGUAGE C STRICT;
+
+CREATE FUNCTION pgpool_recovery(IN script_name text,
+ IN remote_host text,
+ IN remote_data_directory text,
+ IN primary_port text)
+RETURNS bool
+AS 'MODULE_PATHNAME', 'pgpool_recovery'
+LANGUAGE C STRICT;
+
+CREATE FUNCTION pgpool_recovery(IN script_name text,
+ IN remote_host text,
+ IN remote_data_directory text)
+RETURNS bool
+AS 'MODULE_PATHNAME', 'pgpool_recovery'
+LANGUAGE C STRICT;
+
+CREATE FUNCTION pgpool_remote_start(IN remote_host text, IN remote_data_directory text)
+RETURNS bool
+AS 'MODULE_PATHNAME', 'pgpool_remote_start'
+LANGUAGE C STRICT;
+
+CREATE FUNCTION pgpool_pgctl(IN action text, IN stop_mode text)
+RETURNS bool
+AS '$libdir/pgpool-recovery', 'pgpool_pgctl'
+LANGUAGE C STRICT;
+
+CREATE FUNCTION pgpool_switch_xlog(IN archive_dir text)
+RETURNS text
+AS 'MODULE_PATHNAME', 'pgpool_switch_xlog'
+LANGUAGE C STRICT;
diff --git a/src/sql/pgpool-recovery/pgpool_recovery.control b/src/sql/pgpool-recovery/pgpool_recovery.control
index beb710a5..3940edb0 100644
--- a/src/sql/pgpool-recovery/pgpool_recovery.control
+++ b/src/sql/pgpool-recovery/pgpool_recovery.control
@@ -1,5 +1,5 @@
# pgpool-recovery extension
-comment = 'recovery functions for pgpool-II for V4.1 or later'
-default_version = '1.3'
+comment = 'recovery functions for pgpool-II for V4.3'
+default_version = '1.4'
module_pathname = '$libdir/pgpool-recovery'
relocatable = true