mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-25 16:16:29 +00:00
"standby promote": add check for WAL replay status if replay is paused
If WAL replay is paused but WAL is still pending replay, PostgreSQL will ignore the promote request until WAL replay is unpaused. This may lead to the standby being promoted at an unpredictable point in time outside of repmgr's control. Moreover it may not be obvious that this is happening, or why, and it will appear that an apparently successful promotion attempt has not actually worked. To prevent this from happening, repmgr will now refuse to promote the standy if WAL replay is paused *and* WAL is still pending replay. GitHub #540.
This commit is contained in:
50
dbutils.c
50
dbutils.c
@@ -4946,6 +4946,7 @@ is_downstream_node_attached(PGconn *conn, char *node_name)
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
set_primary_last_seen(PGconn *conn)
|
||||
{
|
||||
@@ -5000,6 +5001,55 @@ get_primary_last_seen(PGconn *conn)
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
is_wal_replay_paused(PGconn *conn, bool check_pending_wal)
|
||||
{
|
||||
PQExpBufferData query;
|
||||
PGresult *res = NULL;
|
||||
bool is_paused = false;
|
||||
|
||||
initPQExpBuffer(&query);
|
||||
|
||||
if (PQserverVersion(conn) >= 100000)
|
||||
{
|
||||
appendPQExpBufferStr(&query,
|
||||
"SELECT pg_catalog.pg_is_wal_replay_paused()");
|
||||
|
||||
if (check_pending_wal == true)
|
||||
{
|
||||
appendPQExpBufferStr(&query,
|
||||
" AND pg_catalog.pg_last_wal_replay_location() < pg_catalog.pg_last_wal_receive_location()");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
appendPQExpBufferStr(&query,
|
||||
"SELECT pg_catalog.pg_is_xlog_replay_paused()");
|
||||
if (check_pending_wal == true)
|
||||
{
|
||||
appendPQExpBufferStr(&query,
|
||||
" AND pg_catalog.pg_last_xlog_replay_location() < pg_catalog.pg_last_xlog_receive_location()");
|
||||
}
|
||||
}
|
||||
|
||||
res = PQexec(conn, query.data);
|
||||
|
||||
if (PQresultStatus(res) != PGRES_TUPLES_OK)
|
||||
{
|
||||
log_db_error(conn, query.data, _("unable to execute \"%s\""), query.data);
|
||||
}
|
||||
else
|
||||
{
|
||||
is_paused = atobool(PQgetvalue(res, 0, 0));
|
||||
}
|
||||
|
||||
termPQExpBuffer(&query);
|
||||
PQclear(res);
|
||||
|
||||
return is_paused;
|
||||
}
|
||||
|
||||
|
||||
/* ============= */
|
||||
/* BDR functions */
|
||||
/* ============= */
|
||||
|
||||
Reference in New Issue
Block a user