mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-27 00:46:29 +00:00
repmgr: set "synchronous_commit" to "local" by default
Rather than set this for individual connections, we'll change the setting each time a connection is made (except replication connections), which will obviate the need to take this into consideration when making connections in the application code. Resolves GitHub #276.
This commit is contained in:
51
dbutils.c
51
dbutils.c
@@ -35,6 +35,14 @@ char repmgr_schema_quoted[MAXLEN] = "";
|
|||||||
static int _get_node_record(PGconn *conn, char *cluster, char *sqlquery, t_node_info *node_info);
|
static int _get_node_record(PGconn *conn, char *cluster, char *sqlquery, t_node_info *node_info);
|
||||||
static bool _set_config(PGconn *conn, const char *config_param, const char *sqlquery);
|
static bool _set_config(PGconn *conn, const char *config_param, const char *sqlquery);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* _establish_db_connection()
|
||||||
|
*
|
||||||
|
* Connect to a database using a conninfo string.
|
||||||
|
*
|
||||||
|
* NOTE: *do not* use this for replication connections; use establish_db_connection_by_params() instead.
|
||||||
|
*/
|
||||||
|
|
||||||
PGconn *
|
PGconn *
|
||||||
_establish_db_connection(const char *conninfo, const bool exit_on_error, const bool log_notice, const bool verbose_only)
|
_establish_db_connection(const char *conninfo, const bool exit_on_error, const bool log_notice, const bool verbose_only)
|
||||||
{
|
{
|
||||||
@@ -78,6 +86,20 @@ _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)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (exit_on_error)
|
||||||
|
{
|
||||||
|
PQfinish(conn);
|
||||||
|
exit(ERR_DB_CON);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return conn;
|
return conn;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,8 +139,12 @@ PGconn *
|
|||||||
establish_db_connection_by_params(const char *keywords[], const char *values[],
|
establish_db_connection_by_params(const char *keywords[], const char *values[],
|
||||||
const bool exit_on_error)
|
const bool exit_on_error)
|
||||||
{
|
{
|
||||||
/* Make a connection to the database */
|
PGconn *conn;
|
||||||
PGconn *conn = PQconnectdbParams(keywords, values, true);
|
bool replication_connection = false;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
/* Connect to the database using the provided parameters */
|
||||||
|
conn = PQconnectdbParams(keywords, values, true);
|
||||||
|
|
||||||
/* Check to see that the backend connection was successfully made */
|
/* Check to see that the backend connection was successfully made */
|
||||||
if ((PQstatus(conn) != CONNECTION_OK))
|
if ((PQstatus(conn) != CONNECTION_OK))
|
||||||
@@ -132,6 +158,27 @@ establish_db_connection_by_params(const char *keywords[], const char *values[],
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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++)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return conn;
|
return conn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
18
repmgr.c
18
repmgr.c
@@ -3022,18 +3022,6 @@ do_standby_clone(void)
|
|||||||
strncpy(recovery_conninfo_str, upstream_node_record.conninfo_str, MAXLEN);
|
strncpy(recovery_conninfo_str, upstream_node_record.conninfo_str, MAXLEN);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Finally, set `synchronous_commit` to `local` to avoid problems
|
|
||||||
* if synchronous commit is in use.
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (primary_conn != NULL && PQstatus(primary_conn) == CONNECTION_OK)
|
|
||||||
{
|
|
||||||
if (set_config(primary_conn, "synchronous_commit", "local") == false)
|
|
||||||
{
|
|
||||||
exit(ERR_DB_QUERY);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mode == barman && PQstatus(source_conn) != CONNECTION_OK)
|
if (mode == barman && PQstatus(source_conn) != CONNECTION_OK)
|
||||||
@@ -4857,8 +4845,6 @@ do_standby_follow(void)
|
|||||||
*
|
*
|
||||||
* TODO:
|
* TODO:
|
||||||
* - make connection test timeouts/intervals configurable (see below)
|
* - make connection test timeouts/intervals configurable (see below)
|
||||||
* - add command line option --remote_pg_bindir or similar to
|
|
||||||
* optionally handle cases where the remote pg_bindir is different
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -5592,6 +5578,8 @@ do_standby_switchover(void)
|
|||||||
|
|
||||||
/* Check for entry in the new master's pg_stat_replication */
|
/* Check for entry in the new master's pg_stat_replication */
|
||||||
|
|
||||||
|
local_conn = establish_db_connection(options.conninfo, true);
|
||||||
|
|
||||||
{
|
{
|
||||||
int i,
|
int i,
|
||||||
replication_check_timeout = 60,
|
replication_check_timeout = 60,
|
||||||
@@ -5601,8 +5589,6 @@ do_standby_switchover(void)
|
|||||||
|
|
||||||
initPQExpBuffer(&event_details);
|
initPQExpBuffer(&event_details);
|
||||||
|
|
||||||
local_conn = establish_db_connection(options.conninfo, true);
|
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user