Add name to nodes and show it for the standby in repl_status.

This commit is contained in:
Jaime Casanova
2011-07-26 16:58:02 -05:00
parent 020e17b059
commit 276c947202
4 changed files with 35 additions and 20 deletions

View File

@@ -203,6 +203,12 @@ reload_configuration(char *config_file, t_configuration_options *orig_options)
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)
{
log_warning(_("\nNew value for failover is not valid. Should be MANUAL or AUTOMATIC.\n"));

View File

@@ -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)",
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);
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)",
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);
if (!PQexec(master_conn, sqlquery))
@@ -1923,6 +1925,7 @@ create_schema(PGconn *conn)
sqlquery_snprintf(sqlquery, "CREATE TABLE %s.repl_nodes ( "
" id integer primary key, "
" cluster text not null, "
" name text not null, "
" conninfo text not null, "
" priority integer not null, "
" witness boolean not null default false)", repmgr_schema);
@@ -1954,14 +1957,15 @@ create_schema(PGconn *conn)
/* a view */
sqlquery_snprintf(sqlquery, "CREATE VIEW %s.repl_status AS "
" SELECT primary_node, standby_node, last_monitor_time, last_wal_primary_location, "
" last_wal_standby_location, pg_size_pretty(replication_lag) replication_lag, "
" 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, "
" pg_size_pretty(apply_lag) apply_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) "
" 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);
if (!PQexec(conn, sqlquery))
{
@@ -2027,7 +2031,7 @@ copy_configuration(PGconn *masterconn, PGconn *witnessconn)
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);
if (PQresultStatus(res) != PGRES_TUPLES_OK)
{
@@ -2038,12 +2042,13 @@ copy_configuration(PGconn *masterconn, PGconn *witnessconn)
}
for (i = 0; i < PQntuples(res); i++)
{
sqlquery_snprintf(sqlquery, "INSERT INTO %s.repl_nodes(id, cluster, conninfo, priority, witness) "
"VALUES (%d, '%s', '%s', %d, '%s')",
sqlquery_snprintf(sqlquery, "INSERT INTO %s.repl_nodes(id, cluster, name, conninfo, priority, witness) "
"VALUES (%d, '%s', '%s', '%s', %d, '%s')",
repmgr_schema, atoi(PQgetvalue(res, i, 0)),
options.cluster_name, PQgetvalue(res, i, 1),
atoi(PQgetvalue(res, i, 2)),
PQgetvalue(res, i, 3));
PQgetvalue(res, i, 2),
atoi(PQgetvalue(res, i, 3)),
PQgetvalue(res, i, 4));
if (!PQexec(witnessconn, sqlquery))
{

View File

@@ -14,8 +14,11 @@ CREATE SCHEMA repmgr;
*/
CREATE TABLE repl_nodes (
id integer primary key,
cluster text not null, -- Name to identify the cluster
conninfo text not null
cluster text not null, -- Name to identify the cluster
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;
@@ -34,8 +37,6 @@ CREATE TABLE repl_monitor (
);
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.
* 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
*/
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,
pg_size_pretty(apply_lag) apply_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)
FROM repl_monitor GROUP BY 1);
ALTER VIEW repl_status OWNER TO repmgr;
CREATE INDEX idx_repl_status_sort ON repl_monitor(last_monitor_time, standby_node);

View File

@@ -858,9 +858,10 @@ checkNodeConfiguration(char *conninfo)
log_info(_("%s Adding node %d to cluster '%s'\n"),
progname, local_options.node, local_options.cluster_name);
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,
local_options.cluster_name,
local_options.standby_name,
local_options.conninfo);
if (!PQexec(primaryConn, sqlquery))