mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-26 08:36:30 +00:00
cluster show: don't display witness node timeline ID
The witness node is not part of the replication cluster, so its timeline ID is not of any relevance.
This commit is contained in:
40
dbutils.c
40
dbutils.c
@@ -5456,31 +5456,43 @@ get_replication_lag_seconds(PGconn *conn)
|
|||||||
|
|
||||||
|
|
||||||
TimeLineID
|
TimeLineID
|
||||||
get_node_timeline(PGconn *conn)
|
get_node_timeline(PGconn *conn, char *timeline_id_str)
|
||||||
{
|
{
|
||||||
TimeLineID timeline_id = UNKNOWN_TIMELINE_ID;
|
TimeLineID timeline_id = UNKNOWN_TIMELINE_ID;
|
||||||
PGresult *res = NULL;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* PG_control_checkpoint() was introduced in PostgreSQL 9.6
|
* PG_control_checkpoint() was introduced in PostgreSQL 9.6
|
||||||
*/
|
*/
|
||||||
if (PQserverVersion(conn) < 90600)
|
if (PQserverVersion(conn) >= 90600)
|
||||||
{
|
{
|
||||||
return UNKNOWN_TIMELINE_ID;
|
PGresult *res = NULL;
|
||||||
|
|
||||||
|
res = PQexec(conn, "SELECT timeline_id FROM pg_catalog.pg_control_checkpoint()");
|
||||||
|
|
||||||
|
if (PQresultStatus(res) != PGRES_TUPLES_OK)
|
||||||
|
{
|
||||||
|
log_db_error(conn, NULL, _("get_node_timeline(): unable to query pg_control_system()"));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
timeline_id = atoi(PQgetvalue(res, 0, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
PQclear(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
res = PQexec(conn, "SELECT timeline_id FROM pg_catalog.pg_control_checkpoint()");
|
/* If requested, format the timeline ID as a string */
|
||||||
|
if (timeline_id_str != NULL)
|
||||||
if (PQresultStatus(res) != PGRES_TUPLES_OK)
|
|
||||||
{
|
{
|
||||||
log_db_error(conn, NULL, _("get_node_timeline(): unable to query pg_control_system()"));
|
if (timeline_id == UNKNOWN_TIMELINE_ID)
|
||||||
|
{
|
||||||
|
strncpy(timeline_id_str, "?", MAXLEN);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
snprintf(timeline_id_str, MAXLEN, "%i", timeline_id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
timeline_id = atoi(PQgetvalue(res, 0, 0));
|
|
||||||
}
|
|
||||||
|
|
||||||
PQclear(res);
|
|
||||||
|
|
||||||
return timeline_id;
|
return timeline_id;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -166,6 +166,7 @@ typedef struct
|
|||||||
char current_timestamp[MAXLEN];
|
char current_timestamp[MAXLEN];
|
||||||
bool in_recovery;
|
bool in_recovery;
|
||||||
TimeLineID timeline_id;
|
TimeLineID timeline_id;
|
||||||
|
char timeline_id_str[MAXLEN];
|
||||||
XLogRecPtr last_wal_receive_lsn;
|
XLogRecPtr last_wal_receive_lsn;
|
||||||
XLogRecPtr last_wal_replay_lsn;
|
XLogRecPtr last_wal_replay_lsn;
|
||||||
char last_xact_replay_timestamp[MAXLEN];
|
char last_xact_replay_timestamp[MAXLEN];
|
||||||
@@ -575,7 +576,7 @@ XLogRecPtr get_last_wal_receive_location(PGconn *conn);
|
|||||||
void init_replication_info(ReplInfo *replication_info);
|
void init_replication_info(ReplInfo *replication_info);
|
||||||
bool get_replication_info(PGconn *conn, t_server_type node_type, ReplInfo *replication_info);
|
bool get_replication_info(PGconn *conn, t_server_type node_type, ReplInfo *replication_info);
|
||||||
int get_replication_lag_seconds(PGconn *conn);
|
int get_replication_lag_seconds(PGconn *conn);
|
||||||
TimeLineID get_node_timeline(PGconn *conn);
|
TimeLineID get_node_timeline(PGconn *conn, char *timeline_id_str);
|
||||||
void get_node_replication_stats(PGconn *conn, t_node_info *node_info);
|
void get_node_replication_stats(PGconn *conn, t_node_info *node_info);
|
||||||
NodeAttached is_downstream_node_attached(PGconn *conn, char *node_name);
|
NodeAttached is_downstream_node_attached(PGconn *conn, char *node_name);
|
||||||
void set_upstream_last_seen(PGconn *conn, int upstream_node_id);
|
void set_upstream_last_seen(PGconn *conn, int upstream_node_id);
|
||||||
|
|||||||
@@ -206,7 +206,8 @@ do_cluster_show(void)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* NOP on pre-9.6 servers */
|
/* NOP on pre-9.6 servers */
|
||||||
cell->node_info->replication_info->timeline_id = get_node_timeline(cell->node_info->conn);
|
cell->node_info->replication_info->timeline_id = get_node_timeline(cell->node_info->conn,
|
||||||
|
cell->node_info->replication_info->timeline_id_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
initPQExpBuffer(&node_status);
|
initPQExpBuffer(&node_status);
|
||||||
@@ -244,18 +245,13 @@ do_cluster_show(void)
|
|||||||
|
|
||||||
headers_show[SHOW_LOCATION].cur_length = strlen(cell->node_info->location);
|
headers_show[SHOW_LOCATION].cur_length = strlen(cell->node_info->location);
|
||||||
|
|
||||||
if (cell->node_info->replication_info->timeline_id == UNKNOWN_TIMELINE_ID)
|
/* Format timeline ID */
|
||||||
|
if (cell->node_info->type == WITNESS)
|
||||||
{
|
{
|
||||||
/* display "?" */
|
/* The witness node's timeline ID is irrelevant */
|
||||||
headers_show[SHOW_TIMELINE_ID].cur_length = 1;
|
strncpy(cell->node_info->replication_info->timeline_id_str, _("n/a"), MAXLEN);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
initPQExpBuffer(&buf);
|
|
||||||
appendPQExpBuffer(&buf, "%i", cell->node_info->replication_info->timeline_id);
|
|
||||||
headers_show[SHOW_TIMELINE_ID].cur_length = strlen(buf.data);
|
|
||||||
termPQExpBuffer(&buf);
|
|
||||||
}
|
}
|
||||||
|
headers_show[SHOW_TIMELINE_ID].cur_length = strlen(cell->node_info->replication_info->timeline_id_str);
|
||||||
|
|
||||||
headers_show[SHOW_CONNINFO].cur_length = strlen(cell->node_info->conninfo);
|
headers_show[SHOW_CONNINFO].cur_length = strlen(cell->node_info->conninfo);
|
||||||
|
|
||||||
@@ -322,10 +318,7 @@ do_cluster_show(void)
|
|||||||
|
|
||||||
if (headers_show[SHOW_TIMELINE_ID].display == true)
|
if (headers_show[SHOW_TIMELINE_ID].display == true)
|
||||||
{
|
{
|
||||||
if (cell->node_info->replication_info->timeline_id == UNKNOWN_TIMELINE_ID)
|
printf("| %-*s ", headers_show[SHOW_TIMELINE_ID].max_length, cell->node_info->replication_info->timeline_id_str);
|
||||||
printf("| %-*c ", headers_show[SHOW_TIMELINE_ID].max_length, '?');
|
|
||||||
else
|
|
||||||
printf("| %-*i ", headers_show[SHOW_TIMELINE_ID].max_length, (int)cell->node_info->replication_info->timeline_id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (headers_show[SHOW_CONNINFO].display == true)
|
if (headers_show[SHOW_CONNINFO].display == true)
|
||||||
|
|||||||
Reference in New Issue
Block a user