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:
Ian Barwick
2020-02-25 10:33:54 +09:00
parent 3b03edebb6
commit 76af2d9e08
3 changed files with 36 additions and 30 deletions

View File

@@ -5456,31 +5456,43 @@ get_replication_lag_seconds(PGconn *conn)
TimeLineID
get_node_timeline(PGconn *conn)
get_node_timeline(PGconn *conn, char *timeline_id_str)
{
TimeLineID timeline_id = UNKNOWN_TIMELINE_ID;
PGresult *res = NULL;
/*
* 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 (PQresultStatus(res) != PGRES_TUPLES_OK)
/* If requested, format the timeline ID as a string */
if (timeline_id_str != NULL)
{
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;
}

View File

@@ -166,6 +166,7 @@ typedef struct
char current_timestamp[MAXLEN];
bool in_recovery;
TimeLineID timeline_id;
char timeline_id_str[MAXLEN];
XLogRecPtr last_wal_receive_lsn;
XLogRecPtr last_wal_replay_lsn;
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);
bool get_replication_info(PGconn *conn, t_server_type node_type, ReplInfo *replication_info);
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);
NodeAttached is_downstream_node_attached(PGconn *conn, char *node_name);
void set_upstream_last_seen(PGconn *conn, int upstream_node_id);

View File

@@ -206,7 +206,8 @@ do_cluster_show(void)
else
{
/* 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);
@@ -244,18 +245,13 @@ do_cluster_show(void)
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 "?" */
headers_show[SHOW_TIMELINE_ID].cur_length = 1;
}
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);
/* The witness node's timeline ID is irrelevant */
strncpy(cell->node_info->replication_info->timeline_id_str, _("n/a"), MAXLEN);
}
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);
@@ -322,10 +318,7 @@ do_cluster_show(void)
if (headers_show[SHOW_TIMELINE_ID].display == true)
{
if (cell->node_info->replication_info->timeline_id == UNKNOWN_TIMELINE_ID)
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);
printf("| %-*s ", headers_show[SHOW_TIMELINE_ID].max_length, cell->node_info->replication_info->timeline_id_str);
}
if (headers_show[SHOW_CONNINFO].display == true)