mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-22 22:56:29 +00:00
Add function to execute "IDENTIFY_SYSTEM"
This commit is contained in:
22
dbutils.c
22
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 */
|
||||
/* ================ */
|
||||
|
||||
12
dbutils.h
12
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);
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user