mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-27 17:06:29 +00:00
Add name to nodes and show it for the standby in repl_status.
This commit is contained in:
6
config.c
6
config.c
@@ -203,6 +203,12 @@ reload_configuration(char *config_file, t_configuration_options *orig_options)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (new_options.standby_name != orig_options->standby_name)
|
||||||
|
{
|
||||||
|
log_warning(_("\nCannot change standby name, will keep current configuration.\n"));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (new_options.failover != MANUAL_FAILOVER && new_options.failover != AUTOMATIC_FAILOVER)
|
if (new_options.failover != MANUAL_FAILOVER && new_options.failover != AUTOMATIC_FAILOVER)
|
||||||
{
|
{
|
||||||
log_warning(_("\nNew value for failover is not valid. Should be MANUAL or AUTOMATIC.\n"));
|
log_warning(_("\nNew value for failover is not valid. Should be MANUAL or AUTOMATIC.\n"));
|
||||||
|
|||||||
31
repmgr.c
31
repmgr.c
@@ -518,9 +518,10 @@ do_master_register(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sqlquery_snprintf(sqlquery, "INSERT INTO %s.repl_nodes (id, cluster, conninfo, priority) "
|
sqlquery_snprintf(sqlquery, "INSERT INTO %s.repl_nodes (id, cluster, name, conninfo, priority) "
|
||||||
"VALUES (%d, '%s', '%s', %d)",
|
"VALUES (%d, '%s', '%s', %d)",
|
||||||
repmgr_schema, options.node, options.cluster_name, options.conninfo, options.priority);
|
repmgr_schema, options.node, options.cluster_name, options.standby_name,
|
||||||
|
options.conninfo, options.priority);
|
||||||
log_debug(_("master register: %s\n"), sqlquery);
|
log_debug(_("master register: %s\n"), sqlquery);
|
||||||
|
|
||||||
if (!PQexec(conn, sqlquery))
|
if (!PQexec(conn, sqlquery))
|
||||||
@@ -660,9 +661,10 @@ do_standby_register(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sqlquery_snprintf(sqlquery, "INSERT INTO %s.repl_nodes(id, cluster, conninfo, priority) "
|
sqlquery_snprintf(sqlquery, "INSERT INTO %s.repl_nodes(id, cluster, name, conninfo, priority) "
|
||||||
"VALUES (%d, '%s', '%s', %d)",
|
"VALUES (%d, '%s', '%s', %d)",
|
||||||
repmgr_schema, options.node, options.cluster_name, options.conninfo, options.priority);
|
repmgr_schema, options.node, options.cluster_name, options.standby_name,
|
||||||
|
options.conninfo, options.priority);
|
||||||
log_debug(_("standby register: %s\n"), sqlquery);
|
log_debug(_("standby register: %s\n"), sqlquery);
|
||||||
|
|
||||||
if (!PQexec(master_conn, sqlquery))
|
if (!PQexec(master_conn, sqlquery))
|
||||||
@@ -1923,6 +1925,7 @@ create_schema(PGconn *conn)
|
|||||||
sqlquery_snprintf(sqlquery, "CREATE TABLE %s.repl_nodes ( "
|
sqlquery_snprintf(sqlquery, "CREATE TABLE %s.repl_nodes ( "
|
||||||
" id integer primary key, "
|
" id integer primary key, "
|
||||||
" cluster text not null, "
|
" cluster text not null, "
|
||||||
|
" name text not null, "
|
||||||
" conninfo text not null, "
|
" conninfo text not null, "
|
||||||
" priority integer not null, "
|
" priority integer not null, "
|
||||||
" witness boolean not null default false)", repmgr_schema);
|
" witness boolean not null default false)", repmgr_schema);
|
||||||
@@ -1954,14 +1957,15 @@ create_schema(PGconn *conn)
|
|||||||
|
|
||||||
/* a view */
|
/* a view */
|
||||||
sqlquery_snprintf(sqlquery, "CREATE VIEW %s.repl_status AS "
|
sqlquery_snprintf(sqlquery, "CREATE VIEW %s.repl_status AS "
|
||||||
" SELECT primary_node, standby_node, last_monitor_time, last_wal_primary_location, "
|
" SELECT primary_node, standby_node, name AS standby_name, last_monitor_time, "
|
||||||
" last_wal_standby_location, pg_size_pretty(replication_lag) replication_lag, "
|
" last_wal_primary_location, last_wal_standby_location, "
|
||||||
|
" pg_size_pretty(replication_lag) replication_lag, "
|
||||||
" pg_size_pretty(apply_lag) apply_lag, "
|
" pg_size_pretty(apply_lag) apply_lag, "
|
||||||
" age(now(), last_monitor_time) AS time_lag "
|
" age(now(), last_monitor_time) AS time_lag "
|
||||||
" FROM %s.repl_monitor "
|
" FROM %s.repl_monitor JOIN %s.repl_nodes ON standby_node = id "
|
||||||
" WHERE (standby_node, last_monitor_time) IN (SELECT standby_node, MAX(last_monitor_time) "
|
" WHERE (standby_node, last_monitor_time) IN (SELECT standby_node, MAX(last_monitor_time) "
|
||||||
" FROM %s.repl_monitor GROUP BY 1)",
|
" FROM %s.repl_monitor GROUP BY 1)",
|
||||||
repmgr_schema, repmgr_schema, repmgr_schema);
|
repmgr_schema, repmgr_schema, repmgr_schema, repmgr_schema);
|
||||||
log_debug(_("master register: %s\n"), sqlquery);
|
log_debug(_("master register: %s\n"), sqlquery);
|
||||||
if (!PQexec(conn, sqlquery))
|
if (!PQexec(conn, sqlquery))
|
||||||
{
|
{
|
||||||
@@ -2027,7 +2031,7 @@ copy_configuration(PGconn *masterconn, PGconn *witnessconn)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
sqlquery_snprintf(sqlquery, "SELECT id, conninfo, priority, witness FROM %s.repl_nodes", repmgr_schema);
|
sqlquery_snprintf(sqlquery, "SELECT id, name, conninfo, priority, witness FROM %s.repl_nodes", repmgr_schema);
|
||||||
res = PQexec(masterconn, sqlquery);
|
res = PQexec(masterconn, sqlquery);
|
||||||
if (PQresultStatus(res) != PGRES_TUPLES_OK)
|
if (PQresultStatus(res) != PGRES_TUPLES_OK)
|
||||||
{
|
{
|
||||||
@@ -2038,12 +2042,13 @@ copy_configuration(PGconn *masterconn, PGconn *witnessconn)
|
|||||||
}
|
}
|
||||||
for (i = 0; i < PQntuples(res); i++)
|
for (i = 0; i < PQntuples(res); i++)
|
||||||
{
|
{
|
||||||
sqlquery_snprintf(sqlquery, "INSERT INTO %s.repl_nodes(id, cluster, conninfo, priority, witness) "
|
sqlquery_snprintf(sqlquery, "INSERT INTO %s.repl_nodes(id, cluster, name, conninfo, priority, witness) "
|
||||||
"VALUES (%d, '%s', '%s', %d, '%s')",
|
"VALUES (%d, '%s', '%s', '%s', %d, '%s')",
|
||||||
repmgr_schema, atoi(PQgetvalue(res, i, 0)),
|
repmgr_schema, atoi(PQgetvalue(res, i, 0)),
|
||||||
options.cluster_name, PQgetvalue(res, i, 1),
|
options.cluster_name, PQgetvalue(res, i, 1),
|
||||||
atoi(PQgetvalue(res, i, 2)),
|
PQgetvalue(res, i, 2),
|
||||||
PQgetvalue(res, i, 3));
|
atoi(PQgetvalue(res, i, 3)),
|
||||||
|
PQgetvalue(res, i, 4));
|
||||||
|
|
||||||
if (!PQexec(witnessconn, sqlquery))
|
if (!PQexec(witnessconn, sqlquery))
|
||||||
{
|
{
|
||||||
|
|||||||
15
repmgr.sql
15
repmgr.sql
@@ -14,8 +14,11 @@ CREATE SCHEMA repmgr;
|
|||||||
*/
|
*/
|
||||||
CREATE TABLE repl_nodes (
|
CREATE TABLE repl_nodes (
|
||||||
id integer primary key,
|
id integer primary key,
|
||||||
cluster text not null, -- Name to identify the cluster
|
cluster text not null, -- Name to identify the cluster
|
||||||
conninfo text not null
|
name text not null,
|
||||||
|
conninfo text not null,
|
||||||
|
priority integer not null,
|
||||||
|
witness boolean not null default false
|
||||||
);
|
);
|
||||||
ALTER TABLE repl_nodes OWNER TO repmgr;
|
ALTER TABLE repl_nodes OWNER TO repmgr;
|
||||||
|
|
||||||
@@ -34,8 +37,6 @@ CREATE TABLE repl_monitor (
|
|||||||
);
|
);
|
||||||
ALTER TABLE repl_monitor OWNER TO repmgr;
|
ALTER TABLE repl_monitor OWNER TO repmgr;
|
||||||
|
|
||||||
CREATE INDEX idx_repl_monitor_last_monitor_sort ON repl_monitor(last_monitor_time, standby_node);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This view shows the latest monitor info about every node.
|
* This view shows the latest monitor info about every node.
|
||||||
* Interesting thing to see:
|
* Interesting thing to see:
|
||||||
@@ -47,12 +48,14 @@ CREATE INDEX idx_repl_monitor_last_monitor_sort ON repl_monitor(last_monitor_tim
|
|||||||
* time_lag: how many seconds are we from being up-to-date with master
|
* time_lag: how many seconds are we from being up-to-date with master
|
||||||
*/
|
*/
|
||||||
CREATE VIEW repl_status AS
|
CREATE VIEW repl_status AS
|
||||||
SELECT primary_node, standby_node, last_monitor_time, last_wal_primary_location,
|
SELECT primary_node, standby_node, name AS standby_name, last_monitor_time, last_wal_primary_location,
|
||||||
last_wal_standby_location, pg_size_pretty(replication_lag) replication_lag,
|
last_wal_standby_location, pg_size_pretty(replication_lag) replication_lag,
|
||||||
pg_size_pretty(apply_lag) apply_lag,
|
pg_size_pretty(apply_lag) apply_lag,
|
||||||
age(now(), last_monitor_time) AS time_lag
|
age(now(), last_monitor_time) AS time_lag
|
||||||
FROM repl_monitor
|
FROM repl_monitor JOIN repl_nodes ON standby_node = id
|
||||||
WHERE (standby_node, last_monitor_time) IN (SELECT standby_node, MAX(last_monitor_time)
|
WHERE (standby_node, last_monitor_time) IN (SELECT standby_node, MAX(last_monitor_time)
|
||||||
FROM repl_monitor GROUP BY 1);
|
FROM repl_monitor GROUP BY 1);
|
||||||
|
|
||||||
ALTER VIEW repl_status OWNER TO repmgr;
|
ALTER VIEW repl_status OWNER TO repmgr;
|
||||||
|
|
||||||
|
CREATE INDEX idx_repl_status_sort ON repl_monitor(last_monitor_time, standby_node);
|
||||||
|
|||||||
@@ -858,9 +858,10 @@ checkNodeConfiguration(char *conninfo)
|
|||||||
log_info(_("%s Adding node %d to cluster '%s'\n"),
|
log_info(_("%s Adding node %d to cluster '%s'\n"),
|
||||||
progname, local_options.node, local_options.cluster_name);
|
progname, local_options.node, local_options.cluster_name);
|
||||||
sqlquery_snprintf(sqlquery, "INSERT INTO %s.repl_nodes "
|
sqlquery_snprintf(sqlquery, "INSERT INTO %s.repl_nodes "
|
||||||
"VALUES (%d, '%s', '%s', 'f')",
|
"VALUES (%d, '%s', '%s', '%s', 0, 'f')",
|
||||||
repmgr_schema, local_options.node,
|
repmgr_schema, local_options.node,
|
||||||
local_options.cluster_name,
|
local_options.cluster_name,
|
||||||
|
local_options.standby_name,
|
||||||
local_options.conninfo);
|
local_options.conninfo);
|
||||||
|
|
||||||
if (!PQexec(primaryConn, sqlquery))
|
if (!PQexec(primaryConn, sqlquery))
|
||||||
|
|||||||
Reference in New Issue
Block a user