mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-27 08:56:29 +00:00
Attack of whitespace pedantry
pgsql conventions (tabs, four-spaces-wide, etc) applied all around. Also tried to fix some very tiny capitalization errors, auto-fill problems, and some inter-block vertical whitespacing issues. Long strings in repmgr.c were left intact, though. They are rather numerous and are less of a problem than tiny bits of function calls and comments wrapping over a line; the latter kind of problem has been mostly fixed. Signed-off-by: Dan Farina <drfarina@acm.org> Signed-off-by: Peter van Hardenberg <pvh@heroku.com>
This commit is contained in:
committed by
Peter van Hardenberg
parent
56c65acd99
commit
af2edf10a0
6
config.c
6
config.c
@@ -8,7 +8,8 @@
|
|||||||
#include "repmgr.h"
|
#include "repmgr.h"
|
||||||
|
|
||||||
void
|
void
|
||||||
parse_config(const char *config_file, char *cluster_name, int *node, char *conninfo)
|
parse_config(const char *config_file, char *cluster_name, int *node,
|
||||||
|
char *conninfo)
|
||||||
{
|
{
|
||||||
char *s, buff[256];
|
char *s, buff[256];
|
||||||
FILE *fp = fopen (config_file, "r");
|
FILE *fp = fopen (config_file, "r");
|
||||||
@@ -37,7 +38,8 @@ parse_config(const char *config_file, char *cluster_name, int *node, char *conni
|
|||||||
else if (strcmp(name, "conninfo") == 0)
|
else if (strcmp(name, "conninfo") == 0)
|
||||||
strncpy (conninfo, value, MAXLEN);
|
strncpy (conninfo, value, MAXLEN);
|
||||||
else
|
else
|
||||||
printf ("WARNING: %s/%s: Unknown name/value pair!\n", name, value);
|
printf("WARNING: %s/%s: Unknown name/value pair!\n",
|
||||||
|
name, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Close file */
|
/* Close file */
|
||||||
|
|||||||
3
config.h
3
config.h
@@ -4,6 +4,7 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void parse_config(const char *config_file, char *cluster_name, int *node, char *service);
|
void parse_config(const char *config_file, char *cluster_name, int *node,
|
||||||
|
char *service);
|
||||||
void parse_line(char *buff, char *name, char *value);
|
void parse_line(char *buff, char *name, char *value);
|
||||||
char *trim(char *s);
|
char *trim(char *s);
|
||||||
|
|||||||
38
dbutils.c
38
dbutils.c
@@ -12,8 +12,10 @@ PGconn *
|
|||||||
establishDBConnection(const char *conninfo, const bool exit_on_error)
|
establishDBConnection(const char *conninfo, const bool exit_on_error)
|
||||||
{
|
{
|
||||||
PGconn *conn;
|
PGconn *conn;
|
||||||
|
|
||||||
/* Make a connection to the database */
|
/* Make a connection to the database */
|
||||||
conn = PQconnectdb(conninfo);
|
conn = PQconnectdb(conninfo);
|
||||||
|
|
||||||
/* Check to see that the backend connection was successfully made */
|
/* Check to see that the backend connection was successfully made */
|
||||||
if ((PQstatus(conn) != CONNECTION_OK))
|
if ((PQstatus(conn) != CONNECTION_OK))
|
||||||
{
|
{
|
||||||
@@ -38,6 +40,7 @@ is_standby(PGconn *conn)
|
|||||||
bool result;
|
bool result;
|
||||||
|
|
||||||
res = PQexec(conn, "SELECT pg_is_in_recovery()");
|
res = PQexec(conn, "SELECT pg_is_in_recovery()");
|
||||||
|
|
||||||
if (PQresultStatus(res) != PGRES_TUPLES_OK)
|
if (PQresultStatus(res) != PGRES_TUPLES_OK)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Can't query server mode: %s", PQerrorMessage(conn));
|
fprintf(stderr, "Can't query server mode: %s", PQerrorMessage(conn));
|
||||||
@@ -69,8 +72,12 @@ pg_version(PGconn *conn)
|
|||||||
int major_version1;
|
int major_version1;
|
||||||
char *major_version2;
|
char *major_version2;
|
||||||
|
|
||||||
res = PQexec(conn, "WITH pg_version(ver) AS (SELECT split_part(version(), ' ', 2)) "
|
res = PQexec(conn,
|
||||||
"SELECT split_part(ver, '.', 1), split_part(ver, '.', 2) FROM pg_version");
|
"WITH pg_version(ver) AS "
|
||||||
|
"(SELECT split_part(version(), ' ', 2)) "
|
||||||
|
"SELECT split_part(ver, '.', 1), split_part(ver, '.', 2) "
|
||||||
|
"FROM pg_version");
|
||||||
|
|
||||||
if (PQresultStatus(res) != PGRES_TUPLES_OK)
|
if (PQresultStatus(res) != PGRES_TUPLES_OK)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "PQexec failed: %s", PQerrorMessage(conn));
|
fprintf(stderr, "PQexec failed: %s", PQerrorMessage(conn));
|
||||||
@@ -78,11 +85,13 @@ pg_version(PGconn *conn)
|
|||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
major_version1 = atoi(PQgetvalue(res, 0, 0));
|
major_version1 = atoi(PQgetvalue(res, 0, 0));
|
||||||
major_version2 = PQgetvalue(res, 0, 1);
|
major_version2 = PQgetvalue(res, 0, 1);
|
||||||
PQclear(res);
|
PQclear(res);
|
||||||
|
|
||||||
major_version = malloc(10);
|
major_version = malloc(10);
|
||||||
|
|
||||||
if (major_version1 >= 9)
|
if (major_version1 >= 9)
|
||||||
{
|
{
|
||||||
/* form a major version string */
|
/* form a major version string */
|
||||||
@@ -96,7 +105,8 @@ pg_version(PGconn *conn)
|
|||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
guc_setted(PGconn *conn, const char *parameter, const char *op, const char *value)
|
guc_setted(PGconn *conn, const char *parameter, const char *op,
|
||||||
|
const char *value)
|
||||||
{
|
{
|
||||||
PGresult *res;
|
PGresult *res;
|
||||||
char sqlquery[8192];
|
char sqlquery[8192];
|
||||||
@@ -131,7 +141,8 @@ get_cluster_size(PGconn *conn)
|
|||||||
const char *size;
|
const char *size;
|
||||||
char sqlquery[8192];
|
char sqlquery[8192];
|
||||||
|
|
||||||
sprintf(sqlquery, "SELECT pg_size_pretty(SUM(pg_database_size(oid))::bigint) "
|
sprintf(sqlquery,
|
||||||
|
"SELECT pg_size_pretty(SUM(pg_database_size(oid))::bigint) "
|
||||||
" FROM pg_database ");
|
" FROM pg_database ");
|
||||||
|
|
||||||
res = PQexec(conn, sqlquery);
|
res = PQexec(conn, sqlquery);
|
||||||
@@ -152,7 +163,8 @@ get_cluster_size(PGconn *conn)
|
|||||||
* to each node (one at a time) and finding if it is a master or a standby
|
* to each node (one at a time) and finding if it is a master or a standby
|
||||||
*/
|
*/
|
||||||
PGconn *
|
PGconn *
|
||||||
getMasterConnection(PGconn *standby_conn, int id, char *cluster, int *master_id)
|
getMasterConnection(PGconn *standby_conn, int id, char *cluster,
|
||||||
|
int *master_id)
|
||||||
{
|
{
|
||||||
PGconn *master_conn = NULL;
|
PGconn *master_conn = NULL;
|
||||||
PGresult *res1;
|
PGresult *res1;
|
||||||
@@ -169,7 +181,8 @@ getMasterConnection(PGconn *standby_conn, int id, char *cluster, int *master_id)
|
|||||||
res1 = PQexec(standby_conn, sqlquery);
|
res1 = PQexec(standby_conn, sqlquery);
|
||||||
if (PQresultStatus(res1) != PGRES_TUPLES_OK)
|
if (PQresultStatus(res1) != PGRES_TUPLES_OK)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Can't get nodes info: %s\n", PQerrorMessage(standby_conn));
|
fprintf(stderr, "Can't get nodes info: %s\n",
|
||||||
|
PQerrorMessage(standby_conn));
|
||||||
PQclear(res1);
|
PQclear(res1);
|
||||||
PQfinish(standby_conn);
|
PQfinish(standby_conn);
|
||||||
exit(1);
|
exit(1);
|
||||||
@@ -181,18 +194,21 @@ getMasterConnection(PGconn *standby_conn, int id, char *cluster, int *master_id)
|
|||||||
*master_id = atoi(PQgetvalue(res1, i, 0));
|
*master_id = atoi(PQgetvalue(res1, i, 0));
|
||||||
strcpy(master_conninfo, PQgetvalue(res1, i, 2));
|
strcpy(master_conninfo, PQgetvalue(res1, i, 2));
|
||||||
master_conn = establishDBConnection(master_conninfo, false);
|
master_conn = establishDBConnection(master_conninfo, false);
|
||||||
|
|
||||||
if (PQstatus(master_conn) != CONNECTION_OK)
|
if (PQstatus(master_conn) != CONNECTION_OK)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* I can't use the is_standby() function here because on error that
|
* I can't use the is_standby() function here because on error that
|
||||||
* function closes the connection i pass and exit, but i still need to close
|
* function closes the connection i pass and exit, but i still need to
|
||||||
* standby_conn
|
* close standby_conn
|
||||||
*/
|
*/
|
||||||
res2 = PQexec(master_conn, "SELECT pg_is_in_recovery()");
|
res2 = PQexec(master_conn, "SELECT pg_is_in_recovery()");
|
||||||
|
|
||||||
if (PQresultStatus(res2) != PGRES_TUPLES_OK)
|
if (PQresultStatus(res2) != PGRES_TUPLES_OK)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Can't get recovery state from this node: %s\n", PQerrorMessage(master_conn));
|
fprintf(stderr, "Can't get recovery state from this node: %s\n",
|
||||||
|
PQerrorMessage(master_conn));
|
||||||
PQclear(res2);
|
PQclear(res2);
|
||||||
PQfinish(master_conn);
|
PQfinish(master_conn);
|
||||||
continue;
|
continue;
|
||||||
@@ -217,7 +233,8 @@ getMasterConnection(PGconn *standby_conn, int id, char *cluster, int *master_id)
|
|||||||
/* If we finish this loop without finding a master then
|
/* If we finish this loop without finding a master then
|
||||||
* we doesn't have the info or the master has failed (or we
|
* we doesn't have the info or the master has failed (or we
|
||||||
* reached max_connections or superuser_reserved_connections,
|
* reached max_connections or superuser_reserved_connections,
|
||||||
* anything else i'm missing?),
|
* anything else I'm missing?).
|
||||||
|
*
|
||||||
* Probably we will need to check the error to know if we need
|
* Probably we will need to check the error to know if we need
|
||||||
* to start failover procedure or just fix some situation on the
|
* to start failover procedure or just fix some situation on the
|
||||||
* standby.
|
* standby.
|
||||||
@@ -225,4 +242,3 @@ getMasterConnection(PGconn *standby_conn, int id, char *cluster, int *master_id)
|
|||||||
PQclear(res1);
|
PQclear(res1);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,8 @@
|
|||||||
PGconn *establishDBConnection(const char *conninfo, const bool exit_on_error);
|
PGconn *establishDBConnection(const char *conninfo, const bool exit_on_error);
|
||||||
bool is_standby(PGconn *conn);
|
bool is_standby(PGconn *conn);
|
||||||
char *pg_version(PGconn *conn);
|
char *pg_version(PGconn *conn);
|
||||||
bool guc_setted(PGconn *conn, const char *parameter, const char *op, const char *value);
|
bool guc_setted(PGconn *conn, const char *parameter, const char *op,
|
||||||
|
const char *value);
|
||||||
const char *get_cluster_size(PGconn *conn);
|
const char *get_cluster_size(PGconn *conn);
|
||||||
PGconn * getMasterConnection(PGconn *standby_conn, int id, char *cluster, int *master_id);
|
PGconn * getMasterConnection(PGconn *standby_conn, int id, char *cluster,
|
||||||
|
int *master_id);
|
||||||
|
|||||||
214
repmgr.c
214
repmgr.c
@@ -34,7 +34,8 @@
|
|||||||
|
|
||||||
static void help(const char *progname);
|
static void help(const char *progname);
|
||||||
static bool create_recovery_file(const char *data_dir);
|
static bool create_recovery_file(const char *data_dir);
|
||||||
static int copy_remote_files(char *host, char *remote_user, char *remote_path, char *local_path, bool is_directory);
|
static int copy_remote_files(char *host, char *remote_user, char *remote_path,
|
||||||
|
char *local_path, bool is_directory);
|
||||||
static bool check_parameters_for_action(const int action);
|
static bool check_parameters_for_action(const int action);
|
||||||
|
|
||||||
static void do_master_register(void);
|
static void do_master_register(void);
|
||||||
@@ -103,7 +104,8 @@ main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
while ((c = getopt_long(argc, argv, "d:h:p:U:D:f:R:w:F:v", long_options, &optindex)) != -1)
|
while ((c = getopt_long(argc, argv, "d:h:p:U:D:f:R:w:F:v", long_options,
|
||||||
|
&optindex)) != -1)
|
||||||
{
|
{
|
||||||
switch (c)
|
switch (c)
|
||||||
{
|
{
|
||||||
@@ -138,7 +140,8 @@ main(int argc, char **argv)
|
|||||||
verbose = true;
|
verbose = true;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
|
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
|
||||||
|
progname);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -154,9 +157,11 @@ 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 && strcasecmp(server_mode, "MASTER") != 0)
|
if (strcasecmp(server_mode, "STANDBY") != 0 &&
|
||||||
|
strcasecmp(server_mode, "MASTER") != 0)
|
||||||
{
|
{
|
||||||
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
|
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
|
||||||
|
progname);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -185,7 +190,8 @@ main(int argc, char **argv)
|
|||||||
action = STANDBY_FOLLOW;
|
action = STANDBY_FOLLOW;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
|
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
|
||||||
|
progname);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -211,7 +217,8 @@ main(int argc, char **argv)
|
|||||||
default:
|
default:
|
||||||
fprintf(stderr, _("%s: too many command-line arguments (first is \"%s\")\n"),
|
fprintf(stderr, _("%s: too many command-line arguments (first is \"%s\")\n"),
|
||||||
progname, argv[optind + 1]);
|
progname, argv[optind + 1]);
|
||||||
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
|
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
|
||||||
|
progname);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -267,7 +274,8 @@ main(int argc, char **argv)
|
|||||||
do_standby_follow();
|
do_standby_follow();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
|
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
|
||||||
|
progname);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -307,7 +315,8 @@ do_master_register(void)
|
|||||||
if (strcmp(master_version, "") == 0)
|
if (strcmp(master_version, "") == 0)
|
||||||
{
|
{
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
fprintf(stderr, _("%s needs master to be PostgreSQL 9.0 or better\n"), progname);
|
fprintf(stderr, _("%s needs master to be PostgreSQL 9.0 or better\n"),
|
||||||
|
progname);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -320,11 +329,13 @@ do_master_register(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Check if there is a schema for this cluster */
|
/* Check if there is a schema for this cluster */
|
||||||
sprintf(sqlquery, "SELECT 1 FROM pg_namespace WHERE nspname = 'repmgr_%s'", myClusterName);
|
sprintf(sqlquery, "SELECT 1 FROM pg_namespace WHERE nspname = 'repmgr_%s'",
|
||||||
|
myClusterName);
|
||||||
res = PQexec(conn, sqlquery);
|
res = PQexec(conn, sqlquery);
|
||||||
if (PQresultStatus(res) != PGRES_TUPLES_OK)
|
if (PQresultStatus(res) != PGRES_TUPLES_OK)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Can't get info about schemas: %s\n", PQerrorMessage(conn));
|
fprintf(stderr, "Can't get info about schemas: %s\n",
|
||||||
|
PQerrorMessage(conn));
|
||||||
PQclear(res);
|
PQclear(res);
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
return;
|
return;
|
||||||
@@ -362,7 +373,8 @@ do_master_register(void)
|
|||||||
" conninfo text not null)", myClusterName);
|
" conninfo text not null)", myClusterName);
|
||||||
if (!PQexec(conn, sqlquery))
|
if (!PQexec(conn, sqlquery))
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Cannot create the table repmgr_%s.repl_nodes: %s\n",
|
fprintf(stderr,
|
||||||
|
"Cannot create the table repmgr_%s.repl_nodes: %s\n",
|
||||||
myClusterName, PQerrorMessage(conn));
|
myClusterName, PQerrorMessage(conn));
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
return;
|
return;
|
||||||
@@ -375,10 +387,12 @@ do_master_register(void)
|
|||||||
" last_wal_primary_location TEXT NOT NULL, "
|
" last_wal_primary_location TEXT NOT NULL, "
|
||||||
" last_wal_standby_location TEXT NOT NULL, "
|
" last_wal_standby_location TEXT NOT NULL, "
|
||||||
" replication_lag BIGINT NOT NULL, "
|
" replication_lag BIGINT NOT NULL, "
|
||||||
" apply_lag BIGINT NOT NULL) ", myClusterName);
|
" apply_lag BIGINT NOT NULL) ",
|
||||||
|
myClusterName);
|
||||||
if (!PQexec(conn, sqlquery))
|
if (!PQexec(conn, sqlquery))
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Cannot create the table repmgr_%s.repl_monitor: %s\n",
|
fprintf(stderr,
|
||||||
|
"Cannot create the table repmgr_%s.repl_monitor: %s\n",
|
||||||
myClusterName, PQerrorMessage(conn));
|
myClusterName, PQerrorMessage(conn));
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
return;
|
return;
|
||||||
@@ -396,7 +410,8 @@ do_master_register(void)
|
|||||||
" WHERE row_number = 1", myClusterName, myClusterName);
|
" WHERE row_number = 1", myClusterName, myClusterName);
|
||||||
if (!PQexec(conn, sqlquery))
|
if (!PQexec(conn, sqlquery))
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Cannot create the view repmgr_%s.repl_status: %s\n",
|
fprintf(stderr,
|
||||||
|
"Cannot create the view repmgr_%s.repl_status: %s\n",
|
||||||
myClusterName, PQerrorMessage(conn));
|
myClusterName, PQerrorMessage(conn));
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
return;
|
return;
|
||||||
@@ -485,7 +500,8 @@ do_standby_register(void)
|
|||||||
if (strcmp(standby_version, "") == 0)
|
if (strcmp(standby_version, "") == 0)
|
||||||
{
|
{
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
fprintf(stderr, _("%s needs standby to be PostgreSQL 9.0 or better\n"), progname);
|
fprintf(stderr, _("%s needs standby to be PostgreSQL 9.0 or better\n"),
|
||||||
|
progname);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -498,11 +514,13 @@ do_standby_register(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Check if there is a schema for this cluster */
|
/* Check if there is a schema for this cluster */
|
||||||
sprintf(sqlquery, "SELECT 1 FROM pg_namespace WHERE nspname = 'repmgr_%s'", myClusterName);
|
sprintf(sqlquery, "SELECT 1 FROM pg_namespace WHERE nspname = 'repmgr_%s'",
|
||||||
|
myClusterName);
|
||||||
res = PQexec(conn, sqlquery);
|
res = PQexec(conn, sqlquery);
|
||||||
if (PQresultStatus(res) != PGRES_TUPLES_OK)
|
if (PQresultStatus(res) != PGRES_TUPLES_OK)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Can't get info about tablespaces: %s\n", PQerrorMessage(conn));
|
fprintf(stderr, "Can't get info about tablespaces: %s\n",
|
||||||
|
PQerrorMessage(conn));
|
||||||
PQclear(res);
|
PQclear(res);
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
return;
|
return;
|
||||||
@@ -518,7 +536,8 @@ do_standby_register(void)
|
|||||||
PQclear(res);
|
PQclear(res);
|
||||||
|
|
||||||
/* check if there is a master in this cluster */
|
/* check if there is a master in this cluster */
|
||||||
master_conn = getMasterConnection(conn, myLocalId, myClusterName, &master_id);
|
master_conn = getMasterConnection(conn, myLocalId, myClusterName,
|
||||||
|
&master_id);
|
||||||
if (!master_conn)
|
if (!master_conn)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -528,7 +547,8 @@ do_standby_register(void)
|
|||||||
{
|
{
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
PQfinish(master_conn);
|
PQfinish(master_conn);
|
||||||
fprintf(stderr, _("%s needs master to be PostgreSQL 9.0 or better\n"), progname);
|
fprintf(stderr, _("%s needs master to be PostgreSQL 9.0 or better\n"),
|
||||||
|
progname);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -687,7 +707,8 @@ do_standby_clone(void)
|
|||||||
if (strcmp(master_version, "") == 0)
|
if (strcmp(master_version, "") == 0)
|
||||||
{
|
{
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
fprintf(stderr, _("%s needs master to be PostgreSQL 9.0 or better\n"), progname);
|
fprintf(stderr, _("%s needs master to be PostgreSQL 9.0 or better\n"),
|
||||||
|
progname);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -748,7 +769,8 @@ do_standby_clone(void)
|
|||||||
|
|
||||||
if (!create_directory(tblspc_dir))
|
if (!create_directory(tblspc_dir))
|
||||||
{
|
{
|
||||||
fprintf(stderr, _("%s: couldn't create directory \"%s\"... "),
|
fprintf(stderr,
|
||||||
|
_("%s: couldn't create directory \"%s\"... "),
|
||||||
progname, tblspc_dir);
|
progname, tblspc_dir);
|
||||||
PQclear(res);
|
PQclear(res);
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
@@ -775,7 +797,8 @@ do_standby_clone(void)
|
|||||||
/* Present and not empty */
|
/* Present and not empty */
|
||||||
if (!force)
|
if (!force)
|
||||||
{
|
{
|
||||||
fprintf(stderr,
|
fprintf(
|
||||||
|
stderr,
|
||||||
_("%s: directory \"%s\" exists but is not empty\n"),
|
_("%s: directory \"%s\" exists but is not empty\n"),
|
||||||
progname, tblspc_dir);
|
progname, tblspc_dir);
|
||||||
PQclear(res);
|
PQclear(res);
|
||||||
@@ -784,7 +807,8 @@ do_standby_clone(void)
|
|||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
/* Trouble accessing directory */
|
/* Trouble accessing directory */
|
||||||
fprintf(stderr, _("%s: could not access directory \"%s\": %s\n"),
|
fprintf(stderr,
|
||||||
|
_("%s: could not access directory \"%s\": %s\n"),
|
||||||
progname, tblspc_dir, strerror(errno));
|
progname, tblspc_dir, strerror(errno));
|
||||||
PQclear(res);
|
PQclear(res);
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
@@ -840,18 +864,20 @@ do_standby_clone(void)
|
|||||||
/*
|
/*
|
||||||
* 1) first move global/pg_control
|
* 1) first move global/pg_control
|
||||||
*
|
*
|
||||||
* 2) then move data_directory ommiting the files we have already moved and pg_xlog
|
* 2) then move data_directory ommiting the files we have already moved and
|
||||||
* content
|
* pg_xlog content
|
||||||
*
|
*
|
||||||
* 3) finally We need to backup configuration files (that could be on other directories, debian
|
* 3) finally We need to backup configuration files (that could be on other
|
||||||
* like systems likes to do that), so look at config_file, hba_file and ident_file but we
|
* directories, debian like systems likes to do that), so look at
|
||||||
* can omit external_pid_file ;)
|
* config_file, hba_file and ident_file but we can omit
|
||||||
|
* external_pid_file ;)
|
||||||
*
|
*
|
||||||
* On error we need to return but before that execute pg_stop_backup()
|
* On error we need to return but before that execute pg_stop_backup()
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* need to create the global sub directory */
|
/* need to create the global sub directory */
|
||||||
sprintf(master_control_file, "%s/global/pg_control", master_data_directory);
|
sprintf(master_control_file, "%s/global/pg_control",
|
||||||
|
master_data_directory);
|
||||||
sprintf(local_control_file, "%s/global", dest_dir);
|
sprintf(local_control_file, "%s/global", dest_dir);
|
||||||
if (!create_directory(local_control_file))
|
if (!create_directory(local_control_file))
|
||||||
{
|
{
|
||||||
@@ -860,34 +886,40 @@ do_standby_clone(void)
|
|||||||
goto stop_backup;
|
goto stop_backup;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = copy_remote_files(host, remote_user, master_control_file, local_control_file, false);
|
r = copy_remote_files(host, remote_user, master_control_file,
|
||||||
|
local_control_file, false);
|
||||||
if (r != 0)
|
if (r != 0)
|
||||||
goto stop_backup;
|
goto stop_backup;
|
||||||
|
|
||||||
r = copy_remote_files(host, remote_user, master_data_directory, dest_dir, true);
|
r = copy_remote_files(host, remote_user, master_data_directory, dest_dir,
|
||||||
|
true);
|
||||||
if (r != 0)
|
if (r != 0)
|
||||||
goto stop_backup;
|
goto stop_backup;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copy tablespace locations, i'm doing this separately because i couldn't find and appropiate
|
* Copy tablespace locations, i'm doing this separately because i couldn't
|
||||||
* rsync option but besides we could someday make all these rsync happen concurrently
|
* find and appropiate rsync option but besides we could someday make all
|
||||||
|
* these rsync happen concurrently
|
||||||
*/
|
*/
|
||||||
sprintf(sqlquery, "select spclocation from pg_tablespace where spcname not in ('pg_default', 'pg_global')");
|
sprintf(sqlquery, "select spclocation from pg_tablespace where spcname not in ('pg_default', 'pg_global')");
|
||||||
res = PQexec(conn, sqlquery);
|
res = PQexec(conn, sqlquery);
|
||||||
if (PQresultStatus(res) != PGRES_TUPLES_OK)
|
if (PQresultStatus(res) != PGRES_TUPLES_OK)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Can't get info about tablespaces: %s\n", PQerrorMessage(conn));
|
fprintf(stderr, "Can't get info about tablespaces: %s\n",
|
||||||
|
PQerrorMessage(conn));
|
||||||
PQclear(res);
|
PQclear(res);
|
||||||
goto stop_backup;
|
goto stop_backup;
|
||||||
}
|
}
|
||||||
for (i = 0; i < PQntuples(res); i++)
|
for (i = 0; i < PQntuples(res); i++)
|
||||||
{
|
{
|
||||||
r = copy_remote_files(host, remote_user, PQgetvalue(res, i, 0), PQgetvalue(res, i, 0), true);
|
r = copy_remote_files(host, remote_user, PQgetvalue(res, i, 0),
|
||||||
|
PQgetvalue(res, i, 0), true);
|
||||||
if (r != 0)
|
if (r != 0)
|
||||||
goto stop_backup;
|
goto stop_backup;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = copy_remote_files(host, remote_user, master_config_file, dest_dir, false);
|
r = copy_remote_files(host, remote_user, master_config_file, dest_dir,
|
||||||
|
false);
|
||||||
if (r != 0)
|
if (r != 0)
|
||||||
goto stop_backup;
|
goto stop_backup;
|
||||||
|
|
||||||
@@ -895,7 +927,8 @@ do_standby_clone(void)
|
|||||||
if (r != 0)
|
if (r != 0)
|
||||||
goto stop_backup;
|
goto stop_backup;
|
||||||
|
|
||||||
r = copy_remote_files(host, remote_user, master_ident_file, dest_dir, false);
|
r = copy_remote_files(host, remote_user, master_ident_file, dest_dir,
|
||||||
|
false);
|
||||||
if (r != 0)
|
if (r != 0)
|
||||||
goto stop_backup;
|
goto stop_backup;
|
||||||
|
|
||||||
@@ -929,10 +962,14 @@ stop_backup:
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if (verbose)
|
if (verbose)
|
||||||
printf(_("%s requires primary to keep WAL files %s until at least %s\n"),
|
printf(
|
||||||
|
_("%s requires primary to keep WAL files %s until at least %s\n"),
|
||||||
progname, first_wal_segment, last_wal_segment);
|
progname, first_wal_segment, last_wal_segment);
|
||||||
|
|
||||||
/* we need to create the pg_xlog sub directory too, i'm reusing a variable here */
|
/*
|
||||||
|
* We need to create the pg_xlog sub directory too, I'm reusing a variable
|
||||||
|
* here.
|
||||||
|
*/
|
||||||
sprintf(local_control_file, "%s/pg_xlog", dest_dir);
|
sprintf(local_control_file, "%s/pg_xlog", dest_dir);
|
||||||
if (!create_directory(local_control_file))
|
if (!create_directory(local_control_file))
|
||||||
{
|
{
|
||||||
@@ -943,7 +980,10 @@ stop_backup:
|
|||||||
/* Finally, write the recovery.conf file */
|
/* Finally, write the recovery.conf file */
|
||||||
create_recovery_file(dest_dir);
|
create_recovery_file(dest_dir);
|
||||||
|
|
||||||
/* We don't start the service because we still may want to move the directory */
|
/*
|
||||||
|
* We don't start the service because we still may want to move the
|
||||||
|
* directory
|
||||||
|
*/
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -989,19 +1029,22 @@ do_standby_promote(void)
|
|||||||
if (strcmp(standby_version, "") == 0)
|
if (strcmp(standby_version, "") == 0)
|
||||||
{
|
{
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
fprintf(stderr, _("%s needs standby to be PostgreSQL 9.0 or better\n"), progname);
|
fprintf(stderr, _("%s needs standby to be PostgreSQL 9.0 or better\n"),
|
||||||
|
progname);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check we are in a standby node */
|
/* Check we are in a standby node */
|
||||||
if (!is_standby(conn))
|
if (!is_standby(conn))
|
||||||
{
|
{
|
||||||
fprintf(stderr, "repmgr: The command should be executed in a standby node\n");
|
fprintf(stderr,
|
||||||
|
"repmgr: The command should be executed in a standby node\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* we also need to check if there isn't any master already */
|
/* we also need to check if there isn't any master already */
|
||||||
old_master_conn = getMasterConnection(conn, myLocalId, myClusterName, &old_master_id);
|
old_master_conn = getMasterConnection(conn, myLocalId, myClusterName,
|
||||||
|
&old_master_id);
|
||||||
if (old_master_conn != NULL)
|
if (old_master_conn != NULL)
|
||||||
{
|
{
|
||||||
PQfinish(old_master_conn);
|
PQfinish(old_master_conn);
|
||||||
@@ -1018,7 +1061,8 @@ do_standby_promote(void)
|
|||||||
res = PQexec(conn, sqlquery);
|
res = PQexec(conn, sqlquery);
|
||||||
if (PQresultStatus(res) != PGRES_TUPLES_OK)
|
if (PQresultStatus(res) != PGRES_TUPLES_OK)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Can't get info about data directory: %s\n", PQerrorMessage(conn));
|
fprintf(stderr, "Can't get info about data directory: %s\n",
|
||||||
|
PQerrorMessage(conn));
|
||||||
PQclear(res);
|
PQclear(res);
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
return;
|
return;
|
||||||
@@ -1041,9 +1085,11 @@ do_standby_promote(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* reconnect to check we got promoted */
|
/* reconnect to check we got promoted */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* XXX i'm removing this because it gives an annoying message saying couldn't connect
|
* XXX i'm removing this because it gives an annoying message saying
|
||||||
* but is just the server starting up
|
* couldn't connect but is just the server starting up
|
||||||
|
*
|
||||||
* conn = establishDBConnection(conninfo, true);
|
* conn = establishDBConnection(conninfo, true);
|
||||||
* if (is_standby(conn))
|
* if (is_standby(conn))
|
||||||
* fprintf(stderr, "\n%s: STANDBY PROMOTE failed, this is still a standby node.\n", progname);
|
* fprintf(stderr, "\n%s: STANDBY PROMOTE failed, this is still a standby node.\n", progname);
|
||||||
@@ -1077,9 +1123,7 @@ do_standby_follow(void)
|
|||||||
const char *master_version = NULL;
|
const char *master_version = NULL;
|
||||||
const char *standby_version = NULL;
|
const char *standby_version = NULL;
|
||||||
|
|
||||||
/*
|
/* Read the configuration file: repmgr.conf */
|
||||||
* Read the configuration file: repmgr.conf
|
|
||||||
*/
|
|
||||||
parse_config(config_file, myClusterName, &myLocalId, conninfo);
|
parse_config(config_file, myClusterName, &myLocalId, conninfo);
|
||||||
if (myLocalId == -1)
|
if (myLocalId == -1)
|
||||||
{
|
{
|
||||||
@@ -1108,7 +1152,8 @@ do_standby_follow(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* we also need to check if there is any master in the cluster */
|
/* we also need to check if there is any master in the cluster */
|
||||||
master_conn = getMasterConnection(conn, myLocalId, myClusterName, &master_id);
|
master_conn = getMasterConnection(conn, myLocalId, myClusterName,
|
||||||
|
&master_id);
|
||||||
if (master_conn == NULL)
|
if (master_conn == NULL)
|
||||||
{
|
{
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
@@ -1120,7 +1165,8 @@ do_standby_follow(void)
|
|||||||
if (is_standby(master_conn))
|
if (is_standby(master_conn))
|
||||||
{
|
{
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
fprintf(stderr, "%s: The node to follow should be a master\n", progname);
|
fprintf(stderr, "%s: The node to follow should be a master\n",
|
||||||
|
progname);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1130,7 +1176,8 @@ do_standby_follow(void)
|
|||||||
{
|
{
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
PQfinish(master_conn);
|
PQfinish(master_conn);
|
||||||
fprintf(stderr, _("%s needs master to be PostgreSQL 9.0 or better\n"), progname);
|
fprintf(stderr, _("%s needs master to be PostgreSQL 9.0 or better\n"),
|
||||||
|
progname);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1164,7 +1211,8 @@ do_standby_follow(void)
|
|||||||
res = PQexec(conn, sqlquery);
|
res = PQexec(conn, sqlquery);
|
||||||
if (PQresultStatus(res) != PGRES_TUPLES_OK)
|
if (PQresultStatus(res) != PGRES_TUPLES_OK)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Can't get info about data directory: %s\n", PQerrorMessage(conn));
|
fprintf(stderr, "Can't get info about data directory: %s\n",
|
||||||
|
PQerrorMessage(conn));
|
||||||
PQclear(res);
|
PQclear(res);
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
return;
|
return;
|
||||||
@@ -1197,7 +1245,8 @@ help(const char *progname)
|
|||||||
printf(_("\n%s: Replicator manager \n"), progname);
|
printf(_("\n%s: Replicator manager \n"), progname);
|
||||||
printf(_("Usage:\n"));
|
printf(_("Usage:\n"));
|
||||||
printf(_(" %s [OPTIONS] master {register}\n"), progname);
|
printf(_(" %s [OPTIONS] master {register}\n"), progname);
|
||||||
printf(_(" %s [OPTIONS] standby {register|clone|promote|follow}\n"), progname);
|
printf(_(" %s [OPTIONS] standby {register|clone|promote|follow}\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"));
|
||||||
@@ -1250,7 +1299,8 @@ create_recovery_file(const char *data_dir)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
sprintf(line, "primary_conninfo = 'host=%s port=%s'\n", host, ((masterport==NULL) ? "5432" : masterport));
|
sprintf(line, "primary_conninfo = 'host=%s port=%s'\n", host,
|
||||||
|
((masterport==NULL) ? "5432" : masterport));
|
||||||
if (fputs(line, recovery_file) == EOF)
|
if (fputs(line, recovery_file) == EOF)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "recovery file could not be written, it could be necesary to create it manually\n");
|
fprintf(stderr, "recovery file could not be written, it could be necesary to create it manually\n");
|
||||||
@@ -1266,7 +1316,8 @@ create_recovery_file(const char *data_dir)
|
|||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
copy_remote_files(char *host, char *remote_user, char *remote_path, char *local_path, bool is_directory)
|
copy_remote_files(char *host, char *remote_user, char *remote_path,
|
||||||
|
char *local_path, bool is_directory)
|
||||||
{
|
{
|
||||||
char script[QUERY_STR_LEN];
|
char script[QUERY_STR_LEN];
|
||||||
char options[QUERY_STR_LEN];
|
char options[QUERY_STR_LEN];
|
||||||
@@ -1288,7 +1339,8 @@ copy_remote_files(char *host, char *remote_user, char *remote_path, char *local_
|
|||||||
|
|
||||||
if (is_directory)
|
if (is_directory)
|
||||||
{
|
{
|
||||||
strcat(options, " --exclude=pg_xlog* --exclude=pg_control --exclude=*.pid");
|
strcat(options,
|
||||||
|
" --exclude=pg_xlog* --exclude=pg_control --exclude=*.pid");
|
||||||
sprintf(script, "rsync %s %s:%s/* %s",
|
sprintf(script, "rsync %s %s:%s/* %s",
|
||||||
options, host_string, remote_path, local_path);
|
options, host_string, remote_path, local_path);
|
||||||
}
|
}
|
||||||
@@ -1304,7 +1356,8 @@ copy_remote_files(char *host, char *remote_user, char *remote_path, char *local_
|
|||||||
r = system(script);
|
r = system(script);
|
||||||
|
|
||||||
if (r != 0)
|
if (r != 0)
|
||||||
fprintf(stderr, _("Can't rsync from remote file or directory (%s:%s)\n"),
|
fprintf(stderr,
|
||||||
|
_("Can't rsync from remote file or directory (%s:%s)\n"),
|
||||||
host_string, remote_path);
|
host_string, remote_path);
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
@@ -1327,16 +1380,18 @@ check_parameters_for_action(const int action)
|
|||||||
* all other parameters are at least useless and could be
|
* all other parameters are at least useless and could be
|
||||||
* confusing so reject them
|
* confusing so reject them
|
||||||
*/
|
*/
|
||||||
if ((host != NULL) || (masterport != NULL) || (username != NULL) ||
|
if ((host != NULL) || (masterport != NULL) ||
|
||||||
(dbname != NULL))
|
(username != NULL) || (dbname != NULL))
|
||||||
{
|
{
|
||||||
fprintf(stderr, "\nYou can't use connection parameters to the master when issuing a MASTER REGISTER command.");
|
fprintf(stderr, "\nYou can't use connection parameters to the master when issuing a MASTER REGISTER command.");
|
||||||
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
|
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
|
||||||
|
progname);
|
||||||
ok = false;
|
ok = false;
|
||||||
}
|
}
|
||||||
if (dest_dir != NULL) {
|
if (dest_dir != NULL) {
|
||||||
fprintf(stderr, "\nYou don't need a destination directory for MASTER REGISTER command");
|
fprintf(stderr, "\nYou don't need a destination directory for MASTER REGISTER command");
|
||||||
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
|
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
|
||||||
|
progname);
|
||||||
ok = false;
|
ok = false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -1346,16 +1401,18 @@ check_parameters_for_action(const int action)
|
|||||||
* we don't need connection parameters to the master
|
* we don't need connection parameters to the master
|
||||||
* because we can detect the master in repl_nodes
|
* because we can detect the master in repl_nodes
|
||||||
*/
|
*/
|
||||||
if ((host != NULL) || (masterport != NULL) || (username != NULL) ||
|
if ((host != NULL) || (masterport != NULL) ||
|
||||||
(dbname != NULL))
|
(username != NULL) || (dbname != NULL))
|
||||||
{
|
{
|
||||||
fprintf(stderr, "\nYou can't use connection parameters to the master when issuing a STANDBY REGISTER command.");
|
fprintf(stderr, "\nYou can't use connection parameters to the master when issuing a STANDBY REGISTER command.");
|
||||||
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
|
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
|
||||||
|
progname);
|
||||||
ok = false;
|
ok = false;
|
||||||
}
|
}
|
||||||
if (dest_dir != NULL) {
|
if (dest_dir != NULL) {
|
||||||
fprintf(stderr, "\nYou don't need a destination directory for STANDBY REGISTER command");
|
fprintf(stderr, "\nYou don't need a destination directory for STANDBY REGISTER command");
|
||||||
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
|
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
|
||||||
|
progname);
|
||||||
ok = false;
|
ok = false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -1366,16 +1423,18 @@ check_parameters_for_action(const int action)
|
|||||||
* because we will try to detect the master in repl_nodes
|
* because we will try to detect the master in repl_nodes
|
||||||
* if we can't find it then the promote action will be cancelled
|
* if we can't find it then the promote action will be cancelled
|
||||||
*/
|
*/
|
||||||
if ((host != NULL) || (masterport != NULL) || (username != NULL) ||
|
if ((host != NULL) || (masterport != NULL) ||
|
||||||
(dbname != NULL))
|
(username != NULL) || (dbname != NULL))
|
||||||
{
|
{
|
||||||
fprintf(stderr, "\nYou can't use connection parameters to the master when issuing a STANDBY PROMOTE command.");
|
fprintf(stderr, "\nYou can't use connection parameters to the master when issuing a STANDBY PROMOTE command.");
|
||||||
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
|
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
|
||||||
|
progname);
|
||||||
ok = false;
|
ok = false;
|
||||||
}
|
}
|
||||||
if (dest_dir != NULL) {
|
if (dest_dir != NULL) {
|
||||||
fprintf(stderr, "\nYou don't need a destination directory for STANDBY PROMOTE command");
|
fprintf(stderr, "\nYou don't need a destination directory for STANDBY PROMOTE command");
|
||||||
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
|
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
|
||||||
|
progname);
|
||||||
ok = false;
|
ok = false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -1386,16 +1445,18 @@ check_parameters_for_action(const int action)
|
|||||||
* because we will try to detect the master in repl_nodes
|
* because we will try to detect the master in repl_nodes
|
||||||
* if we can't find it then the follow action will be cancelled
|
* if we can't find it then the follow action will be cancelled
|
||||||
*/
|
*/
|
||||||
if ((host != NULL) || (masterport != NULL) || (username != NULL) ||
|
if ((host != NULL) || (masterport != NULL) ||
|
||||||
(dbname != NULL))
|
(username != NULL) || (dbname != NULL))
|
||||||
{
|
{
|
||||||
fprintf(stderr, "\nYou can't use connection parameters to the master when issuing a STANDBY FOLLOW command.");
|
fprintf(stderr, "\nYou can't use connection parameters to the master when issuing a STANDBY FOLLOW command.");
|
||||||
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
|
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
|
||||||
|
progname);
|
||||||
ok = false;
|
ok = false;
|
||||||
}
|
}
|
||||||
if (dest_dir != NULL) {
|
if (dest_dir != NULL) {
|
||||||
fprintf(stderr, "\nYou don't need a destination directory for STANDBY FOLLOW command");
|
fprintf(stderr, "\nYou don't need a destination directory for STANDBY FOLLOW command");
|
||||||
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
|
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
|
||||||
|
progname);
|
||||||
ok = false;
|
ok = false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -1407,7 +1468,8 @@ check_parameters_for_action(const int action)
|
|||||||
*/
|
*/
|
||||||
if (config_file != NULL) {
|
if (config_file != NULL) {
|
||||||
fprintf(stderr, "\nYou need to use connection parameters to the master when issuing a STANDBY CLONE command.");
|
fprintf(stderr, "\nYou need to use connection parameters to the master when issuing a STANDBY CLONE command.");
|
||||||
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
|
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
|
||||||
|
progname);
|
||||||
ok = false;
|
ok = false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|||||||
29
repmgrd.c
29
repmgrd.c
@@ -111,7 +111,8 @@ main(int argc, char **argv)
|
|||||||
verbose = true;
|
verbose = true;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
|
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
|
||||||
|
progname);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -142,7 +143,8 @@ main(int argc, char **argv)
|
|||||||
if (strcmp(standby_version, "") == 0)
|
if (strcmp(standby_version, "") == 0)
|
||||||
{
|
{
|
||||||
PQfinish(myLocalConn);
|
PQfinish(myLocalConn);
|
||||||
fprintf(stderr, _("%s needs standby to be PostgreSQL 9.0 or better\n"), progname);
|
fprintf(stderr, _("%s needs standby to be PostgreSQL 9.0 or better\n"),
|
||||||
|
progname);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,7 +162,8 @@ main(int argc, char **argv)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* I need the id of the primary as well as a connection to it */
|
/* I need the id of the primary as well as a connection to it */
|
||||||
primaryConn = getMasterConnection(myLocalConn, myLocalId, myClusterName, &primaryId);
|
primaryConn = getMasterConnection(myLocalConn, myLocalId,
|
||||||
|
myClusterName, &primaryId);
|
||||||
if (primaryConn == NULL)
|
if (primaryConn == NULL)
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
@@ -221,11 +224,14 @@ MonitorExecute(void)
|
|||||||
}
|
}
|
||||||
if (PQstatus(primaryConn) != CONNECTION_OK)
|
if (PQstatus(primaryConn) != CONNECTION_OK)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "\n%s: We couldn't reconnect to master, checking if ", progname);
|
fprintf(stderr, "\n%s: We couldn't reconnect to master, checking if ",
|
||||||
|
progname);
|
||||||
fprintf(stderr, "%s: another node has been promoted.\n", progname);
|
fprintf(stderr, "%s: another node has been promoted.\n", progname);
|
||||||
for (connection_retries = 0; connection_retries < 6; connection_retries++)
|
for (connection_retries = 0; connection_retries < 6;
|
||||||
|
connection_retries++)
|
||||||
{
|
{
|
||||||
primaryConn = getMasterConnection(myLocalConn, myLocalId, myClusterName, &primaryId);
|
primaryConn = getMasterConnection(myLocalConn, myLocalId,
|
||||||
|
myClusterName, &primaryId);
|
||||||
if (PQstatus(primaryConn) == CONNECTION_OK)
|
if (PQstatus(primaryConn) == CONNECTION_OK)
|
||||||
{
|
{
|
||||||
/* Connected, we can continue the process so break the loop */
|
/* Connected, we can continue the process so break the loop */
|
||||||
@@ -344,8 +350,10 @@ checkClusterConfiguration(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If there isn't any results then we have not configured a primary node yet
|
* If there isn't any results then we have not configured a primary node
|
||||||
* in repmgr or the connection string is pointing to the wrong database.
|
* yet in repmgr or the connection string is pointing to the wrong
|
||||||
|
* database.
|
||||||
|
*
|
||||||
* XXX if we are the primary, should we try to create the tables needed?
|
* XXX if we are the primary, should we try to create the tables needed?
|
||||||
*/
|
*/
|
||||||
if (PQntuples(res) == 0)
|
if (PQntuples(res) == 0)
|
||||||
@@ -365,9 +373,7 @@ checkNodeConfiguration(char *conninfo)
|
|||||||
{
|
{
|
||||||
PGresult *res;
|
PGresult *res;
|
||||||
|
|
||||||
/*
|
/* Check if we have my node information in repl_nodes */
|
||||||
* Check if we have my node information in repl_nodes
|
|
||||||
*/
|
|
||||||
sprintf(sqlquery, "SELECT * FROM repmgr_%s.repl_nodes "
|
sprintf(sqlquery, "SELECT * FROM repmgr_%s.repl_nodes "
|
||||||
" WHERE id = %d AND cluster = '%s' ",
|
" WHERE id = %d AND cluster = '%s' ",
|
||||||
myClusterName, myLocalId, myClusterName);
|
myClusterName, myLocalId, myClusterName);
|
||||||
@@ -389,6 +395,7 @@ checkNodeConfiguration(char *conninfo)
|
|||||||
if (PQntuples(res) == 0)
|
if (PQntuples(res) == 0)
|
||||||
{
|
{
|
||||||
PQclear(res);
|
PQclear(res);
|
||||||
|
|
||||||
/* Adding the node */
|
/* Adding the node */
|
||||||
sprintf(sqlquery, "INSERT INTO repmgr_%s.repl_nodes "
|
sprintf(sqlquery, "INSERT INTO repmgr_%s.repl_nodes "
|
||||||
"VALUES (%d, '%s', '%s')",
|
"VALUES (%d, '%s', '%s')",
|
||||||
|
|||||||
Reference in New Issue
Block a user