I need a local connection to get the master of the cluster

This commit is contained in:
Jaime Casanova
2012-04-26 12:29:04 -05:00
parent c543402d65
commit 36d5b5bc24

View File

@@ -399,20 +399,29 @@ static void
do_cluster_cleanup(void) do_cluster_cleanup(void)
{ {
int master_id; int master_id;
PGconn *conn;
PGconn *master_conn; PGconn *master_conn;
PGresult *res; PGresult *res;
char sqlquery[QUERY_STR_LEN]; char sqlquery[QUERY_STR_LEN];
/* I need a connection to my local db to know what node is the master */
log_info(_("%s connecting to database\n"), progname);
conn = establishDBConnection(options.conninfo, true);
/* check if there is a master in this cluster */ /* check if there is a master in this cluster */
log_info(_("%s connecting to master database\n"), progname); log_info(_("%s connecting to master database\n"), progname);
master_conn = getMasterConnection(master_conn, options.node, options.cluster_name, master_conn = getMasterConnection(conn, options.node, options.cluster_name,
&master_id, NULL); &master_id, NULL);
if (!master_conn) if (!master_conn)
{ {
log_err(_("cluster cleanup: cannot connect to master\n")); log_err(_("cluster cleanup: cannot connect to master\n"));
PQfinish(conn);
exit(ERR_DB_CON); exit(ERR_DB_CON);
} }
/* I don't need a local connection anymore */
PQfinish(conn);
if (runtime_options.keep_history > 0) if (runtime_options.keep_history > 0)
{ {
sqlquery_snprintf(sqlquery, "DELETE FROM %s.repl_monitor " sqlquery_snprintf(sqlquery, "DELETE FROM %s.repl_monitor "