mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-22 22:56:29 +00:00
Add configuration file parameter "config_directory"
This enables explicit provision of an external configuration file
directory, which if set will be passed to "pg_ctl" as the -D
parameter. Otherwise "pg_ctl" will default to using the data directory,
which will cause some operations to fail if the configuration files
are not present there.
Note this is implemented primarily for feature completeness and for
development/testing purposes. Users who have installed "repmgr" from
a package should not rely on "pg_ctl" to stop/start/restart PostgreSQL,
instead they should set the appropriate "service_..._command" for their
operating system. For more details see:
https://repmgr.org/docs/4.0/configuration-service-commands.html
Note: in a future release, the presence of "config_directory" in repmgr.conf
will be used to implictly set "--copy-external-config-files=samepath" when
cloning a standby; this is a behaviour change so will be implemented in the
next major realease (repmgr 4.1).
Implements GitHub #424.
This commit is contained in:
@@ -288,6 +288,7 @@ _parse_config(t_configuration_options *options, ItemList *error_list, ItemList *
|
||||
memset(options->node_name, 0, sizeof(options->node_name));
|
||||
memset(options->conninfo, 0, sizeof(options->conninfo));
|
||||
memset(options->data_directory, 0, sizeof(options->data_directory));
|
||||
memset(options->config_directory, 0, sizeof(options->data_directory));
|
||||
memset(options->pg_bindir, 0, sizeof(options->pg_bindir));
|
||||
options->replication_type = REPLICATION_TYPE_PHYSICAL;
|
||||
|
||||
@@ -464,6 +465,9 @@ _parse_config(t_configuration_options *options, ItemList *error_list, ItemList *
|
||||
strncpy(options->conninfo, value, MAXLEN);
|
||||
else if (strcmp(name, "data_directory") == 0)
|
||||
strncpy(options->data_directory, value, MAXPGPATH);
|
||||
else if (strcmp(name, "config_directory") == 0)
|
||||
strncpy(options->config_directory, value, MAXPGPATH);
|
||||
|
||||
else if (strcmp(name, "replication_user") == 0)
|
||||
{
|
||||
if (strlen(value) < NAMEDATALEN)
|
||||
|
||||
@@ -73,6 +73,7 @@ typedef struct
|
||||
char conninfo[MAXLEN];
|
||||
char replication_user[NAMEDATALEN];
|
||||
char data_directory[MAXPGPATH];
|
||||
char config_directory[MAXPGPATH];
|
||||
char pg_bindir[MAXPGPATH];
|
||||
int replication_type;
|
||||
|
||||
@@ -159,7 +160,7 @@ typedef struct
|
||||
|
||||
#define T_CONFIGURATION_OPTIONS_INITIALIZER { \
|
||||
/* node information */ \
|
||||
UNKNOWN_NODE_ID, "", "", "", "", "", REPLICATION_TYPE_PHYSICAL, \
|
||||
UNKNOWN_NODE_ID, "", "", "", "", "", "", REPLICATION_TYPE_PHYSICAL, \
|
||||
/* log settings */ \
|
||||
"", "", "", DEFAULT_LOG_STATUS_INTERVAL, \
|
||||
/* standby clone settings */ \
|
||||
|
||||
@@ -1518,7 +1518,7 @@ do_node_service(void)
|
||||
|
||||
if (data_dir_required_for_action(action))
|
||||
{
|
||||
get_node_data_directory(data_dir);
|
||||
get_node_config_directory(data_dir);
|
||||
|
||||
if (data_dir[0] == '\0')
|
||||
{
|
||||
@@ -1606,7 +1606,7 @@ _do_node_service_list_actions(t_server_action action)
|
||||
|
||||
if (data_dir_required == true)
|
||||
{
|
||||
get_node_data_directory(data_dir);
|
||||
get_node_config_directory(data_dir);
|
||||
}
|
||||
|
||||
/* show command for specific action only */
|
||||
|
||||
@@ -73,7 +73,7 @@ static char local_repmgr_tmp_directory[MAXPGPATH];
|
||||
static char datadir_list_filename[MAXLEN];
|
||||
static char barman_command_buf[MAXLEN] = "";
|
||||
|
||||
static void _do_standby_promote_internal(PGconn *conn, const char *data_dir);
|
||||
static void _do_standby_promote_internal(PGconn *conn);
|
||||
static void _do_create_recovery_conf(void);
|
||||
|
||||
static void check_barman_config(void);
|
||||
@@ -1957,13 +1957,12 @@ do_standby_promote(void)
|
||||
|
||||
PQfinish(current_primary_conn);
|
||||
|
||||
|
||||
_do_standby_promote_internal(conn, config_file_options.data_directory);
|
||||
_do_standby_promote_internal(conn);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
_do_standby_promote_internal(PGconn *conn, const char *data_dir)
|
||||
_do_standby_promote_internal(PGconn *conn)
|
||||
{
|
||||
char script[MAXLEN];
|
||||
int r,
|
||||
@@ -1975,7 +1974,9 @@ _do_standby_promote_internal(PGconn *conn, const char *data_dir)
|
||||
|
||||
t_node_info local_node_record = T_NODE_INFO_INITIALIZER;
|
||||
RecordStatus record_status = RECORD_NOT_FOUND;
|
||||
char data_dir[MAXPGPATH];
|
||||
|
||||
get_node_config_directory(data_dir);
|
||||
|
||||
/* fetch local node record so we can add detail in log messages */
|
||||
record_status = get_node_record(conn,
|
||||
@@ -3636,7 +3637,7 @@ do_standby_switchover(void)
|
||||
}
|
||||
|
||||
/* promote standby (local node) */
|
||||
_do_standby_promote_internal(local_conn, config_file_options.data_directory);
|
||||
_do_standby_promote_internal(local_conn);
|
||||
|
||||
|
||||
/*
|
||||
|
||||
@@ -231,6 +231,7 @@ extern void print_help_header(void);
|
||||
/* server control functions */
|
||||
extern void get_server_action(t_server_action action, char *script, char *data_dir);
|
||||
extern bool data_dir_required_for_action(t_server_action action);
|
||||
extern void get_node_config_directory(char *config_dir_buf);
|
||||
extern void get_node_data_directory(char *data_dir_buf);
|
||||
extern void init_node_record(t_node_info *node_record);
|
||||
extern bool can_use_pg_rewind(PGconn *conn, const char *data_directory, PQExpBufferData *reason);
|
||||
|
||||
@@ -1328,6 +1328,15 @@ check_cli_parameters(const int action)
|
||||
_("--no-upstream-connection only effective in Barman mode"));
|
||||
}
|
||||
}
|
||||
|
||||
if (strlen(config_file_options.config_directory))
|
||||
{
|
||||
if (runtime_options.copy_external_config_files == false)
|
||||
{
|
||||
item_list_append(&cli_warnings,
|
||||
_("\"config_directory\" set in repmgr.conf, but --copy-external-config-files not provided"));
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -2735,6 +2744,33 @@ data_dir_required_for_action(t_server_action action)
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Copy the location of the configuration file directory into the
|
||||
* provided buffer; if "config_directory" provided, use that, otherwise
|
||||
* default to the data directory.
|
||||
*
|
||||
* This is primarily intended for use with "pg_ctl" (which itself shouldn't
|
||||
* be used outside of development environments).
|
||||
*/
|
||||
void
|
||||
get_node_config_directory(char *config_dir_buf)
|
||||
{
|
||||
if (config_file_options.config_directory[0] != '\0')
|
||||
{
|
||||
strncpy(config_dir_buf, config_file_options.config_directory, MAXPGPATH);
|
||||
return;
|
||||
}
|
||||
|
||||
if (config_file_options.data_directory[0] != '\0')
|
||||
{
|
||||
strncpy(config_dir_buf, config_file_options.data_directory, MAXPGPATH);
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
get_node_data_directory(char *data_dir_buf)
|
||||
{
|
||||
|
||||
@@ -40,18 +40,28 @@
|
||||
# is not running and there's no other way of determining
|
||||
# the data directory.
|
||||
|
||||
#replication_user='repmgr' # User to make replication connections with, if not set defaults
|
||||
# to the user defined in "conninfo".
|
||||
|
||||
# =============================================================================
|
||||
|
||||
# Optional configuration items
|
||||
# =============================================================================
|
||||
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Server settings
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
#config_directory='' # If configuration files are located outside the data
|
||||
# directory, specify the directory where the main
|
||||
# postgresql.conf file is located.
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Replication settings
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
#replication_user='repmgr' # User to make replication connections with, if not set defaults
|
||||
# to the user defined in "conninfo".
|
||||
|
||||
#replication_type=physical # Must be one of 'physical' or 'bdr'.
|
||||
|
||||
#location=default # arbitrary string defining the location of the node; this
|
||||
|
||||
Reference in New Issue
Block a user