mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-26 16:46:28 +00:00
astyle run against Heroku code
This commit is contained in:
7
config.c
7
config.c
@@ -30,17 +30,18 @@ parse_config(const char *config_file, repmgr_config *config)
|
|||||||
|
|
||||||
FILE *fp = fopen (config_file, "r");
|
FILE *fp = fopen (config_file, "r");
|
||||||
|
|
||||||
if (fp == NULL) {
|
if (fp == NULL)
|
||||||
|
{
|
||||||
fprintf(stderr, _("Could not find configuration file '%s'\n"), config_file);
|
fprintf(stderr, _("Could not find configuration file '%s'\n"), config_file);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Initialize */
|
/* Initialize */
|
||||||
memset(config->cluster_name, 0, sizeof(config->cluster_name));
|
memset(config->cluster_name, 0, sizeof(config->cluster_name));
|
||||||
config->node = -1;
|
config->node = -1;
|
||||||
memset(config->conninfo, 0, sizeof(config->conninfo));
|
memset(config->conninfo, 0, sizeof(config->conninfo));
|
||||||
memset(config->rsync_options, 0, sizeof(config->rsync_options));
|
memset(config->rsync_options, 0, sizeof(config->rsync_options));
|
||||||
|
|
||||||
/* Read next line */
|
/* Read next line */
|
||||||
while ((s = fgets (buff, sizeof buff, fp)) != NULL)
|
while ((s = fgets (buff, sizeof buff, fp)) != NULL)
|
||||||
{
|
{
|
||||||
|
|||||||
36
dbutils.c
36
dbutils.c
@@ -31,7 +31,7 @@ establishDBConnection(const char *conninfo, const bool exit_on_error)
|
|||||||
if ((PQstatus(conn) != CONNECTION_OK))
|
if ((PQstatus(conn) != CONNECTION_OK))
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Connection to database failed: %s",
|
fprintf(stderr, "Connection to database failed: %s",
|
||||||
PQerrorMessage(conn));
|
PQerrorMessage(conn));
|
||||||
|
|
||||||
if (exit_on_error)
|
if (exit_on_error)
|
||||||
{
|
{
|
||||||
@@ -83,10 +83,10 @@ pg_version(PGconn *conn, char* major_version)
|
|||||||
char *major_version2;
|
char *major_version2;
|
||||||
|
|
||||||
res = PQexec(conn,
|
res = PQexec(conn,
|
||||||
"WITH pg_version(ver) AS "
|
"WITH pg_version(ver) AS "
|
||||||
"(SELECT split_part(version(), ' ', 2)) "
|
"(SELECT split_part(version(), ' ', 2)) "
|
||||||
"SELECT split_part(ver, '.', 1), split_part(ver, '.', 2) "
|
"SELECT split_part(ver, '.', 1), split_part(ver, '.', 2) "
|
||||||
"FROM pg_version");
|
"FROM pg_version");
|
||||||
|
|
||||||
if (PQresultStatus(res) != PGRES_TUPLES_OK)
|
if (PQresultStatus(res) != PGRES_TUPLES_OK)
|
||||||
{
|
{
|
||||||
@@ -103,7 +103,7 @@ pg_version(PGconn *conn, char* major_version)
|
|||||||
{
|
{
|
||||||
/* form a major version string */
|
/* form a major version string */
|
||||||
xsnprintf(major_version, MAXVERSIONSTR, "%d.%s", major_version1,
|
xsnprintf(major_version, MAXVERSIONSTR, "%d.%s", major_version1,
|
||||||
major_version2);
|
major_version2);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
strcpy(major_version, "");
|
strcpy(major_version, "");
|
||||||
@@ -116,14 +116,14 @@ pg_version(PGconn *conn, char* major_version)
|
|||||||
|
|
||||||
bool
|
bool
|
||||||
guc_setted(PGconn *conn, const char *parameter, const char *op,
|
guc_setted(PGconn *conn, const char *parameter, const char *op,
|
||||||
const char *value)
|
const char *value)
|
||||||
{
|
{
|
||||||
PGresult *res;
|
PGresult *res;
|
||||||
char sqlquery[QUERY_STR_LEN];
|
char sqlquery[QUERY_STR_LEN];
|
||||||
|
|
||||||
sqlquery_snprintf(sqlquery, "SELECT true FROM pg_settings "
|
sqlquery_snprintf(sqlquery, "SELECT true FROM pg_settings "
|
||||||
" WHERE name = '%s' AND setting %s '%s'",
|
" WHERE name = '%s' AND setting %s '%s'",
|
||||||
parameter, op, value);
|
parameter, op, value);
|
||||||
|
|
||||||
res = PQexec(conn, sqlquery);
|
res = PQexec(conn, sqlquery);
|
||||||
if (PQresultStatus(res) != PGRES_TUPLES_OK)
|
if (PQresultStatus(res) != PGRES_TUPLES_OK)
|
||||||
@@ -152,9 +152,9 @@ get_cluster_size(PGconn *conn)
|
|||||||
char sqlquery[QUERY_STR_LEN];
|
char sqlquery[QUERY_STR_LEN];
|
||||||
|
|
||||||
sqlquery_snprintf(
|
sqlquery_snprintf(
|
||||||
sqlquery,
|
sqlquery,
|
||||||
"SELECT pg_size_pretty(SUM(pg_database_size(oid))::bigint) "
|
"SELECT pg_size_pretty(SUM(pg_database_size(oid))::bigint) "
|
||||||
" FROM pg_database ");
|
" FROM pg_database ");
|
||||||
|
|
||||||
res = PQexec(conn, sqlquery);
|
res = PQexec(conn, sqlquery);
|
||||||
if (PQresultStatus(res) != PGRES_TUPLES_OK)
|
if (PQresultStatus(res) != PGRES_TUPLES_OK)
|
||||||
@@ -179,7 +179,7 @@ get_cluster_size(PGconn *conn)
|
|||||||
*/
|
*/
|
||||||
PGconn *
|
PGconn *
|
||||||
getMasterConnection(PGconn *standby_conn, int id, char *cluster,
|
getMasterConnection(PGconn *standby_conn, int id, char *cluster,
|
||||||
int *master_id, char *master_conninfo_out)
|
int *master_id, char *master_conninfo_out)
|
||||||
{
|
{
|
||||||
PGconn *master_conn = NULL;
|
PGconn *master_conn = NULL;
|
||||||
PGresult *res1;
|
PGresult *res1;
|
||||||
@@ -207,7 +207,7 @@ getMasterConnection(PGconn *standby_conn, int id, char *cluster,
|
|||||||
maxlen_snprintf(schema_str, "repmgr_%s", cluster);
|
maxlen_snprintf(schema_str, "repmgr_%s", cluster);
|
||||||
{
|
{
|
||||||
char *identifier = PQescapeIdentifier(standby_conn, schema_str,
|
char *identifier = PQescapeIdentifier(standby_conn, schema_str,
|
||||||
strlen(schema_str));
|
strlen(schema_str));
|
||||||
|
|
||||||
maxlen_snprintf(schema_quoted, "%s", identifier);
|
maxlen_snprintf(schema_quoted, "%s", identifier);
|
||||||
PQfreemem(identifier);
|
PQfreemem(identifier);
|
||||||
@@ -215,14 +215,14 @@ getMasterConnection(PGconn *standby_conn, int id, char *cluster,
|
|||||||
|
|
||||||
/* find all nodes belonging to this cluster */
|
/* find all nodes belonging to this cluster */
|
||||||
sqlquery_snprintf(sqlquery, "SELECT * FROM %s.repl_nodes "
|
sqlquery_snprintf(sqlquery, "SELECT * FROM %s.repl_nodes "
|
||||||
" WHERE cluster = '%s' and id <> %d",
|
" WHERE cluster = '%s' and id <> %d",
|
||||||
schema_quoted, cluster, id);
|
schema_quoted, cluster, 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",
|
fprintf(stderr, "Can't get nodes info: %s\n",
|
||||||
PQerrorMessage(standby_conn));
|
PQerrorMessage(standby_conn));
|
||||||
PQclear(res1);
|
PQclear(res1);
|
||||||
PQfinish(standby_conn);
|
PQfinish(standby_conn);
|
||||||
exit(1);
|
exit(1);
|
||||||
@@ -248,7 +248,7 @@ getMasterConnection(PGconn *standby_conn, int id, char *cluster,
|
|||||||
if (PQresultStatus(res2) != PGRES_TUPLES_OK)
|
if (PQresultStatus(res2) != PGRES_TUPLES_OK)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Can't get recovery state from this node: %s\n",
|
fprintf(stderr, "Can't get recovery state from this node: %s\n",
|
||||||
PQerrorMessage(master_conn));
|
PQerrorMessage(master_conn));
|
||||||
PQclear(res2);
|
PQclear(res2);
|
||||||
PQfinish(master_conn);
|
PQfinish(master_conn);
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ 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* major_version);
|
char *pg_version(PGconn *conn, char* major_version);
|
||||||
bool guc_setted(PGconn *conn, const char *parameter, const char *op,
|
bool guc_setted(PGconn *conn, const char *parameter, const char *op,
|
||||||
const char *value);
|
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,
|
PGconn *getMasterConnection(PGconn *standby_conn, int id, char *cluster,
|
||||||
int *master_id, char *master_conninfo_out);
|
int *master_id, char *master_conninfo_out);
|
||||||
|
|||||||
484
repmgr.c
484
repmgr.c
@@ -47,7 +47,7 @@
|
|||||||
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);
|
||||||
static int copy_remote_files(char *host, char *remote_user, char *remote_path,
|
static int copy_remote_files(char *host, char *remote_user, char *remote_path,
|
||||||
char *local_path, bool is_directory);
|
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);
|
||||||
@@ -119,7 +119,7 @@ main(int argc, char **argv)
|
|||||||
|
|
||||||
|
|
||||||
while ((c = getopt_long(argc, argv, "d:h:p:U:D:f:R:w:F:v", long_options,
|
while ((c = getopt_long(argc, argv, "d:h:p:U:D:f:R:w:F:v", long_options,
|
||||||
&optindex)) != -1)
|
&optindex)) != -1)
|
||||||
{
|
{
|
||||||
switch (c)
|
switch (c)
|
||||||
{
|
{
|
||||||
@@ -130,20 +130,20 @@ main(int argc, char **argv)
|
|||||||
host = optarg;
|
host = optarg;
|
||||||
break;
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
masterport = optarg;
|
masterport = optarg;
|
||||||
break;
|
break;
|
||||||
case 'U':
|
case 'U':
|
||||||
username = optarg;
|
username = optarg;
|
||||||
break;
|
break;
|
||||||
case 'D':
|
case 'D':
|
||||||
dest_dir = optarg;
|
dest_dir = optarg;
|
||||||
break;
|
break;
|
||||||
case 'f':
|
case 'f':
|
||||||
config_file = optarg;
|
config_file = optarg;
|
||||||
break;
|
break;
|
||||||
case 'R':
|
case 'R':
|
||||||
remote_user = optarg;
|
remote_user = optarg;
|
||||||
break;
|
break;
|
||||||
case 'w':
|
case 'w':
|
||||||
wal_keep_segments = optarg;
|
wal_keep_segments = optarg;
|
||||||
break;
|
break;
|
||||||
@@ -154,8 +154,8 @@ main(int argc, char **argv)
|
|||||||
verbose = true;
|
verbose = true;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
|
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
|
||||||
progname);
|
progname);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -172,10 +172,10 @@ main(int argc, char **argv)
|
|||||||
{
|
{
|
||||||
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)
|
||||||
{
|
{
|
||||||
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
|
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
|
||||||
progname);
|
progname);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -205,7 +205,7 @@ main(int argc, char **argv)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
|
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
|
||||||
progname);
|
progname);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -231,8 +231,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"),
|
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
|
||||||
progname);
|
progname);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -274,7 +274,7 @@ main(int argc, char **argv)
|
|||||||
if (config.node == -1)
|
if (config.node == -1)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Node information is missing. "
|
fprintf(stderr, "Node information is missing. "
|
||||||
"Check the configuration file.\n");
|
"Check the configuration file.\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -306,8 +306,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"),
|
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
|
||||||
progname);
|
progname);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -335,7 +335,7 @@ do_master_register(void)
|
|||||||
{
|
{
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
fprintf(stderr, _("%s needs master to be PostgreSQL 9.0 or better\n"),
|
fprintf(stderr, _("%s needs master to be PostgreSQL 9.0 or better\n"),
|
||||||
progname);
|
progname);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -351,7 +351,7 @@ do_master_register(void)
|
|||||||
maxlen_snprintf(schema_str, "repmgr_%s", config.cluster_name);
|
maxlen_snprintf(schema_str, "repmgr_%s", config.cluster_name);
|
||||||
{
|
{
|
||||||
char *identifier = PQescapeIdentifier(conn, schema_str,
|
char *identifier = PQescapeIdentifier(conn, schema_str,
|
||||||
strlen(schema_str));
|
strlen(schema_str));
|
||||||
|
|
||||||
maxlen_snprintf(schema_quoted, "%s", identifier);
|
maxlen_snprintf(schema_quoted, "%s", identifier);
|
||||||
PQfreemem(identifier);
|
PQfreemem(identifier);
|
||||||
@@ -359,13 +359,13 @@ do_master_register(void)
|
|||||||
|
|
||||||
/* Check if there is a schema for this cluster */
|
/* Check if there is a schema for this cluster */
|
||||||
sqlquery_snprintf(sqlquery,
|
sqlquery_snprintf(sqlquery,
|
||||||
"SELECT 1 FROM pg_namespace "
|
"SELECT 1 FROM pg_namespace "
|
||||||
"WHERE nspname = '%s'", schema_str);
|
"WHERE nspname = '%s'", schema_str);
|
||||||
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",
|
fprintf(stderr, "Can't get info about schemas: %s\n",
|
||||||
PQerrorMessage(conn));
|
PQerrorMessage(conn));
|
||||||
PQclear(res);
|
PQclear(res);
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
return;
|
return;
|
||||||
@@ -391,59 +391,59 @@ do_master_register(void)
|
|||||||
if (!PQexec(conn, sqlquery))
|
if (!PQexec(conn, sqlquery))
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Cannot create the schema %s: %s\n", schema_quoted,
|
fprintf(stderr, "Cannot create the schema %s: %s\n", schema_quoted,
|
||||||
PQerrorMessage(conn));
|
PQerrorMessage(conn));
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ... the tables */
|
/* ... the tables */
|
||||||
sqlquery_snprintf(sqlquery, "CREATE TABLE %s.repl_nodes ( "
|
sqlquery_snprintf(sqlquery, "CREATE TABLE %s.repl_nodes ( "
|
||||||
" id integer primary key, "
|
" id integer primary key, "
|
||||||
" cluster text not null, "
|
" cluster text not null, "
|
||||||
" conninfo text not null)", schema_quoted);
|
" conninfo text not null)", schema_quoted);
|
||||||
if (!PQexec(conn, sqlquery))
|
if (!PQexec(conn, sqlquery))
|
||||||
{
|
{
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
config.cluster_name, PQerrorMessage(conn));
|
config.cluster_name, PQerrorMessage(conn));
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
sqlquery_snprintf(sqlquery, "CREATE TABLE %s.repl_monitor ( "
|
sqlquery_snprintf(sqlquery, "CREATE TABLE %s.repl_monitor ( "
|
||||||
" primary_node INTEGER NOT NULL, "
|
" primary_node INTEGER NOT NULL, "
|
||||||
" standby_node INTEGER NOT NULL, "
|
" standby_node INTEGER NOT NULL, "
|
||||||
" last_monitor_time TIMESTAMP WITH TIME ZONE NOT NULL, "
|
" last_monitor_time TIMESTAMP WITH TIME ZONE NOT NULL, "
|
||||||
" 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) ",
|
" apply_lag BIGINT NOT NULL) ",
|
||||||
schema_quoted);
|
schema_quoted);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!PQexec(conn, sqlquery))
|
if (!PQexec(conn, sqlquery))
|
||||||
{
|
{
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
config.cluster_name, PQerrorMessage(conn));
|
config.cluster_name, PQerrorMessage(conn));
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* and the view */
|
/* and the view */
|
||||||
sqlquery_snprintf(sqlquery, "CREATE VIEW %s.repl_status AS "
|
sqlquery_snprintf(sqlquery, "CREATE VIEW %s.repl_status AS "
|
||||||
" WITH monitor_info AS (SELECT *, ROW_NUMBER() OVER (PARTITION BY primary_node, standby_node "
|
" WITH monitor_info AS (SELECT *, ROW_NUMBER() OVER (PARTITION BY primary_node, standby_node "
|
||||||
" ORDER BY last_monitor_time desc) "
|
" ORDER BY last_monitor_time desc) "
|
||||||
" FROM %s.repl_monitor) "
|
" FROM %s.repl_monitor) "
|
||||||
" SELECT primary_node, standby_node, last_monitor_time, last_wal_primary_location, "
|
" SELECT primary_node, standby_node, last_monitor_time, last_wal_primary_location, "
|
||||||
" last_wal_standby_location, pg_size_pretty(replication_lag) replication_lag, "
|
" last_wal_standby_location, pg_size_pretty(replication_lag) replication_lag, "
|
||||||
" pg_size_pretty(apply_lag) apply_lag, age(now(), last_monitor_time) AS time_lag "
|
" pg_size_pretty(apply_lag) apply_lag, age(now(), last_monitor_time) AS time_lag "
|
||||||
" FROM monitor_info a "
|
" FROM monitor_info a "
|
||||||
" WHERE row_number = 1",
|
" WHERE row_number = 1",
|
||||||
schema_quoted, schema_quoted);
|
schema_quoted, schema_quoted);
|
||||||
|
|
||||||
if (!PQexec(conn, sqlquery))
|
if (!PQexec(conn, sqlquery))
|
||||||
{
|
{
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
config.cluster_name, PQerrorMessage(conn));
|
config.cluster_name, PQerrorMessage(conn));
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -454,7 +454,7 @@ do_master_register(void)
|
|||||||
|
|
||||||
/* Ensure there isn't any other master already registered */
|
/* Ensure there isn't any other master already registered */
|
||||||
master_conn = getMasterConnection(conn, config.node,
|
master_conn = getMasterConnection(conn, config.node,
|
||||||
config.cluster_name, &id, NULL);
|
config.cluster_name, &id, NULL);
|
||||||
|
|
||||||
if (master_conn != NULL)
|
if (master_conn != NULL)
|
||||||
{
|
{
|
||||||
@@ -468,27 +468,27 @@ do_master_register(void)
|
|||||||
if (force)
|
if (force)
|
||||||
{
|
{
|
||||||
sqlquery_snprintf(sqlquery,
|
sqlquery_snprintf(sqlquery,
|
||||||
"DELETE FROM %s.repl_nodes WHERE id = %d",
|
"DELETE FROM %s.repl_nodes WHERE id = %d",
|
||||||
schema_quoted, config.node);
|
schema_quoted, config.node);
|
||||||
|
|
||||||
if (!PQexec(conn, sqlquery))
|
if (!PQexec(conn, sqlquery))
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Cannot delete node details, %s\n",
|
fprintf(stderr, "Cannot delete node details, %s\n",
|
||||||
PQerrorMessage(conn));
|
PQerrorMessage(conn));
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sqlquery_snprintf(sqlquery, "INSERT INTO %s.repl_nodes "
|
sqlquery_snprintf(sqlquery, "INSERT INTO %s.repl_nodes "
|
||||||
"VALUES (%d, '%s', '%s')",
|
"VALUES (%d, '%s', '%s')",
|
||||||
schema_quoted, config.node, config.cluster_name,
|
schema_quoted, config.node, config.cluster_name,
|
||||||
config.conninfo);
|
config.conninfo);
|
||||||
|
|
||||||
if (!PQexec(conn, sqlquery))
|
if (!PQexec(conn, sqlquery))
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Cannot insert node details, %s\n",
|
fprintf(stderr, "Cannot insert node details, %s\n",
|
||||||
PQerrorMessage(conn));
|
PQerrorMessage(conn));
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -523,7 +523,7 @@ do_standby_register(void)
|
|||||||
{
|
{
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
fprintf(stderr, _("%s needs standby to be PostgreSQL 9.0 or better\n"),
|
fprintf(stderr, _("%s needs standby to be PostgreSQL 9.0 or better\n"),
|
||||||
progname);
|
progname);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -539,7 +539,7 @@ do_standby_register(void)
|
|||||||
maxlen_snprintf(schema_str, "repmgr_%s", config.cluster_name);
|
maxlen_snprintf(schema_str, "repmgr_%s", config.cluster_name);
|
||||||
{
|
{
|
||||||
char *identifier = PQescapeIdentifier(conn, schema_str,
|
char *identifier = PQescapeIdentifier(conn, schema_str,
|
||||||
strlen(schema_str));
|
strlen(schema_str));
|
||||||
|
|
||||||
maxlen_snprintf(schema_quoted, "%s", identifier);
|
maxlen_snprintf(schema_quoted, "%s", identifier);
|
||||||
PQfreemem(identifier);
|
PQfreemem(identifier);
|
||||||
@@ -547,14 +547,14 @@ do_standby_register(void)
|
|||||||
|
|
||||||
/* Check if there is a schema for this cluster */
|
/* Check if there is a schema for this cluster */
|
||||||
sqlquery_snprintf(sqlquery,
|
sqlquery_snprintf(sqlquery,
|
||||||
"SELECT 1 FROM pg_namespace "
|
"SELECT 1 FROM pg_namespace "
|
||||||
" WHERE nspname = '%s'", schema_str);
|
" WHERE nspname = '%s'", schema_str);
|
||||||
|
|
||||||
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",
|
fprintf(stderr, "Can't get info about tablespaces: %s\n",
|
||||||
PQerrorMessage(conn));
|
PQerrorMessage(conn));
|
||||||
PQclear(res);
|
PQclear(res);
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
return;
|
return;
|
||||||
@@ -572,7 +572,7 @@ do_standby_register(void)
|
|||||||
|
|
||||||
/* check if there is a master in this cluster */
|
/* check if there is a master in this cluster */
|
||||||
master_conn = getMasterConnection(conn, config.node, config.cluster_name,
|
master_conn = getMasterConnection(conn, config.node, config.cluster_name,
|
||||||
&master_id, NULL);
|
&master_id, NULL);
|
||||||
|
|
||||||
if (!master_conn)
|
if (!master_conn)
|
||||||
return;
|
return;
|
||||||
@@ -584,7 +584,7 @@ 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"),
|
fprintf(stderr, _("%s needs master to be PostgreSQL 9.0 or better\n"),
|
||||||
progname);
|
progname);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -594,7 +594,7 @@ do_standby_register(void)
|
|||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
PQfinish(master_conn);
|
PQfinish(master_conn);
|
||||||
fprintf(stderr, _("%s needs versions of both master (%s) and standby (%s) to match.\n"),
|
fprintf(stderr, _("%s needs versions of both master (%s) and standby (%s) to match.\n"),
|
||||||
progname, master_version, standby_version);
|
progname, master_version, standby_version);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -603,14 +603,14 @@ do_standby_register(void)
|
|||||||
if (force)
|
if (force)
|
||||||
{
|
{
|
||||||
sqlquery_snprintf(sqlquery,
|
sqlquery_snprintf(sqlquery,
|
||||||
"DELETE FROM %s.repl_nodes "
|
"DELETE FROM %s.repl_nodes "
|
||||||
" WHERE id = %d",
|
" WHERE id = %d",
|
||||||
schema_quoted, config.node);
|
schema_quoted, config.node);
|
||||||
|
|
||||||
if (!PQexec(master_conn, sqlquery))
|
if (!PQexec(master_conn, sqlquery))
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Cannot delete node details, %s\n",
|
fprintf(stderr, "Cannot delete node details, %s\n",
|
||||||
PQerrorMessage(master_conn));
|
PQerrorMessage(master_conn));
|
||||||
PQfinish(master_conn);
|
PQfinish(master_conn);
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
return;
|
return;
|
||||||
@@ -618,14 +618,14 @@ do_standby_register(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
sqlquery_snprintf(sqlquery, "INSERT INTO %s.repl_nodes "
|
sqlquery_snprintf(sqlquery, "INSERT INTO %s.repl_nodes "
|
||||||
"VALUES (%d, '%s', '%s')",
|
"VALUES (%d, '%s', '%s')",
|
||||||
schema_quoted, config.node, config.cluster_name,
|
schema_quoted, config.node, config.cluster_name,
|
||||||
config.conninfo);
|
config.conninfo);
|
||||||
|
|
||||||
if (!PQexec(master_conn, sqlquery))
|
if (!PQexec(master_conn, sqlquery))
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Cannot insert node details, %s\n",
|
fprintf(stderr, "Cannot insert node details, %s\n",
|
||||||
PQerrorMessage(master_conn));
|
PQerrorMessage(master_conn));
|
||||||
PQfinish(master_conn);
|
PQfinish(master_conn);
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
return;
|
return;
|
||||||
@@ -670,46 +670,46 @@ do_standby_clone(void)
|
|||||||
/* Check this directory could be used as a PGDATA dir */
|
/* Check this directory could be used as a PGDATA dir */
|
||||||
switch (check_dir(dest_dir))
|
switch (check_dir(dest_dir))
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
/* dest_dir not there, must create it */
|
/* dest_dir not there, must create it */
|
||||||
if (verbose)
|
if (verbose)
|
||||||
printf(_("creating directory %s ... "), dest_dir);
|
printf(_("creating directory %s ... "), dest_dir);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
|
||||||
if (!create_directory(dest_dir))
|
if (!create_directory(dest_dir))
|
||||||
{
|
{
|
||||||
fprintf(stderr, _("%s: couldn't create directory %s ... "),
|
fprintf(stderr, _("%s: couldn't create directory %s ... "),
|
||||||
progname, dest_dir);
|
progname, dest_dir);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
/* Present but empty, fix permissions and use it */
|
/* Present but empty, fix permissions and use it */
|
||||||
if (verbose)
|
if (verbose)
|
||||||
printf(_("fixing permissions on existing directory %s ... "),
|
printf(_("fixing permissions on existing directory %s ... "),
|
||||||
dest_dir);
|
dest_dir);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
|
||||||
if (!set_directory_permissions(dest_dir))
|
if (!set_directory_permissions(dest_dir))
|
||||||
{
|
{
|
||||||
fprintf(stderr, _("%s: could not change permissions of directory \"%s\": %s\n"),
|
fprintf(stderr, _("%s: could not change permissions of directory \"%s\": %s\n"),
|
||||||
progname, dest_dir, strerror(errno));
|
progname, dest_dir, strerror(errno));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
/* Present and not empty */
|
/* Present and not empty */
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
_("%s: directory \"%s\" exists but is not empty\n"),
|
_("%s: directory \"%s\" exists but is not empty\n"),
|
||||||
progname, dest_dir);
|
progname, dest_dir);
|
||||||
|
|
||||||
pg_dir = is_pg_dir(dest_dir);
|
pg_dir = is_pg_dir(dest_dir);
|
||||||
if (pg_dir && !force)
|
if (pg_dir && !force)
|
||||||
{
|
{
|
||||||
fprintf(stderr, _("\nThis looks like a PostgreSQL directroy.\n"
|
fprintf(stderr, _("\nThis looks like a PostgreSQL directroy.\n"
|
||||||
"If you are sure you want to clone here, "
|
"If you are sure you want to clone here, "
|
||||||
"please check there is no PostgreSQL server "
|
"please check there is no PostgreSQL server "
|
||||||
"running and use the --force option\n"));
|
"running and use the --force option\n"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (pg_dir && force)
|
else if (pg_dir && force)
|
||||||
@@ -717,12 +717,12 @@ do_standby_clone(void)
|
|||||||
/* Let it continue */
|
/* Let it continue */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return;
|
return;
|
||||||
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, dest_dir, strerror(errno));
|
progname, dest_dir, strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Connection parameters for master only */
|
/* Connection parameters for master only */
|
||||||
@@ -736,7 +736,7 @@ do_standby_clone(void)
|
|||||||
if (!conn)
|
if (!conn)
|
||||||
{
|
{
|
||||||
fprintf(stderr, _("%s: could not connect to master\n"),
|
fprintf(stderr, _("%s: could not connect to master\n"),
|
||||||
progname);
|
progname);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -746,7 +746,7 @@ do_standby_clone(void)
|
|||||||
{
|
{
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
fprintf(stderr, _("%s needs master to be PostgreSQL 9.0 or better\n"),
|
fprintf(stderr, _("%s needs master to be PostgreSQL 9.0 or better\n"),
|
||||||
progname);
|
progname);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -785,9 +785,9 @@ do_standby_clone(void)
|
|||||||
* Check if the tablespace locations exists and that we can write to them.
|
* Check if the tablespace locations exists and that we can write to them.
|
||||||
*/
|
*/
|
||||||
sqlquery_snprintf(sqlquery,
|
sqlquery_snprintf(sqlquery,
|
||||||
"SELECT spclocation "
|
"SELECT spclocation "
|
||||||
" FROM pg_tablespace "
|
" FROM pg_tablespace "
|
||||||
"WHERE spcname NOT IN ('pg_default', 'pg_global')");
|
"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)
|
||||||
{
|
{
|
||||||
@@ -804,58 +804,58 @@ do_standby_clone(void)
|
|||||||
/* Check this directory could be used as a PGDATA dir */
|
/* Check this directory could be used as a PGDATA dir */
|
||||||
switch (check_dir(tblspc_dir))
|
switch (check_dir(tblspc_dir))
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
/* tblspc_dir not there, must create it */
|
/* tblspc_dir not there, must create it */
|
||||||
if (verbose)
|
if (verbose)
|
||||||
printf(_("creating directory \"%s\"... "), tblspc_dir);
|
printf(_("creating directory \"%s\"... "), tblspc_dir);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
|
||||||
if (!create_directory(tblspc_dir))
|
if (!create_directory(tblspc_dir))
|
||||||
{
|
{
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
_("%s: couldn't create directory \"%s\"... "),
|
_("%s: couldn't create directory \"%s\"... "),
|
||||||
progname, tblspc_dir);
|
progname, tblspc_dir);
|
||||||
PQclear(res);
|
PQclear(res);
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
/* Present but empty, fix permissions and use it */
|
/* Present but empty, fix permissions and use it */
|
||||||
if (verbose)
|
if (verbose)
|
||||||
printf(_("fixing permissions on existing directory \"%s\"... "),
|
printf(_("fixing permissions on existing directory \"%s\"... "),
|
||||||
tblspc_dir);
|
tblspc_dir);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
|
||||||
if (!set_directory_permissions(tblspc_dir))
|
if (!set_directory_permissions(tblspc_dir))
|
||||||
{
|
{
|
||||||
fprintf(stderr, _("%s: could not change permissions of directory \"%s\": %s\n"),
|
fprintf(stderr, _("%s: could not change permissions of directory \"%s\": %s\n"),
|
||||||
progname, tblspc_dir, strerror(errno));
|
progname, tblspc_dir, strerror(errno));
|
||||||
PQclear(res);
|
PQclear(res);
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
/* Present and not empty */
|
/* Present and not empty */
|
||||||
if (!force)
|
if (!force)
|
||||||
{
|
{
|
||||||
fprintf(
|
fprintf(
|
||||||
stderr,
|
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);
|
|
||||||
PQfinish(conn);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
/* Trouble accessing directory */
|
|
||||||
fprintf(stderr,
|
|
||||||
_("%s: could not access directory \"%s\": %s\n"),
|
|
||||||
progname, tblspc_dir, strerror(errno));
|
|
||||||
PQclear(res);
|
PQclear(res);
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
/* Trouble accessing directory */
|
||||||
|
fprintf(stderr,
|
||||||
|
_("%s: could not access directory \"%s\": %s\n"),
|
||||||
|
progname, tblspc_dir, strerror(errno));
|
||||||
|
PQclear(res);
|
||||||
|
PQfinish(conn);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -863,11 +863,11 @@ do_standby_clone(void)
|
|||||||
|
|
||||||
/* Get the data directory full path and the configuration files location */
|
/* Get the data directory full path and the configuration files location */
|
||||||
sqlquery_snprintf(
|
sqlquery_snprintf(
|
||||||
sqlquery,
|
sqlquery,
|
||||||
"SELECT name, setting "
|
"SELECT name, setting "
|
||||||
" FROM pg_settings "
|
" FROM pg_settings "
|
||||||
" WHERE name IN ('data_directory', 'config_file', 'hba_file', "
|
" WHERE name IN ('data_directory', 'config_file', 'hba_file', "
|
||||||
" 'ident_file')");
|
" 'ident_file')");
|
||||||
res = PQexec(conn, sqlquery);
|
res = PQexec(conn, sqlquery);
|
||||||
if (PQresultStatus(res) != PGRES_TUPLES_OK)
|
if (PQresultStatus(res) != PGRES_TUPLES_OK)
|
||||||
{
|
{
|
||||||
@@ -896,9 +896,9 @@ do_standby_clone(void)
|
|||||||
* so we can say to the user we need those files
|
* so we can say to the user we need those files
|
||||||
*/
|
*/
|
||||||
sqlquery_snprintf(
|
sqlquery_snprintf(
|
||||||
sqlquery,
|
sqlquery,
|
||||||
"SELECT pg_xlogfile_name(pg_start_backup('repmgr_standby_clone_%ld'))",
|
"SELECT pg_xlogfile_name(pg_start_backup('repmgr_standby_clone_%ld'))",
|
||||||
time(NULL));
|
time(NULL));
|
||||||
res = PQexec(conn, sqlquery);
|
res = PQexec(conn, sqlquery);
|
||||||
if (PQresultStatus(res) != PGRES_TUPLES_OK)
|
if (PQresultStatus(res) != PGRES_TUPLES_OK)
|
||||||
{
|
{
|
||||||
@@ -935,22 +935,22 @@ do_standby_clone(void)
|
|||||||
|
|
||||||
/* need to create the global sub directory */
|
/* need to create the global sub directory */
|
||||||
maxlen_snprintf(master_control_file, "%s/global/pg_control",
|
maxlen_snprintf(master_control_file, "%s/global/pg_control",
|
||||||
master_data_directory);
|
master_data_directory);
|
||||||
maxlen_snprintf(local_control_file, "%s/global", dest_dir);
|
maxlen_snprintf(local_control_file, "%s/global", dest_dir);
|
||||||
if (!create_directory(local_control_file))
|
if (!create_directory(local_control_file))
|
||||||
{
|
{
|
||||||
fprintf(stderr, _("%s: couldn't create directory %s ... "),
|
fprintf(stderr, _("%s: couldn't create directory %s ... "),
|
||||||
progname, dest_dir);
|
progname, dest_dir);
|
||||||
goto stop_backup;
|
goto stop_backup;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = copy_remote_files(host, remote_user, master_control_file,
|
r = copy_remote_files(host, remote_user, master_control_file,
|
||||||
local_control_file, false);
|
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,
|
r = copy_remote_files(host, remote_user, master_data_directory, dest_dir,
|
||||||
true);
|
true);
|
||||||
if (r != 0)
|
if (r != 0)
|
||||||
goto stop_backup;
|
goto stop_backup;
|
||||||
|
|
||||||
@@ -960,27 +960,27 @@ do_standby_clone(void)
|
|||||||
* these rsync happen concurrently
|
* these rsync happen concurrently
|
||||||
*/
|
*/
|
||||||
sqlquery_snprintf(sqlquery,
|
sqlquery_snprintf(sqlquery,
|
||||||
"SELECT spclocation "
|
"SELECT spclocation "
|
||||||
" FROM pg_tablespace "
|
" FROM pg_tablespace "
|
||||||
" WHERE spcname NOT IN ('pg_default', 'pg_global')");
|
" 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",
|
fprintf(stderr, "Can't get info about tablespaces: %s\n",
|
||||||
PQerrorMessage(conn));
|
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),
|
r = copy_remote_files(host, remote_user, PQgetvalue(res, i, 0),
|
||||||
PQgetvalue(res, i, 0), true);
|
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,
|
r = copy_remote_files(host, remote_user, master_config_file, dest_dir,
|
||||||
false);
|
false);
|
||||||
if (r != 0)
|
if (r != 0)
|
||||||
goto stop_backup;
|
goto stop_backup;
|
||||||
|
|
||||||
@@ -989,7 +989,7 @@ do_standby_clone(void)
|
|||||||
goto stop_backup;
|
goto stop_backup;
|
||||||
|
|
||||||
r = copy_remote_files(host, remote_user, master_ident_file, dest_dir,
|
r = copy_remote_files(host, remote_user, master_ident_file, dest_dir,
|
||||||
false);
|
false);
|
||||||
if (r != 0)
|
if (r != 0)
|
||||||
goto stop_backup;
|
goto stop_backup;
|
||||||
|
|
||||||
@@ -999,7 +999,7 @@ stop_backup:
|
|||||||
if (!conn)
|
if (!conn)
|
||||||
{
|
{
|
||||||
fprintf(stderr, _("%s: could not connect to master\n"),
|
fprintf(stderr, _("%s: could not connect to master\n"),
|
||||||
progname);
|
progname);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1019,8 +1019,8 @@ stop_backup:
|
|||||||
if (verbose)
|
if (verbose)
|
||||||
{
|
{
|
||||||
printf(
|
printf(
|
||||||
_("%s requires primary to keep WAL files %s until at least %s\n"),
|
_("%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);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Only free the first_wal_segment since it was copied out of the
|
* Only free the first_wal_segment since it was copied out of the
|
||||||
@@ -1045,7 +1045,7 @@ stop_backup:
|
|||||||
if (!create_directory(local_control_file))
|
if (!create_directory(local_control_file))
|
||||||
{
|
{
|
||||||
fprintf(stderr, _("%s: couldn't create directory %s, you will need to do it manually...\n"),
|
fprintf(stderr, _("%s: couldn't create directory %s, you will need to do it manually...\n"),
|
||||||
progname, dest_dir);
|
progname, dest_dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Finally, write the recovery.conf file */
|
/* Finally, write the recovery.conf file */
|
||||||
@@ -1086,7 +1086,7 @@ do_standby_promote(void)
|
|||||||
{
|
{
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
fprintf(stderr, _("%s needs standby to be PostgreSQL 9.0 or better\n"),
|
fprintf(stderr, _("%s needs standby to be PostgreSQL 9.0 or better\n"),
|
||||||
progname);
|
progname);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1094,13 +1094,13 @@ do_standby_promote(void)
|
|||||||
if (!is_standby(conn))
|
if (!is_standby(conn))
|
||||||
{
|
{
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"repmgr: The command should be executed in a standby node\n");
|
"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, config.node, config.cluster_name,
|
old_master_conn = getMasterConnection(conn, config.node, config.cluster_name,
|
||||||
&old_master_id, NULL);
|
&old_master_id, NULL);
|
||||||
|
|
||||||
if (old_master_conn != NULL)
|
if (old_master_conn != NULL)
|
||||||
{
|
{
|
||||||
@@ -1114,12 +1114,12 @@ do_standby_promote(void)
|
|||||||
|
|
||||||
/* Get the data directory full path and the last subdirectory */
|
/* Get the data directory full path and the last subdirectory */
|
||||||
sqlquery_snprintf(sqlquery, "SELECT setting "
|
sqlquery_snprintf(sqlquery, "SELECT setting "
|
||||||
" FROM pg_settings WHERE name = 'data_directory'");
|
" FROM pg_settings WHERE name = 'data_directory'");
|
||||||
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",
|
fprintf(stderr, "Can't get info about data directory: %s\n",
|
||||||
PQerrorMessage(conn));
|
PQerrorMessage(conn));
|
||||||
PQclear(res);
|
PQclear(res);
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
return;
|
return;
|
||||||
@@ -1197,7 +1197,7 @@ 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, config.node, config.cluster_name,
|
master_conn = getMasterConnection(conn, config.node, config.cluster_name,
|
||||||
&master_id, (char *) &master_conninfo);
|
&master_id, (char *) &master_conninfo);
|
||||||
|
|
||||||
if (master_conn == NULL)
|
if (master_conn == NULL)
|
||||||
{
|
{
|
||||||
@@ -1211,7 +1211,7 @@ do_standby_follow(void)
|
|||||||
{
|
{
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
fprintf(stderr, "%s: The node to follow should be a master\n",
|
fprintf(stderr, "%s: The node to follow should be a master\n",
|
||||||
progname);
|
progname);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1222,7 +1222,7 @@ 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"),
|
fprintf(stderr, _("%s needs master to be PostgreSQL 9.0 or better\n"),
|
||||||
progname);
|
progname);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1232,7 +1232,7 @@ do_standby_follow(void)
|
|||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
PQfinish(master_conn);
|
PQfinish(master_conn);
|
||||||
fprintf(stderr, _("%s needs versions of both master (%s) and standby (%s) to match.\n"),
|
fprintf(stderr, _("%s needs versions of both master (%s) and standby (%s) to match.\n"),
|
||||||
progname, master_version, standby_version);
|
progname, master_version, standby_version);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1263,12 +1263,12 @@ do_standby_follow(void)
|
|||||||
|
|
||||||
/* Get the data directory full path */
|
/* Get the data directory full path */
|
||||||
sqlquery_snprintf(sqlquery, "SELECT setting "
|
sqlquery_snprintf(sqlquery, "SELECT setting "
|
||||||
" FROM pg_settings WHERE name = 'data_directory'");
|
" FROM pg_settings WHERE name = 'data_directory'");
|
||||||
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",
|
fprintf(stderr, "Can't get info about data directory: %s\n",
|
||||||
PQerrorMessage(conn));
|
PQerrorMessage(conn));
|
||||||
PQclear(res);
|
PQclear(res);
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
return;
|
return;
|
||||||
@@ -1302,7 +1302,7 @@ help(const char *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"),
|
printf(_(" %s [OPTIONS] standby {register|clone|promote|follow}\n"),
|
||||||
progname);
|
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"));
|
||||||
@@ -1375,15 +1375,15 @@ create_recovery_file(const char *data_dir, char *master_conninfo)
|
|||||||
if (password == NULL)
|
if (password == NULL)
|
||||||
{
|
{
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
_("%s: Panic! PGPASSWORD not set, how can we get here?\n"),
|
_("%s: Panic! PGPASSWORD not set, how can we get here?\n"),
|
||||||
progname);
|
progname);
|
||||||
exit(255);
|
exit(255);
|
||||||
}
|
}
|
||||||
|
|
||||||
maxlen_snprintf(line,
|
maxlen_snprintf(line,
|
||||||
"primary_conninfo = 'host=%s port=%s password=%s'\n",
|
"primary_conninfo = 'host=%s port=%s password=%s'\n",
|
||||||
host, ((masterport==NULL) ? "5432" : masterport),
|
host, ((masterport==NULL) ? "5432" : masterport),
|
||||||
password);
|
password);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
maxlen_snprintf(line, "primary_conninfo = '%s'\n", master_conninfo);
|
maxlen_snprintf(line, "primary_conninfo = '%s'\n", master_conninfo);
|
||||||
@@ -1404,7 +1404,7 @@ create_recovery_file(const char *data_dir, char *master_conninfo)
|
|||||||
|
|
||||||
static int
|
static int
|
||||||
copy_remote_files(char *host, char *remote_user, char *remote_path,
|
copy_remote_files(char *host, char *remote_user, char *remote_path,
|
||||||
char *local_path, bool is_directory)
|
char *local_path, bool is_directory)
|
||||||
{
|
{
|
||||||
char script[MAXLEN];
|
char script[MAXLEN];
|
||||||
char options[MAXLEN];
|
char options[MAXLEN];
|
||||||
@@ -1413,8 +1413,8 @@ copy_remote_files(char *host, char *remote_user, char *remote_path,
|
|||||||
|
|
||||||
if (strnlen(config.rsync_options, MAXLEN) == 0)
|
if (strnlen(config.rsync_options, MAXLEN) == 0)
|
||||||
maxlen_snprintf(
|
maxlen_snprintf(
|
||||||
options, "%s",
|
options, "%s",
|
||||||
"--archive --checksum --compress --progress --rsh=ssh");
|
"--archive --checksum --compress --progress --rsh=ssh");
|
||||||
else
|
else
|
||||||
maxlen_snprintf(options, "%s", config.rsync_options);
|
maxlen_snprintf(options, "%s", config.rsync_options);
|
||||||
|
|
||||||
@@ -1433,14 +1433,14 @@ copy_remote_files(char *host, char *remote_user, char *remote_path,
|
|||||||
if (is_directory)
|
if (is_directory)
|
||||||
{
|
{
|
||||||
strcat(options,
|
strcat(options,
|
||||||
" --exclude=pg_xlog* --exclude=pg_control --exclude=*.pid");
|
" --exclude=pg_xlog* --exclude=pg_control --exclude=*.pid");
|
||||||
maxlen_snprintf(script, "rsync %s %s:%s/* %s",
|
maxlen_snprintf(script, "rsync %s %s:%s/* %s",
|
||||||
options, host_string, remote_path, local_path);
|
options, host_string, remote_path, local_path);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
maxlen_snprintf(script, "rsync %s %s:%s %s/.",
|
maxlen_snprintf(script, "rsync %s %s:%s %s/.",
|
||||||
options, host_string, remote_path, local_path);
|
options, host_string, remote_path, local_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (verbose)
|
if (verbose)
|
||||||
@@ -1450,8 +1450,8 @@ copy_remote_files(char *host, char *remote_user, char *remote_path,
|
|||||||
|
|
||||||
if (r != 0)
|
if (r != 0)
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
_("Can't rsync from remote file or directory (%s:%s)\n"),
|
_("Can't rsync from remote file or directory (%s:%s)\n"),
|
||||||
host_string, remote_path);
|
host_string, remote_path);
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
@@ -1473,19 +1473,19 @@ 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) ||
|
if ((host != NULL) || (masterport != NULL) ||
|
||||||
(username != 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"),
|
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
|
||||||
progname);
|
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"),
|
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
|
||||||
progname);
|
progname);
|
||||||
ok = false;
|
ok = false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -1495,19 +1495,19 @@ 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) ||
|
if ((host != NULL) || (masterport != NULL) ||
|
||||||
(username != 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"),
|
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
|
||||||
progname);
|
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"),
|
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
|
||||||
progname);
|
progname);
|
||||||
ok = false;
|
ok = false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -1518,19 +1518,19 @@ 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) ||
|
if ((host != NULL) || (masterport != NULL) ||
|
||||||
(username != 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"),
|
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
|
||||||
progname);
|
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"),
|
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
|
||||||
progname);
|
progname);
|
||||||
ok = false;
|
ok = false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -1541,46 +1541,46 @@ 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) ||
|
if ((host != NULL) || (masterport != NULL) ||
|
||||||
(username != 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"),
|
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
|
||||||
progname);
|
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"),
|
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
|
||||||
progname);
|
progname);
|
||||||
ok = false;
|
ok = false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case STANDBY_CLONE:
|
case STANDBY_CLONE:
|
||||||
/*
|
/*
|
||||||
* Issue a friendly notice that the configuration file is not
|
* Issue a friendly notice that the configuration file is not
|
||||||
* necessary nor read at all in when performing a STANDBY CLONE
|
* necessary nor read at all in when performing a STANDBY CLONE
|
||||||
* action.
|
* action.
|
||||||
*/
|
*/
|
||||||
if (config_file != NULL)
|
if (config_file != NULL)
|
||||||
fprintf(stderr, "NOTICE: The passed configuration file is not "
|
fprintf(stderr, "NOTICE: The passed configuration file is not "
|
||||||
"required nor used when performing the STANDBY CLONE "
|
"required nor used when performing the STANDBY CLONE "
|
||||||
"command.\n");
|
"command.\n");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* To clone a master into a standby we need connection parameters
|
* To clone a master into a standby we need connection parameters
|
||||||
* repmgr.conf is useless because we don't have a server running in
|
* repmgr.conf is useless because we don't have a server running in
|
||||||
* the standby; warn the user, but keep going.
|
* the standby; warn the user, but keep going.
|
||||||
*/
|
*/
|
||||||
if (host == NULL)
|
if (host == NULL)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "\nYou need to use connection parameters to "
|
fprintf(stderr, "\nYou need to use connection parameters to "
|
||||||
"the master when issuing a STANDBY CLONE command.");
|
"the master when issuing a STANDBY CLONE command.");
|
||||||
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
|
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
|
||||||
progname);
|
progname);
|
||||||
ok = false;
|
ok = false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
60
repmgrd.c
60
repmgrd.c
@@ -125,8 +125,8 @@ main(int argc, char **argv)
|
|||||||
verbose = true;
|
verbose = true;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
|
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
|
||||||
progname);
|
progname);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -148,7 +148,7 @@ main(int argc, char **argv)
|
|||||||
if (config.node == -1)
|
if (config.node == -1)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Node information is missing. "
|
fprintf(stderr, "Node information is missing. "
|
||||||
"Check the configuration file.\n");
|
"Check the configuration file.\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,7 +160,7 @@ main(int argc, char **argv)
|
|||||||
{
|
{
|
||||||
PQfinish(myLocalConn);
|
PQfinish(myLocalConn);
|
||||||
fprintf(stderr, _("%s needs standby to be PostgreSQL 9.0 or better\n"),
|
fprintf(stderr, _("%s needs standby to be PostgreSQL 9.0 or better\n"),
|
||||||
progname);
|
progname);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -179,8 +179,8 @@ main(int argc, char **argv)
|
|||||||
{
|
{
|
||||||
/* 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, config.node,
|
primaryConn = getMasterConnection(myLocalConn, config.node,
|
||||||
config.cluster_name, &primaryId,
|
config.cluster_name, &primaryId,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
if (primaryConn == NULL)
|
if (primaryConn == NULL)
|
||||||
exit(1);
|
exit(1);
|
||||||
@@ -247,13 +247,13 @@ MonitorExecute(void)
|
|||||||
if (PQstatus(primaryConn) != CONNECTION_OK)
|
if (PQstatus(primaryConn) != CONNECTION_OK)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "\n%s: We couldn't reconnect to master, checking if ",
|
fprintf(stderr, "\n%s: We couldn't reconnect to master, checking if ",
|
||||||
progname);
|
progname);
|
||||||
for (connection_retries = 0; connection_retries < 6;
|
for (connection_retries = 0; connection_retries < 6;
|
||||||
connection_retries++)
|
connection_retries++)
|
||||||
{
|
{
|
||||||
primaryConn = getMasterConnection(myLocalConn, config.node,
|
primaryConn = getMasterConnection(myLocalConn, config.node,
|
||||||
config.cluster_name, &primaryId,
|
config.cluster_name, &primaryId,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
if (PQstatus(primaryConn) == CONNECTION_OK)
|
if (PQstatus(primaryConn) == CONNECTION_OK)
|
||||||
{
|
{
|
||||||
@@ -294,9 +294,9 @@ MonitorExecute(void)
|
|||||||
|
|
||||||
/* Get local xlog info */
|
/* Get local xlog info */
|
||||||
sqlquery_snprintf(
|
sqlquery_snprintf(
|
||||||
sqlquery,
|
sqlquery,
|
||||||
"SELECT CURRENT_TIMESTAMP, pg_last_xlog_receive_location(), "
|
"SELECT CURRENT_TIMESTAMP, pg_last_xlog_receive_location(), "
|
||||||
"pg_last_xlog_replay_location()");
|
"pg_last_xlog_replay_location()");
|
||||||
|
|
||||||
res = PQexec(myLocalConn, sqlquery);
|
res = PQexec(myLocalConn, sqlquery);
|
||||||
if (PQresultStatus(res) != PGRES_TUPLES_OK)
|
if (PQresultStatus(res) != PGRES_TUPLES_OK)
|
||||||
@@ -335,15 +335,15 @@ MonitorExecute(void)
|
|||||||
* Build the SQL to execute on primary
|
* Build the SQL to execute on primary
|
||||||
*/
|
*/
|
||||||
sqlquery_snprintf(sqlquery,
|
sqlquery_snprintf(sqlquery,
|
||||||
"INSERT INTO repmgr_%s.repl_monitor "
|
"INSERT INTO repmgr_%s.repl_monitor "
|
||||||
"VALUES(%d, %d, '%s'::timestamp with time zone, "
|
"VALUES(%d, %d, '%s'::timestamp with time zone, "
|
||||||
" '%s', '%s', "
|
" '%s', '%s', "
|
||||||
" %lld, %lld)", config.cluster_name,
|
" %lld, %lld)", config.cluster_name,
|
||||||
primaryId, config.node, monitor_standby_timestamp,
|
primaryId, config.node, monitor_standby_timestamp,
|
||||||
last_wal_primary_location,
|
last_wal_primary_location,
|
||||||
last_wal_standby_received,
|
last_wal_standby_received,
|
||||||
(lsn_primary - lsn_standby_received),
|
(lsn_primary - lsn_standby_received),
|
||||||
(lsn_standby_received - lsn_standby_applied));
|
(lsn_standby_received - lsn_standby_applied));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Execute the query asynchronously, but don't check for a result. We
|
* Execute the query asynchronously, but don't check for a result. We
|
||||||
@@ -351,7 +351,7 @@ MonitorExecute(void)
|
|||||||
*/
|
*/
|
||||||
if (PQsendQuery(primaryConn, sqlquery) == 0)
|
if (PQsendQuery(primaryConn, sqlquery) == 0)
|
||||||
fprintf(stderr, "Query could not be sent to primary. %s\n",
|
fprintf(stderr, "Query could not be sent to primary. %s\n",
|
||||||
PQerrorMessage(primaryConn));
|
PQerrorMessage(primaryConn));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -361,8 +361,8 @@ checkClusterConfiguration(void)
|
|||||||
PGresult *res;
|
PGresult *res;
|
||||||
|
|
||||||
sqlquery_snprintf(sqlquery, "SELECT oid FROM pg_class "
|
sqlquery_snprintf(sqlquery, "SELECT oid FROM pg_class "
|
||||||
" WHERE oid = 'repmgr_%s.repl_nodes'::regclass",
|
" WHERE oid = 'repmgr_%s.repl_nodes'::regclass",
|
||||||
config.cluster_name);
|
config.cluster_name);
|
||||||
res = PQexec(myLocalConn, sqlquery);
|
res = PQexec(myLocalConn, sqlquery);
|
||||||
if (PQresultStatus(res) != PGRES_TUPLES_OK)
|
if (PQresultStatus(res) != PGRES_TUPLES_OK)
|
||||||
{
|
{
|
||||||
@@ -399,8 +399,8 @@ checkNodeConfiguration(char *conninfo)
|
|||||||
|
|
||||||
/* Check if we have my node information in repl_nodes */
|
/* Check if we have my node information in repl_nodes */
|
||||||
sqlquery_snprintf(sqlquery, "SELECT * FROM repmgr_%s.repl_nodes "
|
sqlquery_snprintf(sqlquery, "SELECT * FROM repmgr_%s.repl_nodes "
|
||||||
" WHERE id = %d AND cluster = '%s' ",
|
" WHERE id = %d AND cluster = '%s' ",
|
||||||
config.cluster_name, config.node, config.cluster_name);
|
config.cluster_name, config.node, config.cluster_name);
|
||||||
|
|
||||||
res = PQexec(myLocalConn, sqlquery);
|
res = PQexec(myLocalConn, sqlquery);
|
||||||
if (PQresultStatus(res) != PGRES_TUPLES_OK)
|
if (PQresultStatus(res) != PGRES_TUPLES_OK)
|
||||||
@@ -422,13 +422,13 @@ checkNodeConfiguration(char *conninfo)
|
|||||||
|
|
||||||
/* Adding the node */
|
/* Adding the node */
|
||||||
sqlquery_snprintf(sqlquery, "INSERT INTO repmgr_%s.repl_nodes "
|
sqlquery_snprintf(sqlquery, "INSERT INTO repmgr_%s.repl_nodes "
|
||||||
"VALUES (%d, '%s', '%s')",
|
"VALUES (%d, '%s', '%s')",
|
||||||
config.cluster_name, config.node, config.cluster_name, conninfo);
|
config.cluster_name, config.node, config.cluster_name, conninfo);
|
||||||
|
|
||||||
if (!PQexec(primaryConn, sqlquery))
|
if (!PQexec(primaryConn, sqlquery))
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Cannot insert node details, %s\n",
|
fprintf(stderr, "Cannot insert node details, %s\n",
|
||||||
PQerrorMessage(primaryConn));
|
PQerrorMessage(primaryConn));
|
||||||
PQfinish(myLocalConn);
|
PQfinish(myLocalConn);
|
||||||
PQfinish(primaryConn);
|
PQfinish(primaryConn);
|
||||||
exit(1);
|
exit(1);
|
||||||
|
|||||||
Reference in New Issue
Block a user