do not exit in guc_setted and guc_setted_typed

This commit is contained in:
Christian Kruse
2014-01-16 14:48:46 +01:00
parent 77aa6aa326
commit 6f149ead8f
3 changed files with 35 additions and 26 deletions

View File

@@ -213,12 +213,13 @@ pg_version(PGconn *conn, char* major_version)
}
bool
int
guc_setted(PGconn *conn, const char *parameter, const char *op,
const char *value)
{
PGresult *res;
char sqlquery[QUERY_STR_LEN];
int retval = 1;
sqlquery_snprintf(sqlquery, "SELECT true FROM pg_settings "
" WHERE name = '%s' AND setting %s '%s'",
@@ -229,30 +230,29 @@ guc_setted(PGconn *conn, const char *parameter, const char *op,
{
log_err(_("GUC setting check PQexec failed: %s"),
PQerrorMessage(conn));
PQclear(res);
PQfinish(conn);
exit(ERR_DB_QUERY);
retval = -1;
}
if (PQntuples(res) == 0)
else if (PQntuples(res) == 0)
{
PQclear(res);
return false;
retval = 0;
}
PQclear(res);
return true;
return retval;
}
/**
* Just like guc_setted except with an extra parameter containing the name of
* the pg datatype so that the comparison can be done properly.
*/
bool
int
guc_setted_typed(PGconn *conn, const char *parameter, const char *op,
const char *value, const char *datatype)
{
PGresult *res;
char sqlquery[QUERY_STR_LEN];
int retval = 1;
sqlquery_snprintf(sqlquery, "SELECT true FROM pg_settings "
" WHERE name = '%s' AND setting::%s %s '%s'::%s",
@@ -263,18 +263,16 @@ guc_setted_typed(PGconn *conn, const char *parameter, const char *op,
{
log_err(_("GUC setting check PQexec failed: %s"),
PQerrorMessage(conn));
PQclear(res);
PQfinish(conn);
exit(ERR_DB_QUERY);
retval = -1;
}
if (PQntuples(res) == 0)
else if (PQntuples(res) == 0)
{
PQclear(res);
return false;
retval = 0;
}
PQclear(res);
return true;
return retval;
}

View File

@@ -30,9 +30,9 @@ int is_standby(PGconn *conn);
int is_witness(PGconn *conn, char *schema, char *cluster, int node_id);
bool is_pgup(PGconn *conn, int timeout);
char *pg_version(PGconn *conn, char* major_version);
bool guc_setted(PGconn *conn, const char *parameter, const char *op,
int guc_setted(PGconn *conn, const char *parameter, const char *op,
const char *value);
bool guc_setted_typed(PGconn *conn, const char *parameter, const char *op,
int guc_setted_typed(PGconn *conn, const char *parameter, const char *op,
const char *value, const char *datatype);
const char *get_cluster_size(PGconn *conn);

View File

@@ -853,28 +853,39 @@ do_standby_clone(void)
}
/* And check if it is well configured */
if (!guc_setted(conn, "wal_level", "=", "hot_standby"))
i = guc_setted(conn, "wal_level", "=", "hot_standby");
if (i == 0 || i == -1)
{
PQfinish(conn);
log_err(_("%s needs parameter 'wal_level' to be set to 'hot_standby'\n"), progname);
if (i == 0)
log_err(_("%s needs parameter 'wal_level' to be set to 'hot_standby'\n"), progname);
exit(ERR_BAD_CONFIG);
}
if (!guc_setted_typed(conn, "wal_keep_segments", ">=", runtime_options.wal_keep_segments, "integer"))
i = guc_setted_typed(conn, "wal_keep_segments", ">=", runtime_options.wal_keep_segments, "integer");
if (i == 0 || i == -1)
{
PQfinish(conn);
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 PostgreSQL master.)\n"), progname, runtime_options.wal_keep_segments);
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 PostgreSQL master.)\n"), progname, runtime_options.wal_keep_segments);
exit(ERR_BAD_CONFIG);
}
if (!guc_setted(conn, "archive_mode", "=", "on"))
i = guc_setted(conn, "archive_mode", "=", "on");
if (i == 0 || i == -1)
{
PQfinish(conn);
log_err(_("%s needs parameter 'archive_mode' to be set to 'on'\n"), progname);
if (i == 0)
log_err(_("%s needs parameter 'archive_mode' to be set to 'on'\n"), progname);
exit(ERR_BAD_CONFIG);
}
if (!guc_setted(conn, "hot_standby", "=", "on"))
i = guc_setted(conn, "hot_standby", "=", "on");
if (i == 0 || i == -1)
{
PQfinish(conn);
log_err(_("%s needs parameter 'hot_standby' to be set to 'on'\n"), progname);
if (i == 0)
log_err(_("%s needs parameter 'hot_standby' to be set to 'on'\n"), progname);
exit(ERR_BAD_CONFIG);
}