mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-27 17:06:29 +00:00
Add CLUSTER SHOW command to show the current nodes configured
This commit is contained in:
77
repmgr.c
77
repmgr.c
@@ -7,7 +7,7 @@
|
|||||||
*
|
*
|
||||||
* Commands implemented are.
|
* Commands implemented are.
|
||||||
* MASTER REGISTER, STANDBY REGISTER, STANDBY CLONE, STANDBY FOLLOW,
|
* MASTER REGISTER, STANDBY REGISTER, STANDBY CLONE, STANDBY FOLLOW,
|
||||||
* STANDBY PROMOTE
|
* STANDBY PROMOTE, CLUSTER SHOW
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -45,6 +45,7 @@
|
|||||||
#define STANDBY_CLONE 3
|
#define STANDBY_CLONE 3
|
||||||
#define STANDBY_PROMOTE 4
|
#define STANDBY_PROMOTE 4
|
||||||
#define STANDBY_FOLLOW 5
|
#define STANDBY_FOLLOW 5
|
||||||
|
#define CLUSTER_SHOW 6
|
||||||
|
|
||||||
static void help(const char *progname);
|
static void help(const char *progname);
|
||||||
static bool create_recovery_file(const char *data_dir, char *master_conninfo);
|
static bool create_recovery_file(const char *data_dir, char *master_conninfo);
|
||||||
@@ -57,7 +58,8 @@ static void do_standby_register(void);
|
|||||||
static void do_standby_clone(void);
|
static void do_standby_clone(void);
|
||||||
static void do_standby_promote(void);
|
static void do_standby_promote(void);
|
||||||
static void do_standby_follow(void);
|
static void do_standby_follow(void);
|
||||||
static void help(const char* progname);
|
static void do_cluster_show(void);
|
||||||
|
|
||||||
static void usage(void);
|
static void usage(void);
|
||||||
|
|
||||||
/* Global variables */
|
/* Global variables */
|
||||||
@@ -166,7 +168,8 @@ main(int argc, char **argv)
|
|||||||
/*
|
/*
|
||||||
* Now we need to obtain the action, this comes in one of these forms:
|
* Now we need to obtain the action, this comes in one of these forms:
|
||||||
* MASTER REGISTER |
|
* MASTER REGISTER |
|
||||||
* STANDBY {REGISTER | CLONE [node] | PROMOTE | FOLLOW [node]}
|
* STANDBY {REGISTER | CLONE [node] | PROMOTE | FOLLOW [node]} |
|
||||||
|
* CLUSTER SHOW
|
||||||
*
|
*
|
||||||
* the node part is optional, if we receive it then we shouldn't
|
* the node part is optional, if we receive it then we shouldn't
|
||||||
* have received a -h option
|
* have received a -h option
|
||||||
@@ -174,8 +177,8 @@ main(int argc, char **argv)
|
|||||||
if (optind < argc)
|
if (optind < argc)
|
||||||
{
|
{
|
||||||
server_mode = argv[optind++];
|
server_mode = argv[optind++];
|
||||||
if (strcasecmp(server_mode, "STANDBY") != 0 &&
|
if (strcasecmp(server_mode, "STANDBY") != 0 && strcasecmp(server_mode, "MASTER") != 0 &&
|
||||||
strcasecmp(server_mode, "MASTER") != 0)
|
strcasecmp(server_mode, "CLUSTER") != 0 )
|
||||||
{
|
{
|
||||||
usage();
|
usage();
|
||||||
exit(ERR_BAD_CONFIG);
|
exit(ERR_BAD_CONFIG);
|
||||||
@@ -204,12 +207,18 @@ main(int argc, char **argv)
|
|||||||
action = STANDBY_PROMOTE;
|
action = STANDBY_PROMOTE;
|
||||||
else if (strcasecmp(server_cmd, "FOLLOW") == 0)
|
else if (strcasecmp(server_cmd, "FOLLOW") == 0)
|
||||||
action = STANDBY_FOLLOW;
|
action = STANDBY_FOLLOW;
|
||||||
else
|
else if (strcasecmp(server_mode, "CLUSTER") == 0)
|
||||||
|
{
|
||||||
|
if(strcasecmp(server_cmd, "SHOW") == 0)
|
||||||
|
action = CLUSTER_SHOW;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (action == NO_ACTION)
|
||||||
{
|
{
|
||||||
usage();
|
usage();
|
||||||
exit(ERR_BAD_CONFIG);
|
exit(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/* For some actions we still can receive a last argument */
|
/* For some actions we still can receive a last argument */
|
||||||
if (action == STANDBY_CLONE)
|
if (action == STANDBY_CLONE)
|
||||||
@@ -314,6 +323,9 @@ main(int argc, char **argv)
|
|||||||
case STANDBY_FOLLOW:
|
case STANDBY_FOLLOW:
|
||||||
do_standby_follow();
|
do_standby_follow();
|
||||||
break;
|
break;
|
||||||
|
case CLUSTER_SHOW:
|
||||||
|
do_cluster_show();
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
usage();
|
usage();
|
||||||
exit(ERR_BAD_CONFIG);
|
exit(ERR_BAD_CONFIG);
|
||||||
@@ -323,6 +335,52 @@ main(int argc, char **argv)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
do_cluster_show(void)
|
||||||
|
{
|
||||||
|
PGconn *conn;
|
||||||
|
PGresult *res;
|
||||||
|
char sqlquery[QUERY_STR_LEN];
|
||||||
|
char node_role[MAXLEN];
|
||||||
|
int i;
|
||||||
|
|
||||||
|
/* We need to connect to check configuration */
|
||||||
|
log_info(_("%s connecting to database\n"), progname);
|
||||||
|
conn = establishDBConnection(options.conninfo, true);
|
||||||
|
|
||||||
|
sqlquery_snprintf(sqlquery, "SELECT conninfo FROM %s.repl_nodes;", repmgr_schema);
|
||||||
|
res = PQexec(conn, sqlquery);
|
||||||
|
|
||||||
|
if (PQresultStatus(res) != PGRES_TUPLES_OK)
|
||||||
|
{
|
||||||
|
log_err(_("Can't get nodes informations, have you regitered them?\n%s\n"), PQerrorMessage(conn));
|
||||||
|
PQclear(res);
|
||||||
|
PQfinish(conn);
|
||||||
|
exit(ERR_BAD_CONFIG);
|
||||||
|
}
|
||||||
|
PQclear(res);
|
||||||
|
PQfinish(conn);
|
||||||
|
|
||||||
|
printf("Role | Connection String \n");
|
||||||
|
for (i = 0; i < PQntuples(res); i++)
|
||||||
|
{
|
||||||
|
conn = establishDBConnection(PQgetvalue(res, i, 0), false);
|
||||||
|
if (PQstatus(conn) != CONNECTION_OK)
|
||||||
|
strcpy(node_role, " FAILED");
|
||||||
|
else if (is_standby(conn))
|
||||||
|
strcpy(node_role, " standby");
|
||||||
|
else
|
||||||
|
strcpy(node_role, "* master");
|
||||||
|
|
||||||
|
printf("%-10s", node_role);
|
||||||
|
printf("| %s\n", PQgetvalue(res, i, 0));
|
||||||
|
|
||||||
|
PQclear(res);
|
||||||
|
PQfinish(conn);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
do_master_register(void)
|
do_master_register(void)
|
||||||
{
|
{
|
||||||
@@ -1351,6 +1409,7 @@ void help(const char *progname)
|
|||||||
printf(_(" %s [OPTIONS] master {register}\n"), progname);
|
printf(_(" %s [OPTIONS] master {register}\n"), progname);
|
||||||
printf(_(" %s [OPTIONS] standby {register|clone|promote|follow}\n"),
|
printf(_(" %s [OPTIONS] standby {register|clone|promote|follow}\n"),
|
||||||
progname);
|
progname);
|
||||||
|
printf(_(" %s [OPTIONS] cluster show\n"), progname);
|
||||||
printf(_("\nGeneral options:\n"));
|
printf(_("\nGeneral options:\n"));
|
||||||
printf(_(" --help show this help, then exit\n"));
|
printf(_(" --help show this help, then exit\n"));
|
||||||
printf(_(" --version output version information, then exit\n"));
|
printf(_(" --version output version information, then exit\n"));
|
||||||
@@ -1377,6 +1436,7 @@ void help(const char *progname)
|
|||||||
printf(_(" standby promote - allows manual promotion of a specific standby into a "));
|
printf(_(" standby promote - allows manual promotion of a specific standby into a "));
|
||||||
printf(_("new master in the event of a failover\n"));
|
printf(_("new master in the event of a failover\n"));
|
||||||
printf(_(" standby follow - allows the standby to re-point itself to a new master\n"));
|
printf(_(" standby follow - allows the standby to re-point itself to a new master\n"));
|
||||||
|
printf(_(" cluster show - print node informations\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1652,6 +1712,9 @@ check_parameters_for_action(const int action)
|
|||||||
}
|
}
|
||||||
need_a_node = false;
|
need_a_node = false;
|
||||||
break;
|
break;
|
||||||
|
case CLUSTER_SHOW:
|
||||||
|
/* allow all parameters to be supplied */
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ok;
|
return ok;
|
||||||
|
|||||||
Reference in New Issue
Block a user