mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-25 08:06:29 +00:00
standby promote: fall back to "pg_ctl promote" if necessary
From PostgreSQL 12, the SQL-level function "pg_promote()" can be used to promote a PostgreSQL instance, however usage is restricted to superusers and users to whom explicit execution permission for this function has been granted. Therefore, if execution permission is not available, fall back to "pg_ctl promote".
This commit is contained in:
37
dbutils.c
37
dbutils.c
@@ -1723,6 +1723,43 @@ get_timeline_history(PGconn *repl_conn, TimeLineID tli)
|
||||
/* user/role information functions */
|
||||
/* =============================== */
|
||||
|
||||
|
||||
bool
|
||||
can_execute_pg_promote(PGconn *conn)
|
||||
{
|
||||
PQExpBufferData query;
|
||||
PGresult *res;
|
||||
bool has_pg_promote= false;
|
||||
|
||||
/* pg_promote() available from PostgreSQL 12 */
|
||||
if(PQserverVersion(conn) < 120000)
|
||||
return false;
|
||||
|
||||
initPQExpBuffer(&query);
|
||||
appendPQExpBufferStr(&query,
|
||||
" SELECT pg_catalog.has_function_privilege( "
|
||||
" CURRENT_USER, "
|
||||
" 'pg_catalog.pg_promote(bool,int)', "
|
||||
" 'execute' "
|
||||
" )");
|
||||
|
||||
res = PQexec(conn, query.data);
|
||||
|
||||
if (PQresultStatus(res) != PGRES_TUPLES_OK)
|
||||
{
|
||||
log_db_error(conn, query.data,
|
||||
_("can_execute_pg_promote(): unable to query user function privilege"));
|
||||
}
|
||||
else
|
||||
{
|
||||
has_pg_promote = atobool(PQgetvalue(res, 0, 0));
|
||||
}
|
||||
termPQExpBuffer(&query);
|
||||
|
||||
return has_pg_promote;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
connection_has_pg_settings(PGconn *conn)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user