From a1f4285e2bc78f776b3756400b757ddecb50395d Mon Sep 17 00:00:00 2001 From: Jaime Casanova Date: Thu, 19 Dec 2013 00:55:56 -0500 Subject: [PATCH] Add guc_setted_typed() function to allow wal_keep_segmeents to be checked as an integer instead of text Patch by Jay Taylor --- dbutils.c | 34 ++++++++++++++++++++++++++++++++++ dbutils.h | 2 ++ repmgr.c | 2 +- 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/dbutils.c b/dbutils.c index 0e4c4749..9157a6e9 100644 --- a/dbutils.c +++ b/dbutils.c @@ -250,6 +250,40 @@ guc_setted(PGconn *conn, const char *parameter, const char *op, return true; } +/** + * 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 +guc_setted_typed(PGconn *conn, const char *parameter, const char *op, + const char *value, const char *datatype) +{ + PGresult *res; + char sqlquery[QUERY_STR_LEN]; + + sqlquery_snprintf(sqlquery, "SELECT true FROM pg_settings " + " WHERE name = '%s' AND setting::%s %s '%s'::%s", + parameter, datatype, op, value, datatype); + + res = PQexec(conn, sqlquery); + if (PQresultStatus(res) != PGRES_TUPLES_OK) + { + log_err(_("GUC setting check PQexec failed: %s"), + PQerrorMessage(conn)); + PQclear(res); + PQfinish(conn); + exit(ERR_DB_QUERY); + } + if (PQntuples(res) == 0) + { + PQclear(res); + return false; + } + PQclear(res); + + return true; +} + const char * get_cluster_size(PGconn *conn) diff --git a/dbutils.h b/dbutils.h index 8d983048..4ce7f0a6 100644 --- a/dbutils.h +++ b/dbutils.h @@ -32,6 +32,8 @@ 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, const char *value); +bool guc_setted(PGconn *conn, const char *parameter, const char *op, + const char *value, const char *datatype); const char *get_cluster_size(PGconn *conn); PGconn *getMasterConnection(PGconn *standby_conn, char *schema, char *cluster, int *master_id, char *master_conninfo_out); diff --git a/repmgr.c b/repmgr.c index a20c159b..111b4e5e 100644 --- a/repmgr.c +++ b/repmgr.c @@ -842,7 +842,7 @@ do_standby_clone(void) log_err(_("%s needs parameter 'wal_level' to be set to 'hot_standby'\n"), progname); exit(ERR_BAD_CONFIG); } - if (!guc_setted(conn, "wal_keep_segments", ">=", runtime_options.wal_keep_segments)) + if (!guc_setted_typed(conn, "wal_keep_segments", ">=", runtime_options.wal_keep_segments, "integer")) { 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);