Add version check if replication slot usage requested

Replication slots require 9.4 or greater
This commit is contained in:
Ian Barwick
2015-02-02 22:16:04 +09:00
parent 7a760c32ff
commit 49debcdf92
2 changed files with 71 additions and 21 deletions

View File

@@ -63,7 +63,7 @@ static bool copy_configuration(PGconn *masterconn, PGconn *witnessconn);
static void write_primary_conninfo(char *line); static void write_primary_conninfo(char *line);
static bool write_recovery_file_line(FILE *recovery_file, char *recovery_file_path, char *line); static bool write_recovery_file_line(FILE *recovery_file, char *recovery_file_path, char *line);
static int check_server_version(PGconn *conn, char *server_type, bool exit_on_error, char *server_version_string); static int check_server_version(PGconn *conn, char *server_type, bool exit_on_error, char *server_version_string);
static bool check_upstream_config(PGconn *conn, bool exit_on_error); static bool check_upstream_config(PGconn *conn, int server_version_num, bool exit_on_error);
static bool create_node_record(PGconn *conn, char *action, int node, char *type, int upstream_node, char *cluster_name, char *node_name, char *conninfo, int priority); static bool create_node_record(PGconn *conn, char *action, int node, char *type, int upstream_node, char *cluster_name, char *node_name, char *conninfo, int priority);
@@ -337,7 +337,7 @@ main(int argc, char **argv)
/* We check that port number is not null */ /* We check that port number is not null */
if (!runtime_options.dbname[0]) if (!runtime_options.dbname[0])
{ {
strncpy(runtime_options.masterport, DEFAULT_MASTER_PORT, MAXLEN); strncpy(runtime_options.masterport, DEFAULT_MASTER_PORT, MAXLEN);
} }
/* Read the configuration file, normally repmgr.conf */ /* Read the configuration file, normally repmgr.conf */
@@ -787,6 +787,8 @@ do_standby_clone(void)
PGresult *res; PGresult *res;
char sqlquery[QUERY_STR_LEN]; char sqlquery[QUERY_STR_LEN];
int server_version_num;
char cluster_size[MAXLEN]; char cluster_size[MAXLEN];
int r = 0, int r = 0,
@@ -837,9 +839,9 @@ do_standby_clone(void)
/* Verify that master is a supported server version */ /* Verify that master is a supported server version */
log_info(_("%s connected to master, checking its state\n"), progname); log_info(_("%s connected to master, checking its state\n"), progname);
check_server_version(primary_conn, "master", true, NULL); server_version_num = check_server_version(primary_conn, "master", true, NULL);
check_upstream_config(primary_conn, true); check_upstream_config(primary_conn, server_version_num, true);
sqlquery_snprintf(sqlquery, sqlquery_snprintf(sqlquery,
"SELECT pg_tablespace_location(oid) spclocation " "SELECT pg_tablespace_location(oid) spclocation "
@@ -2402,7 +2404,7 @@ check_server_version(PGconn *conn, char *server_type, bool exit_on_error, char *
*/ */
static bool static bool
check_upstream_config(PGconn *conn, bool exit_on_error) check_upstream_config(PGconn *conn, int server_version_num, bool exit_on_error)
{ {
int i; int i;
bool config_ok = true; bool config_ok = true;
@@ -2425,22 +2427,67 @@ check_upstream_config(PGconn *conn, bool exit_on_error)
config_ok = false; config_ok = false;
} }
/* XXX we may need to modify this */ if(options.use_replication_slots)
i = guc_set_typed(conn, "wal_keep_segments", ">=",
runtime_options.wal_keep_segments, "integer");
if (i == 0 || i == -1)
{ {
if (i == 0) /* Does the server support physical replication slots? */
log_err(_("%s needs parameter 'wal_keep_segments' to be set to %s or greater (see the '-w' option or edit the postgresql.conf of the upstream server.)\n"), if(server_version_num < 90400)
progname, runtime_options.wal_keep_segments);
if(exit_on_error == true)
{ {
PQfinish(conn); log_err(_("Server version must be 9.4 or later to enable replication slots\n"));
exit(ERR_BAD_CONFIG);
if(exit_on_error == true)
{
PQfinish(conn);
exit(ERR_BAD_CONFIG);
}
config_ok = false;
}
/* Server is 9.4 or greater - non-zero `max_replication_slots` required */
else
{
i = guc_set_typed(conn, "max_replication_slots", ">",
"1", "integer");
if (i == 0 || i == -1)
{
if (i == 0)
{
log_err(_("%s needs parameter 'max_replication_slots' must be set to at least 1 to enable replication slots\n"),
progname);
if(exit_on_error == true)
{
PQfinish(conn);
exit(ERR_BAD_CONFIG);
}
config_ok = false;
}
}
} }
config_ok = false; }
/*
* physical replication slots not available or not requested -
* ensure some reasonably high value set for `wal_keep_segments`
*/
else
{
i = guc_set_typed(conn, "wal_keep_segments", ">=",
runtime_options.wal_keep_segments, "integer");
if (i == 0 || i == -1)
{
if (i == 0)
log_err(_("%s needs parameter 'wal_keep_segments' to be set to %s or greater (see the '-w' option or edit the postgresql.conf of the upstream server.)\n"),
progname, runtime_options.wal_keep_segments);
if(exit_on_error == true)
{
PQfinish(conn);
exit(ERR_BAD_CONFIG);
}
config_ok = false;
}
} }
i = guc_set(conn, "archive_mode", "=", "on"); i = guc_set(conn, "archive_mode", "=", "on");
@@ -2499,6 +2546,9 @@ do_check_upstream_config(void)
{ {
PGconn *conn; PGconn *conn;
bool config_ok; bool config_ok;
int server_version_num;
parse_config(runtime_options.config_file, &options);
/* Connection parameters for upstream server only */ /* Connection parameters for upstream server only */
keywords[0] = "host"; keywords[0] = "host";
@@ -2514,9 +2564,9 @@ do_check_upstream_config(void)
/* Verify that upstream server is a supported server version */ /* Verify that upstream server is a supported server version */
log_info(_("%s connected to upstream server, checking its state\n"), progname); log_info(_("%s connected to upstream server, checking its state\n"), progname);
check_server_version(conn, "upstream server", false, NULL); server_version_num = check_server_version(conn, "upstream server", false, NULL);
config_ok = check_upstream_config(conn, false); config_ok = check_upstream_config(conn, server_version_num, false);
if(config_ok == true) if(config_ok == true)
{ {

View File

@@ -1362,10 +1362,10 @@ do_primary_failover(void)
if(local_options.use_replication_slots) if(local_options.use_replication_slots)
{ {
if(create_replication_slot(new_primary_conn, local_options.slot_name) == false) if(create_replication_slot(new_primary_conn, node_info.slot_name) == false)
{ {
log_err(_("Unable to create slot '%s' on the primary node: %s\n"), log_err(_("Unable to create slot '%s' on the primary node: %s\n"),
local_options.slot_name, node_info.slot_name,
PQerrorMessage(new_primary_conn)); PQerrorMessage(new_primary_conn));
PQfinish(new_primary_conn); PQfinish(new_primary_conn);
terminate(ERR_DB_QUERY); terminate(ERR_DB_QUERY);