mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-26 16:46:28 +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 */
|
/* result functions */
|
||||||
/* ================ */
|
/* ================ */
|
||||||
|
|||||||
12
dbutils.h
12
dbutils.h
@@ -264,7 +264,18 @@ typedef struct
|
|||||||
|
|
||||||
#define T_CONFIGFILE_LIST_INITIALIZER { 0, 0, NULL }
|
#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 */
|
/* global variables */
|
||||||
|
|
||||||
extern int server_version_num;
|
extern int server_version_num;
|
||||||
@@ -333,6 +344,7 @@ RecoveryType get_recovery_type(PGconn *conn);
|
|||||||
int get_primary_node_id(PGconn *conn);
|
int get_primary_node_id(PGconn *conn);
|
||||||
bool can_use_pg_rewind(PGconn *conn, const char *data_directory, PQExpBufferData *reason);
|
bool can_use_pg_rewind(PGconn *conn, const char *data_directory, PQExpBufferData *reason);
|
||||||
int get_ready_archive_files(PGconn *conn, const char *data_directory);
|
int get_ready_archive_files(PGconn *conn, const char *data_directory);
|
||||||
|
bool identify_system(PGconn *replconn, t_system_identification *identification);
|
||||||
|
|
||||||
/* extension functions */
|
/* extension functions */
|
||||||
ExtensionStatus get_repmgr_extension_status(PGconn *conn);
|
ExtensionStatus get_repmgr_extension_status(PGconn *conn);
|
||||||
|
|||||||
@@ -96,6 +96,28 @@ do_node_status(void)
|
|||||||
|
|
||||||
get_node_replication_stats(conn, &node_info);
|
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(
|
key_value_list_set(
|
||||||
&node_status,
|
&node_status,
|
||||||
"PostgreSQL version",
|
"PostgreSQL version",
|
||||||
|
|||||||
1
repmgr.h
1
repmgr.h
@@ -33,6 +33,7 @@
|
|||||||
#define REPLICATION_TYPE_BDR 2
|
#define REPLICATION_TYPE_BDR 2
|
||||||
|
|
||||||
#define UNKNOWN_SERVER_VERSION_NUM -1
|
#define UNKNOWN_SERVER_VERSION_NUM -1
|
||||||
|
#define UNKNOWN_TIMELINE_ID -1
|
||||||
|
|
||||||
#define NODE_NOT_FOUND -1
|
#define NODE_NOT_FOUND -1
|
||||||
#define NO_UPSTREAM_NODE -1
|
#define NO_UPSTREAM_NODE -1
|
||||||
|
|||||||
Reference in New Issue
Block a user