node service: enable provision of the -S/--superuser option

This is required to be able to execute a CHECKPOINT if the normal
repmgr user is not a superuser.
This commit is contained in:
Ian Barwick
2020-03-24 17:24:10 +09:00
parent 304c1391cc
commit 2b06f2d1ae
3 changed files with 51 additions and 2 deletions

View File

@@ -75,8 +75,22 @@
<para>
Issue a <command>CHECKPOINT</command> before stopping or restarting the node.
</para>
<para>
Note that a superuser connection is required to be able to execute the
<command>CHECKPOINT</command> command.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>-S</option>/<option>--superuser</option></term>
<listitem>
<para>
Connect as the named superuser instead of the normal &repmgr; user.
</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>

View File

@@ -2028,10 +2028,44 @@ do_node_service(void)
{
PGconn *conn = NULL;
if (strlen(config_file_options.conninfo))
conn = establish_db_connection(config_file_options.conninfo, true);
if (config_file_options.conninfo[0] != '\0')
{
t_conninfo_param_list node_conninfo = T_CONNINFO_PARAM_LIST_INITIALIZER;
char *errmsg = NULL;
bool parse_success = false;
initialize_conninfo_params(&node_conninfo, false);
parse_success = parse_conninfo_string(config_file_options.conninfo,
&node_conninfo,
&errmsg, false);
if (parse_success == false)
{
log_error(_("unable to parse conninfo string \"%s\" for local node"),
config_file_options.conninfo);
log_detail("%s", errmsg);
exit(ERR_BAD_CONFIG);
}
/*
* If --superuser option provided, attempt to connect as the specified user
*/
if (runtime_options.superuser[0] != '\0')
{
param_set(&node_conninfo,
"user",
runtime_options.superuser);
}
conn = establish_db_connection_by_params(&node_conninfo, true);
}
else
{
conn = establish_db_connection_by_params(&source_conninfo, true);
}
if (is_superuser_connection(conn, NULL) == false)
{

View File

@@ -1692,6 +1692,7 @@ check_cli_parameters(const int action)
{
case STANDBY_CLONE:
case NODE_CHECK:
case NODE_SERVICE:
break;
default:
item_list_append_format(&cli_warnings,