mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-26 00:26:30 +00:00
Merge commit '78b925ea54bb7a131e97c2f5d0a63f54ca58e26f'
This commit is contained in:
1
CREDITS
1
CREDITS
@@ -8,3 +8,4 @@ Gabriele Bartolini <gabriele@2ndQuadrant.com>
|
|||||||
Bas van Oostveen <v.oostveen@gmail.com>
|
Bas van Oostveen <v.oostveen@gmail.com>
|
||||||
Hannu Krosing <hannu@2ndQuadrant.com>
|
Hannu Krosing <hannu@2ndQuadrant.com>
|
||||||
Cédric Villemain <cedric@2ndquadrant.fr>
|
Cédric Villemain <cedric@2ndquadrant.fr>
|
||||||
|
Charles Duffy <charles@dyfis.net>
|
||||||
|
|||||||
6
HISTORY
6
HISTORY
@@ -1,4 +1,4 @@
|
|||||||
1.0.0 2010-12-05 First public release
|
1.0.0 2010-12-05 First public release (Greg Smith)
|
||||||
|
|
||||||
1.0.1 2011-02-XX Fix missing "--force" option in help
|
1.0.1 2011-02-XX Fix missing "--force" option in help
|
||||||
Correct warning message for wal_keep_segments (Bas van Oostveen)
|
Correct warning message for wal_keep_segments (Bas van Oostveen)
|
||||||
@@ -13,4 +13,6 @@
|
|||||||
Avoid buffer overruns by using snprintf etc. (Gabriele)
|
Avoid buffer overruns by using snprintf etc. (Gabriele)
|
||||||
Fix use of database query after close (Gabriele)
|
Fix use of database query after close (Gabriele)
|
||||||
Add information about progress during "standby clone" (Gabriele)
|
Add information about progress during "standby clone" (Gabriele)
|
||||||
|
Fix double free error in repmgrd (Charles Duffy)
|
||||||
|
Make repmgr exit with an error code when encountering an error (Charles)
|
||||||
|
Standardize on error return codes, use in repmgrd too (Greg)
|
||||||
|
|||||||
17
README.rst
17
README.rst
@@ -539,6 +539,23 @@ and the same in the standby.
|
|||||||
The repmgr daemon creates 2 connections: one to the master and another to the
|
The repmgr daemon creates 2 connections: one to the master and another to the
|
||||||
standby.
|
standby.
|
||||||
|
|
||||||
|
Error codes
|
||||||
|
-----------
|
||||||
|
|
||||||
|
When the repmgr or repmgrd program exits, it will set one of the
|
||||||
|
following
|
||||||
|
|
||||||
|
* SUCCESS 0: Program ran successfully.
|
||||||
|
|
||||||
|
* ERR_BAD_CONFIG 1: One of the configuration checks the program makes failed.
|
||||||
|
* ERR_BAD_RSYNC 2: An rsync call made by the program returned an error.
|
||||||
|
* ERR_STOP_BACKUP 3: A ``pg_stop_backup()`` call made by the program didn't succeed.
|
||||||
|
* ERR_NO_RESTART 4: An attempt to restart a PostgreSQL instance failed.
|
||||||
|
* ERR_NEEDS_XLOG 5: Could note create the ``pg_xlog`` directory when cloning.
|
||||||
|
* ERR_DB_CON 6: Error when trying to connect to a database.
|
||||||
|
* ERR_DB_QUERY 7: Error executing a database query.
|
||||||
|
* ERR_PROMOTED 8: Exiting program because the node has been promoted to master.
|
||||||
|
|
||||||
Detailed walkthrough
|
Detailed walkthrough
|
||||||
====================
|
====================
|
||||||
|
|
||||||
|
|||||||
6
config.c
6
config.c
@@ -30,7 +30,7 @@ parse_config(const char* config_file, t_configuration_options* options)
|
|||||||
|
|
||||||
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(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Initialize */
|
/* Initialize */
|
||||||
@@ -75,14 +75,14 @@ parse_config(const char* config_file, t_configuration_options* options)
|
|||||||
{
|
{
|
||||||
fprintf(stderr, "Cluster name is missing. "
|
fprintf(stderr, "Cluster name is missing. "
|
||||||
"Check the configuration file.\n");
|
"Check the configuration file.\n");
|
||||||
exit(1);
|
exit(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
|
|
||||||
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(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
12
dbutils.c
12
dbutils.c
@@ -36,7 +36,7 @@ establishDBConnection(const char *conninfo, const bool exit_on_error)
|
|||||||
if (exit_on_error)
|
if (exit_on_error)
|
||||||
{
|
{
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
exit(1);
|
exit(ERR_DB_CON);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,7 +57,7 @@ is_standby(PGconn *conn)
|
|||||||
fprintf(stderr, "Can't query server mode: %s", PQerrorMessage(conn));
|
fprintf(stderr, "Can't query server mode: %s", PQerrorMessage(conn));
|
||||||
PQclear(res);
|
PQclear(res);
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
exit(1);
|
exit(ERR_NO_DB_CON);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strcmp(PQgetvalue(res, 0, 0), "f") == 0)
|
if (strcmp(PQgetvalue(res, 0, 0), "f") == 0)
|
||||||
@@ -89,7 +89,7 @@ pg_version(PGconn *conn, char* major_version)
|
|||||||
fprintf(stderr, "PQexec failed: %s", PQerrorMessage(conn));
|
fprintf(stderr, "PQexec failed: %s", PQerrorMessage(conn));
|
||||||
PQclear(res);
|
PQclear(res);
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
exit(1);
|
exit(ERR_DB_QUERY);
|
||||||
}
|
}
|
||||||
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);
|
||||||
@@ -123,7 +123,7 @@ guc_setted(PGconn *conn, const char *parameter, const char *op, const char *valu
|
|||||||
fprintf(stderr, "PQexec failed: %s", PQerrorMessage(conn));
|
fprintf(stderr, "PQexec failed: %s", PQerrorMessage(conn));
|
||||||
PQclear(res);
|
PQclear(res);
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
exit(1);
|
exit(ERR_DB_QUERY);
|
||||||
}
|
}
|
||||||
if (PQntuples(res) == 0)
|
if (PQntuples(res) == 0)
|
||||||
{
|
{
|
||||||
@@ -152,7 +152,7 @@ get_cluster_size(PGconn *conn)
|
|||||||
fprintf(stderr, "PQexec failed: %s", PQerrorMessage(conn));
|
fprintf(stderr, "PQexec failed: %s", PQerrorMessage(conn));
|
||||||
PQclear(res);
|
PQclear(res);
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
exit(1);
|
exit(ERR_DB_QUERY);
|
||||||
}
|
}
|
||||||
size = PQgetvalue(res, 0, 0);
|
size = PQgetvalue(res, 0, 0);
|
||||||
PQclear(res);
|
PQclear(res);
|
||||||
@@ -184,7 +184,7 @@ getMasterConnection(PGconn *standby_conn, int id, char *cluster, int *master_id)
|
|||||||
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(ERR_DB_QUERY);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < PQntuples(res1); i++)
|
for (i = 0; i < PQntuples(res1); i++)
|
||||||
|
|||||||
189
repmgr.c
189
repmgr.c
@@ -101,12 +101,12 @@ main(int argc, char **argv)
|
|||||||
if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
|
if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
|
||||||
{
|
{
|
||||||
help(progname);
|
help(progname);
|
||||||
exit(0);
|
exit(SUCCESS);
|
||||||
}
|
}
|
||||||
if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
|
if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
|
||||||
{
|
{
|
||||||
printf("%s (PostgreSQL) " PG_VERSION "\n", progname);
|
printf("%s (PostgreSQL) " PG_VERSION "\n", progname);
|
||||||
exit(0);
|
exit(SUCCESS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,7 +149,7 @@ main(int argc, char **argv)
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
usage();
|
usage();
|
||||||
exit(1);
|
exit(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,7 +167,7 @@ main(int argc, char **argv)
|
|||||||
if (strcasecmp(server_mode, "STANDBY") != 0 && strcasecmp(server_mode, "MASTER") != 0)
|
if (strcasecmp(server_mode, "STANDBY") != 0 && strcasecmp(server_mode, "MASTER") != 0)
|
||||||
{
|
{
|
||||||
usage();
|
usage();
|
||||||
exit(1);
|
exit(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -196,7 +196,7 @@ main(int argc, char **argv)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
usage();
|
usage();
|
||||||
exit(1);
|
exit(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -209,7 +209,7 @@ main(int argc, char **argv)
|
|||||||
{
|
{
|
||||||
log_err(_("Conflicting parameters you can't use -h while providing a node separately.\n"));
|
log_err(_("Conflicting parameters you can't use -h while providing a node separately.\n"));
|
||||||
usage();
|
usage();
|
||||||
exit(1);
|
exit(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
strncpy(runtime_options.host, argv[optind++], MAXLEN);
|
strncpy(runtime_options.host, argv[optind++], MAXLEN);
|
||||||
}
|
}
|
||||||
@@ -223,11 +223,11 @@ main(int argc, char **argv)
|
|||||||
log_err(_("%s: too many command-line arguments (first is \"%s\")\n"),
|
log_err(_("%s: too many command-line arguments (first is \"%s\")\n"),
|
||||||
progname, argv[optind + 1]);
|
progname, argv[optind + 1]);
|
||||||
usage();
|
usage();
|
||||||
exit(1);
|
exit(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!check_parameters_for_action(action))
|
if (!check_parameters_for_action(action))
|
||||||
exit(1);
|
exit(ERR_BAD_CONFIG);
|
||||||
|
|
||||||
if (!runtime_options.dbname[0])
|
if (!runtime_options.dbname[0])
|
||||||
{
|
{
|
||||||
@@ -247,7 +247,7 @@ main(int argc, char **argv)
|
|||||||
{
|
{
|
||||||
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(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
|
|
||||||
keywords[2] = "user";
|
keywords[2] = "user";
|
||||||
@@ -276,7 +276,7 @@ main(int argc, char **argv)
|
|||||||
{
|
{
|
||||||
log_err("Node information is missing. "
|
log_err("Node information is missing. "
|
||||||
"Check the configuration file.\n");
|
"Check the configuration file.\n");
|
||||||
exit(1);
|
exit(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -305,7 +305,7 @@ main(int argc, char **argv)
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
usage();
|
usage();
|
||||||
exit(1);
|
exit(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
logger_shutdown();
|
logger_shutdown();
|
||||||
|
|
||||||
@@ -339,7 +339,7 @@ do_master_register(void)
|
|||||||
{
|
{
|
||||||
log_err(_("%s needs master to be PostgreSQL 9.0 or better\n"), progname);
|
log_err(_("%s needs master to be PostgreSQL 9.0 or better\n"), progname);
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
return;
|
exit(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check if there is a schema for this cluster */
|
/* Check if there is a schema for this cluster */
|
||||||
@@ -351,7 +351,7 @@ do_master_register(void)
|
|||||||
log_err(_("Can't get info about schemas: %s\n"), PQerrorMessage(conn));
|
log_err(_("Can't get info about schemas: %s\n"), PQerrorMessage(conn));
|
||||||
PQclear(res);
|
PQclear(res);
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
return;
|
exit(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PQntuples(res) > 0) /* schema exists */
|
if (PQntuples(res) > 0) /* schema exists */
|
||||||
@@ -361,7 +361,7 @@ do_master_register(void)
|
|||||||
log_notice(_("Schema %s already exists.\n"), repmgr_schema);
|
log_notice(_("Schema %s already exists.\n"), repmgr_schema);
|
||||||
PQclear(res);
|
PQclear(res);
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
return;
|
exit(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
schema_exists = true;
|
schema_exists = true;
|
||||||
}
|
}
|
||||||
@@ -379,7 +379,7 @@ do_master_register(void)
|
|||||||
log_err(_("Cannot create the schema %s: %s\n"),
|
log_err(_("Cannot create the schema %s: %s\n"),
|
||||||
repmgr_schema, PQerrorMessage(conn));
|
repmgr_schema, PQerrorMessage(conn));
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
return;
|
exit(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ... the tables */
|
/* ... the tables */
|
||||||
@@ -393,7 +393,7 @@ do_master_register(void)
|
|||||||
log_err(_("Cannot create the table %s.repl_nodes: %s\n"),
|
log_err(_("Cannot create the table %s.repl_nodes: %s\n"),
|
||||||
repmgr_schema, PQerrorMessage(conn));
|
repmgr_schema, PQerrorMessage(conn));
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
return;
|
exit(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf(sqlquery, QUERY_STR_LEN, "CREATE TABLE %s.repl_monitor ( "
|
snprintf(sqlquery, QUERY_STR_LEN, "CREATE TABLE %s.repl_monitor ( "
|
||||||
@@ -410,7 +410,7 @@ do_master_register(void)
|
|||||||
log_err(_("Cannot create the table %s.repl_monitor: %s\n"),
|
log_err(_("Cannot create the table %s.repl_monitor: %s\n"),
|
||||||
repmgr_schema, PQerrorMessage(conn));
|
repmgr_schema, PQerrorMessage(conn));
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
return;
|
exit(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* and the view */
|
/* and the view */
|
||||||
@@ -429,7 +429,7 @@ do_master_register(void)
|
|||||||
log_err(_("Cannot create the view %s.repl_status: %s\n"),
|
log_err(_("Cannot create the view %s.repl_status: %s\n"),
|
||||||
repmgr_schema, PQerrorMessage(conn));
|
repmgr_schema, PQerrorMessage(conn));
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
return;
|
exit(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -443,7 +443,7 @@ do_master_register(void)
|
|||||||
{
|
{
|
||||||
PQfinish(master_conn);
|
PQfinish(master_conn);
|
||||||
log_warning(_("There is a master already in cluster %s\n"), options.cluster_name);
|
log_warning(_("There is a master already in cluster %s\n"), options.cluster_name);
|
||||||
return;
|
exit(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -460,7 +460,7 @@ do_master_register(void)
|
|||||||
log_warning(_("Cannot delete node details, %s\n"),
|
log_warning(_("Cannot delete node details, %s\n"),
|
||||||
PQerrorMessage(conn));
|
PQerrorMessage(conn));
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
return;
|
exit(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -474,7 +474,7 @@ do_master_register(void)
|
|||||||
log_warning(_("Cannot insert node details, %s\n"),
|
log_warning(_("Cannot insert node details, %s\n"),
|
||||||
PQerrorMessage(conn));
|
PQerrorMessage(conn));
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
return;
|
exit(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
|
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
@@ -505,7 +505,7 @@ do_standby_register(void)
|
|||||||
{
|
{
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
log_err(_("%s needs standby to be PostgreSQL 9.0 or better\n"), progname);
|
log_err(_("%s needs standby to be PostgreSQL 9.0 or better\n"), progname);
|
||||||
return;
|
exit(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check we are a standby */
|
/* Check we are a standby */
|
||||||
@@ -513,7 +513,7 @@ do_standby_register(void)
|
|||||||
{
|
{
|
||||||
log_err(_("repmgr: This node should be a standby (%s)\n"), options.conninfo);
|
log_err(_("repmgr: This node should be a standby (%s)\n"), options.conninfo);
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
return;
|
exit(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check if there is a schema for this cluster */
|
/* Check if there is a schema for this cluster */
|
||||||
@@ -525,23 +525,23 @@ do_standby_register(void)
|
|||||||
log_err("Can't get info about tablespaces: %s\n", PQerrorMessage(conn));
|
log_err("Can't get info about tablespaces: %s\n", PQerrorMessage(conn));
|
||||||
PQclear(res);
|
PQclear(res);
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
return;
|
exit(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PQntuples(res) == 0) /* schema doesn't exists */
|
if (PQntuples(res) == 0) /* schema doesn't exist */
|
||||||
{
|
{
|
||||||
log_err("Schema %s doesn't exists.\n", repmgr_schema);
|
log_err("Schema %s doesn't exists.\n", repmgr_schema);
|
||||||
PQclear(res);
|
PQclear(res);
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
return;
|
exit(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
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, options.node, options.cluster_name, &master_id);
|
master_conn = getMasterConnection(conn, options.node, options.cluster_name, &master_id);
|
||||||
if (!master_conn) {
|
if (!master_conn) {
|
||||||
log_err(_("Cannot retrieve information about the connection to the master\n"));
|
log_err(_("A master must be defined before configuring a slave\n"));
|
||||||
return;
|
exit(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* master should be v9 or better */
|
/* master should be v9 or better */
|
||||||
@@ -551,7 +551,7 @@ do_standby_register(void)
|
|||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
PQfinish(master_conn);
|
PQfinish(master_conn);
|
||||||
log_err(_("%s needs master to be PostgreSQL 9.0 or better\n"), progname);
|
log_err(_("%s needs master to be PostgreSQL 9.0 or better\n"), progname);
|
||||||
return;
|
exit(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* master and standby version should match */
|
/* master and standby version should match */
|
||||||
@@ -561,7 +561,7 @@ do_standby_register(void)
|
|||||||
PQfinish(master_conn);
|
PQfinish(master_conn);
|
||||||
log_err(_("%s needs versions of both master (%s) and standby (%s) to match.\n"),
|
log_err(_("%s needs versions of both master (%s) and standby (%s) to match.\n"),
|
||||||
progname, master_version, standby_version);
|
progname, master_version, standby_version);
|
||||||
return;
|
exit(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -579,7 +579,7 @@ do_standby_register(void)
|
|||||||
PQerrorMessage(master_conn));
|
PQerrorMessage(master_conn));
|
||||||
PQfinish(master_conn);
|
PQfinish(master_conn);
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
return;
|
exit(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -594,7 +594,7 @@ do_standby_register(void)
|
|||||||
PQerrorMessage(master_conn));
|
PQerrorMessage(master_conn));
|
||||||
PQfinish(master_conn);
|
PQfinish(master_conn);
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
return;
|
exit(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
|
|
||||||
PQfinish(master_conn);
|
PQfinish(master_conn);
|
||||||
@@ -645,7 +645,7 @@ do_standby_clone(void)
|
|||||||
{
|
{
|
||||||
log_err(_("%s: couldn't create directory %s ...\n"),
|
log_err(_("%s: couldn't create directory %s ...\n"),
|
||||||
progname, runtime_options.dest_dir);
|
progname, runtime_options.dest_dir);
|
||||||
return;
|
exit(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
@@ -658,7 +658,7 @@ do_standby_clone(void)
|
|||||||
{
|
{
|
||||||
log_err(_("%s: could not change permissions of directory \"%s\": %s\n"),
|
log_err(_("%s: could not change permissions of directory \"%s\": %s\n"),
|
||||||
progname, runtime_options.dest_dir, strerror(errno));
|
progname, runtime_options.dest_dir, strerror(errno));
|
||||||
return;
|
exit(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
@@ -673,7 +673,7 @@ do_standby_clone(void)
|
|||||||
"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;
|
exit(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
else if (pg_dir && runtime_options.force)
|
else if (pg_dir && runtime_options.force)
|
||||||
{
|
{
|
||||||
@@ -686,6 +686,7 @@ do_standby_clone(void)
|
|||||||
/* Trouble accessing directory */
|
/* Trouble accessing directory */
|
||||||
log_err( _("%s: could not access directory \"%s\": %s\n"),
|
log_err( _("%s: could not access directory \"%s\": %s\n"),
|
||||||
progname, runtime_options.dest_dir, strerror(errno));
|
progname, runtime_options.dest_dir, strerror(errno));
|
||||||
|
exit(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Connection parameters for master only */
|
/* Connection parameters for master only */
|
||||||
@@ -700,7 +701,7 @@ do_standby_clone(void)
|
|||||||
{
|
{
|
||||||
log_err(_("%s: could not connect to master\n"),
|
log_err(_("%s: could not connect to master\n"),
|
||||||
progname);
|
progname);
|
||||||
return;
|
exit(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* primary should be v9 or better */
|
/* primary should be v9 or better */
|
||||||
@@ -709,7 +710,7 @@ do_standby_clone(void)
|
|||||||
{
|
{
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
log_err(_("%s needs master to be PostgreSQL 9.0 or better\n"), progname);
|
log_err(_("%s needs master to be PostgreSQL 9.0 or better\n"), progname);
|
||||||
return;
|
exit(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check we are cloning a primary node */
|
/* Check we are cloning a primary node */
|
||||||
@@ -717,7 +718,7 @@ do_standby_clone(void)
|
|||||||
{
|
{
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
log_err(_("\nThe command should clone a primary node\n"));
|
log_err(_("\nThe command should clone a primary node\n"));
|
||||||
return;
|
exit(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* And check if it is well configured */
|
/* And check if it is well configured */
|
||||||
@@ -725,19 +726,19 @@ do_standby_clone(void)
|
|||||||
{
|
{
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
log_err(_("%s needs parameter 'wal_level' to be set to 'hot_standby'\n"), progname);
|
log_err(_("%s needs parameter 'wal_level' to be set to 'hot_standby'\n"), progname);
|
||||||
return;
|
exit(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
if (!guc_setted(conn, "wal_keep_segments", ">=", runtime_options.wal_keep_segments))
|
if (!guc_setted(conn, "wal_keep_segments", ">=", runtime_options.wal_keep_segments))
|
||||||
{
|
{
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
log_err(_("%s needs parameter 'wal_keep_segments' to be set to %s or greater (see the '-w' option)\n"), progname, runtime_options.wal_keep_segments);
|
log_err(_("%s needs parameter 'wal_keep_segments' to be set to %s or greater (see the '-w' option)\n"), progname, runtime_options.wal_keep_segments);
|
||||||
return;
|
exit(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
if (!guc_setted(conn, "archive_mode", "=", "on"))
|
if (!guc_setted(conn, "archive_mode", "=", "on"))
|
||||||
{
|
{
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
log_err(_("%s needs parameter 'archive_mode' to be set to 'on'\n"), progname);
|
log_err(_("%s needs parameter 'archive_mode' to be set to 'on'\n"), progname);
|
||||||
return;
|
exit(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
|
|
||||||
log_info(_("Succesfully connected to primary. Current installation size is %s\n"), get_cluster_size(conn));
|
log_info(_("Succesfully connected to primary. Current installation size is %s\n"), get_cluster_size(conn));
|
||||||
@@ -752,7 +753,7 @@ do_standby_clone(void)
|
|||||||
log_err("Can't get info about tablespaces: %s\n", PQerrorMessage(conn));
|
log_err("Can't get info about tablespaces: %s\n", PQerrorMessage(conn));
|
||||||
PQclear(res);
|
PQclear(res);
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
return;
|
exit(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
for (i = 0; i < PQntuples(res); i++)
|
for (i = 0; i < PQntuples(res); i++)
|
||||||
{
|
{
|
||||||
@@ -772,7 +773,7 @@ do_standby_clone(void)
|
|||||||
progname, tblspc_dir);
|
progname, tblspc_dir);
|
||||||
PQclear(res);
|
PQclear(res);
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
return;
|
exit(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
@@ -788,7 +789,7 @@ do_standby_clone(void)
|
|||||||
progname, tblspc_dir, strerror(errno));
|
progname, tblspc_dir, strerror(errno));
|
||||||
PQclear(res);
|
PQclear(res);
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
return;
|
exit(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
@@ -800,7 +801,7 @@ do_standby_clone(void)
|
|||||||
progname, tblspc_dir);
|
progname, tblspc_dir);
|
||||||
PQclear(res);
|
PQclear(res);
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
return;
|
exit(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
/* Trouble accessing directory */
|
/* Trouble accessing directory */
|
||||||
@@ -808,7 +809,7 @@ do_standby_clone(void)
|
|||||||
progname, tblspc_dir, strerror(errno));
|
progname, tblspc_dir, strerror(errno));
|
||||||
PQclear(res);
|
PQclear(res);
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
return;
|
exit(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -825,7 +826,7 @@ do_standby_clone(void)
|
|||||||
log_err("Can't get info about data directory and configuration files: %s\n", PQerrorMessage(conn));
|
log_err("Can't get info about data directory and configuration files: %s\n", PQerrorMessage(conn));
|
||||||
PQclear(res);
|
PQclear(res);
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
return;
|
exit(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
for (i = 0; i < PQntuples(res); i++)
|
for (i = 0; i < PQntuples(res); i++)
|
||||||
{
|
{
|
||||||
@@ -855,7 +856,7 @@ do_standby_clone(void)
|
|||||||
log_err("Can't start backup: %s\n", PQerrorMessage(conn));
|
log_err("Can't start backup: %s\n", PQerrorMessage(conn));
|
||||||
PQclear(res);
|
PQclear(res);
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
return;
|
exit(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
first_wal_segment = PQgetvalue(res, 0, 0);
|
first_wal_segment = PQgetvalue(res, 0, 0);
|
||||||
PQclear(res);
|
PQclear(res);
|
||||||
@@ -949,7 +950,7 @@ stop_backup:
|
|||||||
{
|
{
|
||||||
log_err(_("%s: could not connect to master\n"),
|
log_err(_("%s: could not connect to master\n"),
|
||||||
progname);
|
progname);
|
||||||
return;
|
exit(ERR_BAD_RSYNC);
|
||||||
}
|
}
|
||||||
|
|
||||||
log_notice("Finishing backup...\n");
|
log_notice("Finishing backup...\n");
|
||||||
@@ -963,36 +964,39 @@ stop_backup:
|
|||||||
log_err("Can't stop backup: %s\n", PQerrorMessage(conn));
|
log_err("Can't stop backup: %s\n", PQerrorMessage(conn));
|
||||||
PQclear(res);
|
PQclear(res);
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
return;
|
exit(ERR_STOP_BACKUP);
|
||||||
}
|
}
|
||||||
last_wal_segment = PQgetvalue(res, 0, 0);
|
last_wal_segment = PQgetvalue(res, 0, 0);
|
||||||
|
|
||||||
/* Now, if the rsync failed then exit */
|
/* If the rsync failed then exit */
|
||||||
if (r == 0)
|
if (r != 0)
|
||||||
{
|
exit(ERR_BAD_RSYNC);
|
||||||
|
|
||||||
if (runtime_options.verbose)
|
if (runtime_options.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 */
|
||||||
snprintf(local_control_file, MAXFILENAME, "%s/pg_xlog", runtime_options.dest_dir);
|
snprintf(local_control_file, MAXFILENAME, "%s/pg_xlog", runtime_options.dest_dir);
|
||||||
if (!create_directory(local_control_file))
|
if (!create_directory(local_control_file))
|
||||||
{
|
{
|
||||||
log_err(_("%s: couldn't create directory %s, you will need to do it manually...\n"),
|
log_err(_("%s: couldn't create directory %s, you will need to do it manually...\n"),
|
||||||
progname, runtime_options.dest_dir);
|
progname, runtime_options.dest_dir);
|
||||||
}
|
r = ERR_NEEDS_XLOG; /* continue, but eventually exit returning error */
|
||||||
|
|
||||||
/* Finally, write the recovery.conf file */
|
|
||||||
create_recovery_file(runtime_options.dest_dir);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Finally, write the recovery.conf file */
|
||||||
|
create_recovery_file(runtime_options.dest_dir);
|
||||||
|
|
||||||
PQclear(res);
|
PQclear(res);
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
|
|
||||||
/* We don't start the service because we still may want to move the directory */
|
/*
|
||||||
return;
|
* We don't start the service yet because we still may want to
|
||||||
|
* move the directory
|
||||||
|
*/
|
||||||
|
|
||||||
|
exit(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1023,14 +1027,14 @@ do_standby_promote(void)
|
|||||||
{
|
{
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
log_err(_("%s needs standby to be PostgreSQL 9.0 or better\n"), progname);
|
log_err(_("%s needs standby to be PostgreSQL 9.0 or better\n"), progname);
|
||||||
return;
|
exit(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check we are in a standby node */
|
/* Check we are in a standby node */
|
||||||
if (!is_standby(conn))
|
if (!is_standby(conn))
|
||||||
{
|
{
|
||||||
log_err("repmgr: The command should be executed on a standby node\n");
|
log_err("repmgr: The command should be executed on a standby node\n");
|
||||||
return;
|
exit(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* we also need to check if there isn't any master already */
|
/* we also need to check if there isn't any master already */
|
||||||
@@ -1039,7 +1043,7 @@ do_standby_promote(void)
|
|||||||
{
|
{
|
||||||
PQfinish(old_master_conn);
|
PQfinish(old_master_conn);
|
||||||
log_err("There is a master already in this cluster\n");
|
log_err("There is a master already in this cluster\n");
|
||||||
return;
|
exit(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (runtime_options.verbose)
|
if (runtime_options.verbose)
|
||||||
@@ -1055,7 +1059,7 @@ do_standby_promote(void)
|
|||||||
log_err("Can't get info about data directory: %s\n", PQerrorMessage(conn));
|
log_err("Can't get info about data directory: %s\n", PQerrorMessage(conn));
|
||||||
PQclear(res);
|
PQclear(res);
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
return;
|
exit(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
strcpy(data_dir, PQgetvalue(res, 0, 0));
|
strcpy(data_dir, PQgetvalue(res, 0, 0));
|
||||||
PQclear(res);
|
PQclear(res);
|
||||||
@@ -1065,26 +1069,27 @@ do_standby_promote(void)
|
|||||||
snprintf(recovery_done_path, MAXFILENAME, "%s/%s", data_dir, RECOVERY_DONE_FILE);
|
snprintf(recovery_done_path, MAXFILENAME, "%s/%s", data_dir, RECOVERY_DONE_FILE);
|
||||||
rename(recovery_file_path, recovery_done_path);
|
rename(recovery_file_path, recovery_done_path);
|
||||||
|
|
||||||
/* We assume the pg_ctl script is in the PATH */
|
/*
|
||||||
snprintf(script, QUERY_STR_LEN, "pg_ctl -D %s -m fast restart", data_dir);
|
* We assume the pg_ctl script is in the PATH. Restart and wait for
|
||||||
|
* the server to finish starting, so that the check below will
|
||||||
|
* find an active server rather than one starting up. This may
|
||||||
|
* hang for up the default timeout (60 seconds).
|
||||||
|
*/
|
||||||
|
snprintf(script, QUERY_STR_LEN, "pg_ctl -D %s -w -m fast restart", data_dir);
|
||||||
r = system(script);
|
r = system(script);
|
||||||
if (r != 0)
|
if (r != 0)
|
||||||
{
|
{
|
||||||
log_err("Can't restart service\n");
|
log_err("Can't restart PostgreSQL server\n");
|
||||||
return;
|
exit(ERR_NO_RESTART);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* reconnect to check we got promoted */
|
/* reconnect to check we got promoted */
|
||||||
/*
|
conn = establishDBConnection(options.conninfo, true);
|
||||||
* XXX i'm removing this because it gives an annoying message saying couldn't connect
|
if (is_standby(conn))
|
||||||
* but is just the server starting up
|
log_err("\n%s: STANDBY PROMOTE failed, this is still a standby node.\n", progname);
|
||||||
* conn = establishDBConnection(options.conninfo, true);
|
else
|
||||||
* if (is_standby(conn))
|
log_err("\n%s: you should REINDEX any hash indexes you have.\n", progname);
|
||||||
* log_err("\n%s: STANDBY PROMOTE failed, this is still a standby node.\n", progname);
|
PQfinish(conn);
|
||||||
* else
|
|
||||||
* log_err("\n%s: you should REINDEX any hash indexes you have.\n", progname);
|
|
||||||
* PQfinish(conn);
|
|
||||||
*/
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1115,6 +1120,7 @@ do_standby_follow(void)
|
|||||||
{
|
{
|
||||||
log_err("\n%s: The command should be executed in a standby node\n", progname);
|
log_err("\n%s: The command should be executed in a standby node\n", progname);
|
||||||
return;
|
return;
|
||||||
|
exit(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* should be v9 or better */
|
/* should be v9 or better */
|
||||||
@@ -1123,7 +1129,7 @@ do_standby_follow(void)
|
|||||||
{
|
{
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
log_err(_("\n%s needs standby to be PostgreSQL 9.0 or better\n"), progname);
|
log_err(_("\n%s needs standby to be PostgreSQL 9.0 or better\n"), progname);
|
||||||
return;
|
exit(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 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 */
|
||||||
@@ -1132,7 +1138,7 @@ do_standby_follow(void)
|
|||||||
{
|
{
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
log_err("There isn't a master to follow in this cluster\n");
|
log_err("There isn't a master to follow in this cluster\n");
|
||||||
return;
|
exit(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check we are going to point to a master */
|
/* Check we are going to point to a master */
|
||||||
@@ -1140,7 +1146,7 @@ do_standby_follow(void)
|
|||||||
{
|
{
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
log_err("%s: The node to follow should be a master\n", progname);
|
log_err("%s: The node to follow should be a master\n", progname);
|
||||||
return;
|
exit(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* should be v9 or better */
|
/* should be v9 or better */
|
||||||
@@ -1150,7 +1156,7 @@ do_standby_follow(void)
|
|||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
PQfinish(master_conn);
|
PQfinish(master_conn);
|
||||||
log_err(_("%s needs master to be PostgreSQL 9.0 or better\n"), progname);
|
log_err(_("%s needs master to be PostgreSQL 9.0 or better\n"), progname);
|
||||||
return;
|
exit(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* master and standby version should match */
|
/* master and standby version should match */
|
||||||
@@ -1160,7 +1166,7 @@ do_standby_follow(void)
|
|||||||
PQfinish(master_conn);
|
PQfinish(master_conn);
|
||||||
log_err(_("%s needs versions of both master (%s) and standby (%s) to match.\n"),
|
log_err(_("%s needs versions of both master (%s) and standby (%s) to match.\n"),
|
||||||
progname, master_version, standby_version);
|
progname, master_version, standby_version);
|
||||||
return;
|
exit(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -1185,7 +1191,7 @@ do_standby_follow(void)
|
|||||||
log_err("Can't get info about data directory: %s\n", PQerrorMessage(conn));
|
log_err("Can't get info about data directory: %s\n", PQerrorMessage(conn));
|
||||||
PQclear(res);
|
PQclear(res);
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
return;
|
exit(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
strcpy(data_dir, PQgetvalue(res, 0, 0));
|
strcpy(data_dir, PQgetvalue(res, 0, 0));
|
||||||
PQclear(res);
|
PQclear(res);
|
||||||
@@ -1193,7 +1199,7 @@ do_standby_follow(void)
|
|||||||
|
|
||||||
/* write the recovery.conf file */
|
/* write the recovery.conf file */
|
||||||
if (!create_recovery_file(data_dir))
|
if (!create_recovery_file(data_dir))
|
||||||
return;
|
exit(ERR_BAD_CONFIG);
|
||||||
|
|
||||||
/* Finally, restart the service */
|
/* Finally, restart the service */
|
||||||
/* We assume the pg_ctl script is in the PATH */
|
/* We assume the pg_ctl script is in the PATH */
|
||||||
@@ -1203,6 +1209,7 @@ do_standby_follow(void)
|
|||||||
{
|
{
|
||||||
log_err("Can't restart service\n");
|
log_err("Can't restart service\n");
|
||||||
return;
|
return;
|
||||||
|
exit(ERR_NO_RESTART);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|||||||
12
repmgr.h
12
repmgr.h
@@ -45,6 +45,18 @@
|
|||||||
#define DEFAULT_DBNAME "postgres"
|
#define DEFAULT_DBNAME "postgres"
|
||||||
#define DEFAULT_REPMGR_SCHEMA_PREFIX "repmgr_"
|
#define DEFAULT_REPMGR_SCHEMA_PREFIX "repmgr_"
|
||||||
|
|
||||||
|
/* Exit return code */
|
||||||
|
|
||||||
|
#define SUCCESS 0
|
||||||
|
#define ERR_BAD_CONFIG 1
|
||||||
|
#define ERR_BAD_RSYNC 2
|
||||||
|
#define ERR_STOP_BACKUP 3
|
||||||
|
#define ERR_NO_RESTART 4
|
||||||
|
#define ERR_NEEDS_XLOG 5
|
||||||
|
#define ERR_DB_CON 6
|
||||||
|
#define ERR_DB_QUERY 7
|
||||||
|
#define ERR_PROMOTED 8
|
||||||
|
|
||||||
/* Run time options type */
|
/* Run time options type */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|
||||||
|
|||||||
24
repmgrd.c
24
repmgrd.c
@@ -107,12 +107,12 @@ main(int argc, char **argv)
|
|||||||
if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
|
if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)
|
||||||
{
|
{
|
||||||
help(progname);
|
help(progname);
|
||||||
exit(0);
|
exit(SUCCESS);
|
||||||
}
|
}
|
||||||
if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
|
if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0)
|
||||||
{
|
{
|
||||||
printf("%s (PostgreSQL) " PG_VERSION "\n", progname);
|
printf("%s (PostgreSQL) " PG_VERSION "\n", progname);
|
||||||
exit(0);
|
exit(SUCCESS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,7 +129,7 @@ main(int argc, char **argv)
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
usage();
|
usage();
|
||||||
exit(1);
|
exit(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -143,7 +143,7 @@ main(int argc, char **argv)
|
|||||||
{
|
{
|
||||||
log_err("Node information is missing. "
|
log_err("Node information is missing. "
|
||||||
"Check the configuration file.\n");
|
"Check the configuration file.\n");
|
||||||
exit(1);
|
exit(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
logger_init(progname, local_options.loglevel, local_options.logfacility);
|
logger_init(progname, local_options.loglevel, local_options.logfacility);
|
||||||
snprintf(repmgr_schema, MAXLEN, "%s%s", DEFAULT_REPMGR_SCHEMA_PREFIX, local_options.cluster_name);
|
snprintf(repmgr_schema, MAXLEN, "%s%s", DEFAULT_REPMGR_SCHEMA_PREFIX, local_options.cluster_name);
|
||||||
@@ -156,7 +156,7 @@ main(int argc, char **argv)
|
|||||||
{
|
{
|
||||||
PQfinish(myLocalConn);
|
PQfinish(myLocalConn);
|
||||||
log_err(_("%s needs standby to be PostgreSQL 9.0 or better\n"), progname);
|
log_err(_("%s needs standby to be PostgreSQL 9.0 or better\n"), progname);
|
||||||
exit(1);
|
exit(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -175,7 +175,7 @@ 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, local_options.node, local_options.cluster_name, &primary_options.node);
|
primaryConn = getMasterConnection(myLocalConn, local_options.node, local_options.cluster_name, &primary_options.node);
|
||||||
if (primaryConn == NULL)
|
if (primaryConn == NULL)
|
||||||
exit(1);
|
exit(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
|
|
||||||
checkClusterConfiguration();
|
checkClusterConfiguration();
|
||||||
@@ -258,7 +258,7 @@ MonitorExecute(void)
|
|||||||
if (PQstatus(primaryConn) != CONNECTION_OK)
|
if (PQstatus(primaryConn) != CONNECTION_OK)
|
||||||
{
|
{
|
||||||
log_err(_("We couldn't reconnect for long enough, exiting..."));
|
log_err(_("We couldn't reconnect for long enough, exiting..."));
|
||||||
exit(1);
|
exit(ERR_DB_CON);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check if we still are a standby, we could have been promoted */
|
/* Check if we still are a standby, we could have been promoted */
|
||||||
@@ -266,7 +266,7 @@ MonitorExecute(void)
|
|||||||
{
|
{
|
||||||
log_err(_("It seems like we have been promoted, so exit from monitoring..."));
|
log_err(_("It seems like we have been promoted, so exit from monitoring..."));
|
||||||
CloseConnections();
|
CloseConnections();
|
||||||
exit(1);
|
exit(ERR_PROMOTED);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -354,7 +354,7 @@ checkClusterConfiguration(void)
|
|||||||
PQclear(res);
|
PQclear(res);
|
||||||
PQfinish(myLocalConn);
|
PQfinish(myLocalConn);
|
||||||
PQfinish(primaryConn);
|
PQfinish(primaryConn);
|
||||||
exit(1);
|
exit(ERR_DB_QUERY);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -368,7 +368,7 @@ checkClusterConfiguration(void)
|
|||||||
PQclear(res);
|
PQclear(res);
|
||||||
PQfinish(myLocalConn);
|
PQfinish(myLocalConn);
|
||||||
PQfinish(primaryConn);
|
PQfinish(primaryConn);
|
||||||
exit(1);
|
exit(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
PQclear(res);
|
PQclear(res);
|
||||||
}
|
}
|
||||||
@@ -393,7 +393,7 @@ checkNodeConfiguration(char *conninfo)
|
|||||||
PQclear(res);
|
PQclear(res);
|
||||||
PQfinish(myLocalConn);
|
PQfinish(myLocalConn);
|
||||||
PQfinish(primaryConn);
|
PQfinish(primaryConn);
|
||||||
exit(1);
|
exit(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -414,7 +414,7 @@ checkNodeConfiguration(char *conninfo)
|
|||||||
PQerrorMessage(primaryConn));
|
PQerrorMessage(primaryConn));
|
||||||
PQfinish(myLocalConn);
|
PQfinish(myLocalConn);
|
||||||
PQfinish(primaryConn);
|
PQfinish(primaryConn);
|
||||||
exit(1);
|
exit(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PQclear(res);
|
PQclear(res);
|
||||||
|
|||||||
Reference in New Issue
Block a user