mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-26 08:36:30 +00:00
Merge pull request #2 from 2ndquadrant-it/master
Add function to show nodes with actual roles: repmgr cluster show
This commit is contained in:
66
repmgr.c
66
repmgr.c
@@ -47,6 +47,7 @@
|
|||||||
#define STANDBY_PROMOTE 4
|
#define STANDBY_PROMOTE 4
|
||||||
#define STANDBY_FOLLOW 5
|
#define STANDBY_FOLLOW 5
|
||||||
#define WITNESS_CREATE 6
|
#define WITNESS_CREATE 6
|
||||||
|
#define CLUSTER_SHOW 7
|
||||||
|
|
||||||
static bool create_recovery_file(const char *data_dir);
|
static bool create_recovery_file(const char *data_dir);
|
||||||
static int test_ssh_connection(char *host, char *remote_user);
|
static int test_ssh_connection(char *host, char *remote_user);
|
||||||
@@ -63,6 +64,7 @@ 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 do_witness_create(void);
|
static void do_witness_create(void);
|
||||||
|
static void do_cluster_show(void);
|
||||||
|
|
||||||
static void usage(void);
|
static void usage(void);
|
||||||
static void help(const char *progname);
|
static void help(const char *progname);
|
||||||
@@ -180,6 +182,7 @@ main(int argc, char **argv)
|
|||||||
* MASTER REGISTER |
|
* MASTER REGISTER |
|
||||||
* STANDBY {REGISTER | CLONE [node] | PROMOTE | FOLLOW [node]} |
|
* STANDBY {REGISTER | CLONE [node] | PROMOTE | FOLLOW [node]} |
|
||||||
* WITNESS CREATE
|
* WITNESS CREATE
|
||||||
|
* 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
|
||||||
@@ -188,7 +191,8 @@ main(int argc, char **argv)
|
|||||||
{
|
{
|
||||||
server_mode = argv[optind++];
|
server_mode = argv[optind++];
|
||||||
if (strcasecmp(server_mode, "STANDBY") != 0 && strcasecmp(server_mode, "MASTER") != 0 &&
|
if (strcasecmp(server_mode, "STANDBY") != 0 && strcasecmp(server_mode, "MASTER") != 0 &&
|
||||||
strcasecmp(server_mode, "WITNESS") != 0)
|
strcasecmp(server_mode, "WITNESS") != 0 &&
|
||||||
|
strcasecmp(server_mode, "CLUSTER") != 0 )
|
||||||
{
|
{
|
||||||
usage();
|
usage();
|
||||||
exit(ERR_BAD_CONFIG);
|
exit(ERR_BAD_CONFIG);
|
||||||
@@ -215,6 +219,11 @@ main(int argc, char **argv)
|
|||||||
else if (strcasecmp(server_cmd, "FOLLOW") == 0)
|
else if (strcasecmp(server_cmd, "FOLLOW") == 0)
|
||||||
action = STANDBY_FOLLOW;
|
action = STANDBY_FOLLOW;
|
||||||
}
|
}
|
||||||
|
else if (strcasecmp(server_mode, "CLUSTER") == 0)
|
||||||
|
{
|
||||||
|
if( strcasecmp(server_cmd, "SHOW") == 0)
|
||||||
|
action = CLUSTER_SHOW;
|
||||||
|
}
|
||||||
else if (strcasecmp(server_mode, "WITNESS") == 0)
|
else if (strcasecmp(server_mode, "WITNESS") == 0)
|
||||||
if (strcasecmp(server_cmd, "CREATE") == 0)
|
if (strcasecmp(server_cmd, "CREATE") == 0)
|
||||||
action = WITNESS_CREATE;
|
action = WITNESS_CREATE;
|
||||||
@@ -336,6 +345,9 @@ main(int argc, char **argv)
|
|||||||
case WITNESS_CREATE:
|
case WITNESS_CREATE:
|
||||||
do_witness_create();
|
do_witness_create();
|
||||||
break;
|
break;
|
||||||
|
case CLUSTER_SHOW:
|
||||||
|
do_cluster_show();
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
usage();
|
usage();
|
||||||
exit(ERR_BAD_CONFIG);
|
exit(ERR_BAD_CONFIG);
|
||||||
@@ -345,6 +357,53 @@ 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);
|
||||||
|
}
|
||||||
|
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));
|
||||||
|
|
||||||
|
PQfinish(conn);
|
||||||
|
}
|
||||||
|
|
||||||
|
PQclear(res);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
do_master_register(void)
|
do_master_register(void)
|
||||||
{
|
{
|
||||||
@@ -1543,6 +1602,7 @@ 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"));
|
||||||
@@ -1570,6 +1630,7 @@ 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"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1831,6 +1892,9 @@ check_parameters_for_action(const int action)
|
|||||||
case WITNESS_CREATE:
|
case WITNESS_CREATE:
|
||||||
/* allow all parameters to be supplied */
|
/* allow all parameters to be supplied */
|
||||||
break;
|
break;
|
||||||
|
case CLUSTER_SHOW:
|
||||||
|
/* allow all parameters to be supplied */
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ok;
|
return ok;
|
||||||
|
|||||||
Reference in New Issue
Block a user