From 1ef00f5a3b8d3515b84fa41b22afa999057eb971 Mon Sep 17 00:00:00 2001 From: Ian Barwick Date: Tue, 5 Sep 2017 11:19:25 +0900 Subject: [PATCH] repmgrd: parse "follow_command" during cascaded standby failover --- dbutils.c | 18 +++++++++--------- repmgrd-physical.c | 9 ++++++++- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/dbutils.c b/dbutils.c index 4c4c0bb5..ccced061 100644 --- a/dbutils.c +++ b/dbutils.c @@ -1125,7 +1125,7 @@ _get_primary_connection(PGconn *conn, node_id = atoi(PQgetvalue(res, i, 0)); strncpy(remote_conninfo, PQgetvalue(res, i, 1), MAXCONNINFO); log_verbose(LOG_INFO, - _("checking role of node '%i'"), + _("checking role of node %i"), node_id); if (quiet) @@ -1257,7 +1257,7 @@ get_replication_info(PGconn *conn, ReplInfo *replication_info) " CASE WHEN (last_wal_receive_lsn = last_wal_replay_lsn) " " THEN 0::INT " " ELSE " - " EXTRACT(epoch FROM (clock_timestamp() - last_xact_replay_timestamp))::INT " + " EXTRACT(epoch FROM (pg_catalog.clock_timestamp() - last_xact_replay_timestamp))::INT " " END AS replication_lag_time, " " COALESCE(last_wal_receive_lsn, '0/0') >= last_wal_replay_lsn AS receiving_streamed_wal " " FROM ( "); @@ -1267,18 +1267,18 @@ get_replication_info(PGconn *conn, ReplInfo *replication_info) appendPQExpBuffer( &query, " SELECT CURRENT_TIMESTAMP AS ts, " - " pg_last_wal_receive_lsn() AS last_wal_receive_lsn, " - " pg_last_wal_replay_lsn() AS last_wal_replay_lsn, " - " pg_last_xact_replay_timestamp() AS last_xact_replay_timestamp "); + " pg_catalog.pg_last_wal_receive_lsn() AS last_wal_receive_lsn, " + " pg_catalog.pg_last_wal_replay_lsn() AS last_wal_replay_lsn, " + " pg_catalog.pg_last_xact_replay_timestamp() AS last_xact_replay_timestamp "); } else { appendPQExpBuffer( &query, " SELECT CURRENT_TIMESTAMP AS ts, " - " pg_last_xlog_receive_location() AS last_wal_receive_lsn, " - " pg_last_xlog_replay_location() AS last_wal_replay_lsn, " - " pg_last_xact_replay_timestamp() AS last_xact_replay_timestamp "); + " pg_catalog.pg_last_xlog_receive_location() AS last_wal_receive_lsn, " + " pg_catalog.pg_last_xlog_replay_location() AS last_wal_replay_lsn, " + " pg_catalog.pg_last_xact_replay_timestamp() AS last_xact_replay_timestamp "); } appendPQExpBuffer( @@ -1485,7 +1485,7 @@ get_replication_lag_seconds(PGconn *conn) appendPQExpBuffer( &query, " THEN 0 " - " ELSE EXTRACT(epoch FROM (clock_timestamp() - pg_catalog.pg_last_xact_replay_timestamp()))::INT " + " ELSE EXTRACT(epoch FROM (pg_catalog.clock_timestamp() - pg_catalog.pg_last_xact_replay_timestamp()))::INT " " END " " AS lag_seconds"); diff --git a/repmgrd-physical.c b/repmgrd-physical.c index 162501bd..694ecde8 100644 --- a/repmgrd-physical.c +++ b/repmgrd-physical.c @@ -1264,6 +1264,7 @@ do_upstream_standby_failover(void) RecordStatus record_status = RECORD_NOT_FOUND; RecoveryType primary_type = RECTYPE_UNKNOWN; int r; + char parsed_follow_command[MAXPGPATH] = ""; PQfinish(upstream_conn); upstream_conn = NULL; @@ -1315,7 +1316,13 @@ do_upstream_standby_failover(void) log_debug(_("standby follow command is:\n \"%s\""), config_file_options.follow_command); - r = system(config_file_options.follow_command); + /* + * replace %n in "config_file_options.follow_command" with ID of primary + * to follow. + */ + parse_follow_command(parsed_follow_command, config_file_options.follow_command, primary_node_info.node_id); + + r = system(parsed_follow_command); if (r != 0) {