cluster show: display timeline ID

This helps provide a better picture of the state of the cluster, i.e.
making it more obvious whether there's been a timeline divergence.

This also provides infrastructure for further improvements in cluster
status display and diagnosis.

Note this is only available in PostgreSQL 9.6 and later as it relies
on the SQL functions for interrogating pg_control, which can be executed
remotely. As PostgreSQL 9.5 will shortly be the only community-supported
version without these functions, it's not worth the effort of trying
to duplicate their functionality.
This commit is contained in:
Ian Barwick
2019-05-27 09:15:12 +09:00
parent df6d160d2e
commit c560dfbbce
6 changed files with 133 additions and 23 deletions

View File

@@ -1600,7 +1600,7 @@ system_identifier(PGconn *conn)
if (PQresultStatus(res) != PGRES_TUPLES_OK)
{
log_db_error(conn, NULL, _("get_system_identifier(): unable to query pg_control_system()"));
log_db_error(conn, NULL, _("system_identifier(): unable to query pg_control_system()"));
}
else
{
@@ -3407,6 +3407,10 @@ clear_node_info_list(NodeInfoList *nodes)
while (cell != NULL)
{
next_cell = cell->next;
if (cell->node_info->replication_info != NULL)
pfree(cell->node_info->replication_info);
pfree(cell->node_info);
pfree(cell);
cell = next_cell;
@@ -5073,6 +5077,7 @@ init_replication_info(ReplInfo *replication_info)
{
memset(replication_info->current_timestamp, 0, sizeof(replication_info->current_timestamp));
replication_info->in_recovery = false;
replication_info->timeline_id = UNKNOWN_TIMELINE_ID;
replication_info->last_wal_receive_lsn = InvalidXLogRecPtr;
replication_info->last_wal_replay_lsn = InvalidXLogRecPtr;
memset(replication_info->last_xact_replay_timestamp, 0, sizeof(replication_info->last_xact_replay_timestamp));
@@ -5259,6 +5264,38 @@ get_replication_lag_seconds(PGconn *conn)
}
TimeLineID
get_node_timeline(PGconn *conn)
{
TimeLineID timeline_id = UNKNOWN_TIMELINE_ID;
PGresult *res = NULL;
/*
* PG_control_checkpoint() was introduced in PostgreSQL 9.6
*/
if (PQserverVersion(conn) < 90600)
{
return UNKNOWN_TIMELINE_ID;
}
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);
return timeline_id;
}
void
get_node_replication_stats(PGconn *conn, t_node_info *node_info)
{