From d93d42fadb971bf3dfd605d735e4c93c5a151e47 Mon Sep 17 00:00:00 2001 From: Warren Moore Date: Mon, 24 Mar 2014 14:19:29 +0000 Subject: [PATCH] fix: witness creation and monitoring While reading node entries from master use a separate PGresult when inserting into witness. Witness monitoring supplies a null value for 'last_apply_time'. --- repmgr.c | 10 ++++++---- repmgrd.c | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/repmgr.c b/repmgr.c index 939ea9a7..5a3f65aa 100644 --- a/repmgr.c +++ b/repmgr.c @@ -2368,7 +2368,7 @@ static bool copy_configuration(PGconn *masterconn, PGconn *witnessconn) { char sqlquery[MAXLEN]; - PGresult *res; + PGresult *res, *res_witness; int i; sqlquery_snprintf(sqlquery, "TRUNCATE TABLE %s.repl_nodes", repmgr_schema); @@ -2401,15 +2401,17 @@ copy_configuration(PGconn *masterconn, PGconn *witnessconn) atoi(PQgetvalue(res, i, 3)), PQgetvalue(res, i, 4)); - res = PQexec(witnessconn, sqlquery); - if (!res || PQresultStatus(res) != PGRES_COMMAND_OK) + res_witness = PQexec(witnessconn, sqlquery); + if (!res_witness || PQresultStatus(res_witness) != PGRES_COMMAND_OK) { fprintf(stderr, "Cannot copy configuration to witness, %s\n", PQerrorMessage(witnessconn)); - PQclear(res); + PQclear(res_witness); return false; } + PQclear(res_witness); } + PQclear(res); return true; } diff --git a/repmgrd.c b/repmgrd.c index 84ffb2a2..ad4dcd9b 100644 --- a/repmgrd.c +++ b/repmgrd.c @@ -551,7 +551,7 @@ witness_monitor(void) sqlquery_snprintf(sqlquery, "INSERT INTO %s.repl_monitor " "VALUES(%d, %d, '%s'::timestamp with time zone, " - " pg_current_xlog_location(), null, " + " null, pg_current_xlog_location(), null, " " 0, 0)", repmgr_schema, primary_options.node, local_options.node, monitor_witness_timestamp);