From 447054a6309dcc88e65caf308576b4b34f5fff62 Mon Sep 17 00:00:00 2001 From: Ian Barwick Date: Thu, 2 Apr 2020 12:37:32 +0900 Subject: [PATCH] standby promote: in --dry-run mode, display promote command which will be used For PostgreSQL 12 and later, explicitly note whether repmgr user has execution permissions on the pg_promote() function. --- HISTORY | 3 ++- doc/appendix-release-notes.xml | 10 +++++++++- doc/repmgr-standby-promote.xml | 4 ++++ repmgr-action-standby.c | 31 +++++++++++++++++++++++++++++++ 4 files changed, 46 insertions(+), 2 deletions(-) diff --git a/HISTORY b/HISTORY index f3170115..c6919a5e 100644 --- a/HISTORY +++ b/HISTORY @@ -15,8 +15,9 @@ repmgr: consolidate replication connection code (Ian) repmgr: check permissions for "pg_promote()" and fall back to pg_ctl if necessary (Ian) - repmgr: accept option -S/--superuser for "node check"; GitHub #612 (Ian) + repmgr: in --dry-run mode, display promote command which will be used (Ian) repmgr: enable "service_promote_command" in PostgreSQL 12 (Ian) + repmgr: accept option -S/--superuser for "node check"; GitHub #612 (Ian) 5.0 2019-10-15 general: add PostgreSQL 12 support (Ian) diff --git a/doc/appendix-release-notes.xml b/doc/appendix-release-notes.xml index e79543ed..36fb4aa2 100644 --- a/doc/appendix-release-notes.xml +++ b/doc/appendix-release-notes.xml @@ -49,6 +49,14 @@ General improvements + + + repmgr standby promote: + when executed with , the method which would be used to promote the node + will be displayed. + + + repmgr standby follow: @@ -67,7 +75,7 @@ repmgr node check: - accept option / GitHub #621. + accept option /. GitHub #621. diff --git a/doc/repmgr-standby-promote.xml b/doc/repmgr-standby-promote.xml index b7faf5f7..3f90b965 100644 --- a/doc/repmgr-standby-promote.xml +++ b/doc/repmgr-standby-promote.xml @@ -115,6 +115,10 @@ pg_promote(), &repmgr; will fall back to using "pg_ctl promote". + + Execute repmgr standby promote with the + to check whether the &repmgr; user has permission to execute pg_promote(). + If the repmgr user is not a superuser, execution permission for this function can be granted with e.g.: diff --git a/repmgr-action-standby.c b/repmgr-action-standby.c index 6b95cea0..1d7cb0c8 100644 --- a/repmgr-action-standby.c +++ b/repmgr-action-standby.c @@ -2409,6 +2409,37 @@ do_standby_promote(void) } } + /* + * In --dry-run mode, note which promotion method will be used. + * For Pg12 and later, check whether pg_promote() can be executed. + */ + if (runtime_options.dry_run == true) + { + if (config_file_options.service_promote_command[0] != '\0') + { + log_info(_("node will be promoted using command defined in \"service_promote_command\"")); + log_detail(_("\"service_promote_command\" is \"%s\""), + config_file_options.service_promote_command); + } + else if (PQserverVersion(local_conn) >= 120000) + { + if (can_execute_pg_promote(local_conn) == false) + { + log_info(_("node will be promoted using \"pg_ctl promote\"")); + log_detail(_("user \"%s\" does not have permission to execute \"pg_promote()\""), + PQuser(local_conn)); + } + else + { + log_info(_("node will be promoted using the \"pg_promote()\" function")); + } + } + else + { + log_info(_("node will be promoted using \"pg_ctl promote\"")); + } + } + if (runtime_options.dry_run == true) { PQfinish(local_conn);