"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:
Ian Barwick
2019-02-05 13:25:21 +09:00
parent d8048060a2
commit 701944c194
4 changed files with 218 additions and 14 deletions

View File

@@ -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 */
/* ============= */