From 976a61005e31cdf4f3df8228fa4cc89b69df1221 Mon Sep 17 00:00:00 2001 From: Ian Barwick Date: Fri, 17 Mar 2017 20:32:36 +0900 Subject: [PATCH] Only attempt to set synchronous transaction mode with valid connection --- dbutils.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/dbutils.c b/dbutils.c index 65f6e3c2..c90f045e 100644 --- a/dbutils.c +++ b/dbutils.c @@ -90,9 +90,8 @@ _establish_db_connection(const char *conninfo, const bool exit_on_error, const b * set "synchronous_commit" to "local" in case synchronous replication is in use */ - if (set_config(conn, "synchronous_commit", "local") == false) + else if (set_config(conn, "synchronous_commit", "local") == false) { - if (exit_on_error) { PQfinish(conn); @@ -157,25 +156,26 @@ establish_db_connection_by_params(const char *keywords[], const char *values[], exit(ERR_DB_CON); } } - - - /* - * set "synchronous_commit" to "local" in case synchronous replication is in - * use (provided this is not a replication connection) - */ - - for (i = 0; keywords[i]; i++) + else { - if (strcmp(keywords[i], "replication") == 0) - replication_connection = true; - } + /* + * set "synchronous_commit" to "local" in case synchronous replication is in + * use (provided this is not a replication connection) + */ - if (replication_connection == false && set_config(conn, "synchronous_commit", "local") == false) - { - if (exit_on_error) + for (i = 0; keywords[i]; i++) { - PQfinish(conn); - exit(ERR_DB_CON); + if (strcmp(keywords[i], "replication") == 0) + replication_connection = true; + } + + if (replication_connection == false && set_config(conn, "synchronous_commit", "local") == false) + { + if (exit_on_error) + { + PQfinish(conn); + exit(ERR_DB_CON); + } } }