mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-27 17:06:29 +00:00
Make self-referencing foreign key on repl_nodes table deferrable
This commit is contained in:
20
dbutils.c
20
dbutils.c
@@ -1127,6 +1127,21 @@ witness_copy_node_records(PGconn *masterconn, PGconn *witnessconn, char *cluster
|
|||||||
|
|
||||||
begin_transaction(witnessconn);
|
begin_transaction(witnessconn);
|
||||||
|
|
||||||
|
/* Defer constraints */
|
||||||
|
sqlquery_snprintf(sqlquery, "SET CONSTRAINTS ALL DEFERRED;");
|
||||||
|
log_verbose(LOG_DEBUG, "witness_copy_node_records():\n%s\n", sqlquery);
|
||||||
|
|
||||||
|
res = PQexec(witnessconn, sqlquery);
|
||||||
|
if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
|
||||||
|
{
|
||||||
|
log_err(_("Unable to defer constraints:\n%s\n"),
|
||||||
|
PQerrorMessage(witnessconn));
|
||||||
|
rollback_transaction(witnessconn);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Truncate existing records */
|
||||||
sqlquery_snprintf(sqlquery, "TRUNCATE TABLE %s.repl_nodes", get_repmgr_schema_quoted(witnessconn));
|
sqlquery_snprintf(sqlquery, "TRUNCATE TABLE %s.repl_nodes", get_repmgr_schema_quoted(witnessconn));
|
||||||
|
|
||||||
log_verbose(LOG_DEBUG, "witness_copy_node_records():\n%s\n", sqlquery);
|
log_verbose(LOG_DEBUG, "witness_copy_node_records():\n%s\n", sqlquery);
|
||||||
@@ -1136,9 +1151,12 @@ witness_copy_node_records(PGconn *masterconn, PGconn *witnessconn, char *cluster
|
|||||||
{
|
{
|
||||||
log_err(_("Unable to truncate witness servers's repl_nodes table:\n%s\n"),
|
log_err(_("Unable to truncate witness servers's repl_nodes table:\n%s\n"),
|
||||||
PQerrorMessage(witnessconn));
|
PQerrorMessage(witnessconn));
|
||||||
|
rollback_transaction(witnessconn);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Get current records from primary */
|
||||||
sqlquery_snprintf(sqlquery,
|
sqlquery_snprintf(sqlquery,
|
||||||
"SELECT id, type, upstream_node_id, name, conninfo, priority, slot_name, active FROM %s.repl_nodes",
|
"SELECT id, type, upstream_node_id, name, conninfo, priority, slot_name, active FROM %s.repl_nodes",
|
||||||
get_repmgr_schema_quoted(masterconn));
|
get_repmgr_schema_quoted(masterconn));
|
||||||
@@ -1156,6 +1174,7 @@ witness_copy_node_records(PGconn *masterconn, PGconn *witnessconn, char *cluster
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Insert primary records into witness table */
|
||||||
for (i = 0; i < PQntuples(res); i++)
|
for (i = 0; i < PQntuples(res); i++)
|
||||||
{
|
{
|
||||||
bool node_record_created;
|
bool node_record_created;
|
||||||
@@ -1197,6 +1216,7 @@ witness_copy_node_records(PGconn *masterconn, PGconn *witnessconn, char *cluster
|
|||||||
}
|
}
|
||||||
PQclear(res);
|
PQclear(res);
|
||||||
|
|
||||||
|
/* And finished */
|
||||||
commit_transaction(witnessconn);
|
commit_transaction(witnessconn);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
2
repmgr.c
2
repmgr.c
@@ -4505,7 +4505,7 @@ create_schema(PGconn *conn)
|
|||||||
"CREATE TABLE %s.repl_nodes ( "
|
"CREATE TABLE %s.repl_nodes ( "
|
||||||
" id INTEGER PRIMARY KEY, "
|
" id INTEGER PRIMARY KEY, "
|
||||||
" type TEXT NOT NULL CHECK (type IN('master','standby','witness')), "
|
" type TEXT NOT NULL CHECK (type IN('master','standby','witness')), "
|
||||||
" upstream_node_id INTEGER NULL REFERENCES %s.repl_nodes (id), "
|
" upstream_node_id INTEGER NULL REFERENCES %s.repl_nodes (id) DEFERRABLE, "
|
||||||
" cluster TEXT NOT NULL, "
|
" cluster TEXT NOT NULL, "
|
||||||
" name TEXT NOT NULL, "
|
" name TEXT NOT NULL, "
|
||||||
" conninfo TEXT NOT NULL, "
|
" conninfo TEXT NOT NULL, "
|
||||||
|
|||||||
31
sql/repmgr3.1.1_repmgr3.1.2.sql
Normal file
31
sql/repmgr3.1.1_repmgr3.1.2.sql
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* Update a repmgr 3.1.1 installation to repmgr 3.1.2
|
||||||
|
* --------------------------------------------------
|
||||||
|
*
|
||||||
|
* This update is only required if repmgrd is being used in conjunction
|
||||||
|
* with a witness server.
|
||||||
|
*
|
||||||
|
* The new repmgr package should be installed first. Then
|
||||||
|
* carry out these steps:
|
||||||
|
*
|
||||||
|
* 1. (If repmgrd is used) stop any running repmgrd instances
|
||||||
|
* 2. On the master node, execute the SQL statement listed below
|
||||||
|
* 3. (If repmgrd is used) restart repmgrd
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If your repmgr installation is not included in your repmgr
|
||||||
|
* user's search path, please set the search path to the name
|
||||||
|
* of the repmgr schema to ensure objects are installed in
|
||||||
|
* the correct location.
|
||||||
|
*
|
||||||
|
* The repmgr schema is "repmgr_" + the cluster name defined in
|
||||||
|
* 'repmgr.conf'.
|
||||||
|
*/
|
||||||
|
|
||||||
|
-- SET search_path TO 'name_of_repmgr_schema';
|
||||||
|
|
||||||
|
BEGIN;
|
||||||
|
|
||||||
|
ALTER TABLE repl_nodes ALTER CONSTRAINT repl_nodes_upstream_node_id_fkey DEFERRABLE;
|
||||||
|
COMMIT;
|
||||||
Reference in New Issue
Block a user