From f0693271d31bf5cb3b4b3ea26f302ea370f9b52a Mon Sep 17 00:00:00 2001 From: Ian Barwick Date: Fri, 25 Oct 2019 14:28:31 +0900 Subject: [PATCH] Clean up replication slot creation/deletion functions --- dbutils.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/dbutils.c b/dbutils.c index 3037b395..91915063 100644 --- a/dbutils.c +++ b/dbutils.c @@ -4197,11 +4197,11 @@ create_replication_slot_replprot(PGconn *conn, PGconn *repl_conn, char *slot_nam { PQExpBufferData query; PGresult *res = NULL; + bool success = true; if (_verify_replication_slot(conn, slot_name, error_msg) == false) return false; - initPQExpBuffer(&query); appendPQExpBuffer(&query, @@ -4219,16 +4219,17 @@ create_replication_slot_replprot(PGconn *conn, PGconn *repl_conn, char *slot_nam res = PQexec(repl_conn, query.data); - if (PQresultStatus(res) != PGRES_TUPLES_OK || !PQntuples(res)) + if ((PQresultStatus(res) != PGRES_TUPLES_OK || !PQntuples(res)) && error_msg != NULL) { - log_db_error(conn, NULL, _("unable to execute CREATE_REPLICATION_SLOT")); - - PQclear(res); - return false; + appendPQExpBuffer(error_msg, + _("unable to create slot \"%s\" on the upstream node: %s\n"), + slot_name, + PQerrorMessage(conn)); + success = false; } PQclear(res); - return true; + return success; } @@ -4237,6 +4238,7 @@ create_replication_slot_sql(PGconn *conn, char *slot_name, PQExpBufferData *erro { PQExpBufferData query; PGresult *res = NULL; + bool success = true; if (_verify_replication_slot(conn, slot_name, error_msg) == false) return false; @@ -4263,18 +4265,17 @@ create_replication_slot_sql(PGconn *conn, char *slot_name, PQExpBufferData *erro res = PQexec(conn, query.data); termPQExpBuffer(&query); - if (PQresultStatus(res) != PGRES_TUPLES_OK) + if (PQresultStatus(res) != PGRES_TUPLES_OK && error_msg != NULL) { appendPQExpBuffer(error_msg, _("unable to create slot \"%s\" on the upstream node: %s\n"), slot_name, PQerrorMessage(conn)); - PQclear(res); - return false; + success = false; } PQclear(res); - return true; + return success; }