diff --git a/repmgr.c b/repmgr.c index 8075a9c2..0b589141 100644 --- a/repmgr.c +++ b/repmgr.c @@ -423,19 +423,26 @@ do_cluster_show(void) do_cluster_cleanup(void) { int master_id; + PGconn *conn = NULL; PGconn *master_conn = NULL; PGresult *res; char sqlquery[QUERY_STR_LEN]; + /* We need to connect to check configuration */ + log_info(_("%s connecting to database\n"), progname); + conn = establishDBConnection(options.conninfo, true); + /* check if there is a master in this cluster */ log_info(_("%s connecting to master database\n"), progname); - master_conn = getMasterConnection(master_conn, repmgr_schema, options.cluster_name, + master_conn = getMasterConnection(conn, repmgr_schema, options.cluster_name, &master_id, NULL); if (!master_conn) { log_err(_("cluster cleanup: cannot connect to master\n")); + PQfinish(conn); exit(ERR_DB_CON); } + PQfinish(conn); if (runtime_options.keep_history > 0) {