Ensure standby.signal is set correctly if -D/--data-directory supplied

When cloning a standby, it's possible to do a "raw" clone by providing
-D/--data-directory but no repmgr.conf file. However the code which
creates "standby.signal" was assuming the presence of a valid
repmgr.conf complete with "data_directory" configuration.

This is very much a niche-use case.
This commit is contained in:
Ian Barwick
2020-11-27 11:20:09 +09:00
parent 4d8bc63834
commit a93c6dfca7
4 changed files with 27 additions and 25 deletions

View File

@@ -2813,7 +2813,8 @@ do_node_rejoin(void)
log_notice(_("temporarily removing \"standby.signal\""));
log_detail(_("this is required so pg_rewind can fix the unclean shutdown"));
make_standby_signal_path(standby_signal_file_path);
make_standby_signal_path(config_file_options.data_directory,
standby_signal_file_path);
if (unlink(standby_signal_file_path) < 0 && errno != ENOENT)
{
@@ -2838,7 +2839,7 @@ do_node_rejoin(void)
* of whether the pg_rewind operation failed.
*/
log_notice(_("recreating \"standby.signal\""));
write_standby_signal();
write_standby_signal(config_file_options.data_directory);
}
if (ret == false)

View File

@@ -173,21 +173,6 @@ do_standby_clone(void)
initialize_conninfo_params(&recovery_conninfo, false);
/*
* --replication-conf-only provided - we'll handle that separately
*/
if (runtime_options.replication_conf_only == true)
{
return _do_create_replication_conf();
}
/*
* conninfo params for the actual upstream node (which might be different
* to the node we're cloning from) to write to recovery.conf
*/
mode = get_standby_clone_mode();
/*
* Copy the provided data directory; if a configuration file was provided,
* use the (mandatory) value from that; if -D/--pgdata was provided, use
@@ -215,6 +200,20 @@ do_standby_clone(void)
exit(ERR_BAD_CONFIG);
}
/*
* --replication-conf-only provided - we'll handle that separately
*/
if (runtime_options.replication_conf_only == true)
{
return _do_create_replication_conf();
}
/*
* conninfo params for the actual upstream node (which might be different
* to the node we're cloning from) to write to recovery.conf
*/
mode = get_standby_clone_mode();
if (mode == barman)
{
@@ -1479,7 +1478,7 @@ _do_create_replication_conf(void)
}
else
{
if (write_standby_signal() == false)
if (write_standby_signal(local_data_directory) == false)
{
log_error(_("unable to write \"standby.signal\" file"));
}
@@ -8001,7 +8000,7 @@ create_recovery_file(t_node_info *node_record, t_conninfo_param_list *primary_co
return false;
}
if (write_standby_signal() == false)
if (write_standby_signal(local_data_directory) == false)
{
return false;
}

View File

@@ -282,8 +282,8 @@ 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);
extern void make_standby_signal_path(char *buf);
extern bool write_standby_signal(void);
extern void make_standby_signal_path(const char *data_dir, char *buf);
extern bool write_standby_signal(const char *data_dir);
extern bool create_replication_slot(PGconn *conn, char *slot_name, t_node_info *upstream_node_record, PQExpBufferData *error_msg);
extern bool drop_replication_slot_if_exists(PGconn *conn, int node_id, char *slot_name);

View File

@@ -3661,11 +3661,11 @@ can_use_pg_rewind(PGconn *conn, const char *data_directory, PQExpBufferData *rea
void
make_standby_signal_path(char *buf)
make_standby_signal_path(const char *data_dir, char *buf)
{
snprintf(buf, MAXPGPATH,
"%s/%s",
config_file_options.data_directory,
data_dir,
STANDBY_SIGNAL_FILE);
}
@@ -3673,13 +3673,15 @@ make_standby_signal_path(char *buf)
* create standby.signal (PostgreSQL 12 and later)
*/
bool
write_standby_signal(void)
write_standby_signal(const char *data_dir)
{
char standby_signal_file_path[MAXPGPATH] = "";
FILE *file;
mode_t um;
make_standby_signal_path(standby_signal_file_path);
Assert(data_dir != NULL);
make_standby_signal_path(data_dir, standby_signal_file_path);
/* Set umask to 0600 */
um = umask((~(S_IRUSR | S_IWUSR)) & (S_IRWXG | S_IRWXO));