From 50b82f785e9b72270f00f9474df37ae2ea1ce779 Mon Sep 17 00:00:00 2001 From: Ian Barwick Date: Fri, 11 Aug 2017 22:01:02 +0900 Subject: [PATCH] Add function to execute "IDENTIFY_SYSTEM" --- dbutils.c | 22 ++++++++++++++++++++++ dbutils.h | 12 ++++++++++++ repmgr-action-node.c | 22 ++++++++++++++++++++++ repmgr.h | 1 + 4 files changed, 57 insertions(+) diff --git a/dbutils.c b/dbutils.c index 93b7449f..849f4d23 100644 --- a/dbutils.c +++ b/dbutils.c @@ -1442,6 +1442,28 @@ get_replication_lag_seconds(PGconn *conn) } +bool +identify_system(PGconn *replconn, t_system_identification *identification) +{ + PGresult *res; + + res = PQexec(replconn, "IDENTIFY_SYSTEM;"); + + if (PQresultStatus(res) != PGRES_TUPLES_OK || !PQntuples(res)) + { + PQclear(res); + return false; + } + + strncpy(identification->systemid, PQgetvalue(res, 0, 0), MAXLEN); + identification->timeline = atoi(PQgetvalue(res, 0, 1)); + identification->xlogpos = parse_lsn(PQgetvalue(res, 0, 2)); + + PQclear(res); + return true; +} + + /* ================ */ /* result functions */ /* ================ */ diff --git a/dbutils.h b/dbutils.h index 2bd2123a..006426f2 100644 --- a/dbutils.h +++ b/dbutils.h @@ -264,7 +264,18 @@ typedef struct #define T_CONFIGFILE_LIST_INITIALIZER { 0, 0, NULL } +typedef struct +{ + char systemid[MAXLEN]; + int timeline; + XLogRecPtr xlogpos; +} t_system_identification; +#define T_SYSTEM_IDENTIFICATION_INITIALIZER { \ + "", \ + UNKNOWN_TIMELINE_ID, \ + InvalidXLogRecPtr \ +} /* global variables */ extern int server_version_num; @@ -333,6 +344,7 @@ RecoveryType get_recovery_type(PGconn *conn); int get_primary_node_id(PGconn *conn); bool can_use_pg_rewind(PGconn *conn, const char *data_directory, PQExpBufferData *reason); int get_ready_archive_files(PGconn *conn, const char *data_directory); +bool identify_system(PGconn *replconn, t_system_identification *identification); /* extension functions */ ExtensionStatus get_repmgr_extension_status(PGconn *conn); diff --git a/repmgr-action-node.c b/repmgr-action-node.c index 53ef7c59..fe4cdf83 100644 --- a/repmgr-action-node.c +++ b/repmgr-action-node.c @@ -96,6 +96,28 @@ do_node_status(void) get_node_replication_stats(conn, &node_info); + /* get system information */ + { + t_conninfo_param_list repl_conninfo; + PGconn *replication_conn; + t_system_identification sysid = T_SYSTEM_IDENTIFICATION_INITIALIZER; + initialize_conninfo_params(&repl_conninfo, false); + + conn_to_param_list(conn, &repl_conninfo); + + param_set(&repl_conninfo, "replication", "1"); + + param_set(&repl_conninfo, "user", node_info.repluser); + + + replication_conn = establish_db_connection_by_params(&repl_conninfo, false); + identify_system(replication_conn, &sysid); + + printf("%s\n", sysid.systemid); + exit(0); + + } + key_value_list_set( &node_status, "PostgreSQL version", diff --git a/repmgr.h b/repmgr.h index 9aa17356..3fa783c0 100644 --- a/repmgr.h +++ b/repmgr.h @@ -33,6 +33,7 @@ #define REPLICATION_TYPE_BDR 2 #define UNKNOWN_SERVER_VERSION_NUM -1 +#define UNKNOWN_TIMELINE_ID -1 #define NODE_NOT_FOUND -1 #define NO_UPSTREAM_NODE -1