mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-26 00:26:30 +00:00
repmgrd: parse "follow_command" during cascaded standby failover
This commit is contained in:
18
dbutils.c
18
dbutils.c
@@ -1125,7 +1125,7 @@ _get_primary_connection(PGconn *conn,
|
|||||||
node_id = atoi(PQgetvalue(res, i, 0));
|
node_id = atoi(PQgetvalue(res, i, 0));
|
||||||
strncpy(remote_conninfo, PQgetvalue(res, i, 1), MAXCONNINFO);
|
strncpy(remote_conninfo, PQgetvalue(res, i, 1), MAXCONNINFO);
|
||||||
log_verbose(LOG_INFO,
|
log_verbose(LOG_INFO,
|
||||||
_("checking role of node '%i'"),
|
_("checking role of node %i"),
|
||||||
node_id);
|
node_id);
|
||||||
|
|
||||||
if (quiet)
|
if (quiet)
|
||||||
@@ -1257,7 +1257,7 @@ get_replication_info(PGconn *conn, ReplInfo *replication_info)
|
|||||||
" CASE WHEN (last_wal_receive_lsn = last_wal_replay_lsn) "
|
" CASE WHEN (last_wal_receive_lsn = last_wal_replay_lsn) "
|
||||||
" THEN 0::INT "
|
" THEN 0::INT "
|
||||||
" ELSE "
|
" 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, "
|
" END AS replication_lag_time, "
|
||||||
" COALESCE(last_wal_receive_lsn, '0/0') >= last_wal_replay_lsn AS receiving_streamed_wal "
|
" COALESCE(last_wal_receive_lsn, '0/0') >= last_wal_replay_lsn AS receiving_streamed_wal "
|
||||||
" FROM ( ");
|
" FROM ( ");
|
||||||
@@ -1267,18 +1267,18 @@ get_replication_info(PGconn *conn, ReplInfo *replication_info)
|
|||||||
appendPQExpBuffer(
|
appendPQExpBuffer(
|
||||||
&query,
|
&query,
|
||||||
" SELECT CURRENT_TIMESTAMP AS ts, "
|
" SELECT CURRENT_TIMESTAMP AS ts, "
|
||||||
" pg_last_wal_receive_lsn() AS last_wal_receive_lsn, "
|
" pg_catalog.pg_last_wal_receive_lsn() AS last_wal_receive_lsn, "
|
||||||
" pg_last_wal_replay_lsn() AS last_wal_replay_lsn, "
|
" pg_catalog.pg_last_wal_replay_lsn() AS last_wal_replay_lsn, "
|
||||||
" pg_last_xact_replay_timestamp() AS last_xact_replay_timestamp ");
|
" pg_catalog.pg_last_xact_replay_timestamp() AS last_xact_replay_timestamp ");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
appendPQExpBuffer(
|
appendPQExpBuffer(
|
||||||
&query,
|
&query,
|
||||||
" SELECT CURRENT_TIMESTAMP AS ts, "
|
" SELECT CURRENT_TIMESTAMP AS ts, "
|
||||||
" pg_last_xlog_receive_location() AS last_wal_receive_lsn, "
|
" pg_catalog.pg_last_xlog_receive_location() AS last_wal_receive_lsn, "
|
||||||
" pg_last_xlog_replay_location() AS last_wal_replay_lsn, "
|
" pg_catalog.pg_last_xlog_replay_location() AS last_wal_replay_lsn, "
|
||||||
" pg_last_xact_replay_timestamp() AS last_xact_replay_timestamp ");
|
" pg_catalog.pg_last_xact_replay_timestamp() AS last_xact_replay_timestamp ");
|
||||||
}
|
}
|
||||||
|
|
||||||
appendPQExpBuffer(
|
appendPQExpBuffer(
|
||||||
@@ -1485,7 +1485,7 @@ get_replication_lag_seconds(PGconn *conn)
|
|||||||
appendPQExpBuffer(
|
appendPQExpBuffer(
|
||||||
&query,
|
&query,
|
||||||
" THEN 0 "
|
" 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 "
|
" END "
|
||||||
" AS lag_seconds");
|
" AS lag_seconds");
|
||||||
|
|
||||||
|
|||||||
@@ -1264,6 +1264,7 @@ do_upstream_standby_failover(void)
|
|||||||
RecordStatus record_status = RECORD_NOT_FOUND;
|
RecordStatus record_status = RECORD_NOT_FOUND;
|
||||||
RecoveryType primary_type = RECTYPE_UNKNOWN;
|
RecoveryType primary_type = RECTYPE_UNKNOWN;
|
||||||
int r;
|
int r;
|
||||||
|
char parsed_follow_command[MAXPGPATH] = "";
|
||||||
|
|
||||||
PQfinish(upstream_conn);
|
PQfinish(upstream_conn);
|
||||||
upstream_conn = NULL;
|
upstream_conn = NULL;
|
||||||
@@ -1315,7 +1316,13 @@ do_upstream_standby_failover(void)
|
|||||||
log_debug(_("standby follow command is:\n \"%s\""),
|
log_debug(_("standby follow command is:\n \"%s\""),
|
||||||
config_file_options.follow_command);
|
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)
|
if (r != 0)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user