mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-26 16:46:28 +00:00
repmgr: simplify data directory checks when cloning
Attempting to use the contents of pg_control to tell whether the directory is in use by PostgreSQL can result in false positives; we should use a check based on the pidfile. Also change the HINT to indicate a data directory can be overwritten if -F/--force is provided.
This commit is contained in:
18
dirutil.c
18
dirutil.c
@@ -280,28 +280,14 @@ create_pg_dir(char *path, bool force)
|
|||||||
|
|
||||||
if (is_pg_dir(path))
|
if (is_pg_dir(path))
|
||||||
{
|
{
|
||||||
DBState db_state;
|
|
||||||
|
|
||||||
/* note: state will be DB_SHUTDOWNED if unable to read a control file */
|
|
||||||
db_state = get_db_state(path);
|
|
||||||
|
|
||||||
if (force == true)
|
if (force == true)
|
||||||
{
|
{
|
||||||
if (db_state != DB_SHUTDOWNED && db_state != DB_SHUTDOWNED_IN_RECOVERY)
|
|
||||||
{
|
|
||||||
log_error(_("directory \"%s\" appears to be an active PostgreSQL data directory"), path);
|
|
||||||
log_detail(_("instance appears to be running in state \"%s\""), describe_db_state(db_state));
|
|
||||||
log_hint(_("any running instance must be shut down"));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
log_notice(_("deleting existing data directory \"%s\""), path);
|
log_notice(_("deleting existing data directory \"%s\""), path);
|
||||||
nftw(path, unlink_dir_callback, 64, FTW_DEPTH | FTW_PHYS);
|
nftw(path, unlink_dir_callback, 64, FTW_DEPTH | FTW_PHYS);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
return false;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -276,22 +276,6 @@ do_standby_clone(void)
|
|||||||
exit(ERR_BAD_CONFIG);
|
exit(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* by this point we should know the target data directory - check there's
|
|
||||||
* no running Pg instance
|
|
||||||
*/
|
|
||||||
if (is_pg_dir(local_data_directory))
|
|
||||||
{
|
|
||||||
DBState state = get_db_state(local_data_directory);
|
|
||||||
|
|
||||||
if (state != DB_SHUTDOWNED && state != DB_SHUTDOWNED_IN_RECOVERY)
|
|
||||||
{
|
|
||||||
log_error(_("target data directory appears to contain an active PostgreSQL instance"));
|
|
||||||
log_detail(_("instance state is %s"), describe_db_state(state));
|
|
||||||
exit(ERR_BAD_CONFIG);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (upstream_conninfo_found == true)
|
if (upstream_conninfo_found == true)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
@@ -3289,7 +3273,7 @@ check_source_server()
|
|||||||
{
|
{
|
||||||
log_error(_("target data directory appears to be a PostgreSQL data directory"));
|
log_error(_("target data directory appears to be a PostgreSQL data directory"));
|
||||||
log_detail(_("target data directory is \"%s\""), local_data_directory);
|
log_detail(_("target data directory is \"%s\""), local_data_directory);
|
||||||
log_hint(_("ensure the target data directory is empty before running \"STANDBY CLONE\" in pg_basebackup mode"));
|
log_hint(_("use -F/--force to overwrite the existing data directory"));
|
||||||
PQfinish(source_conn);
|
PQfinish(source_conn);
|
||||||
exit(ERR_BAD_CONFIG);
|
exit(ERR_BAD_CONFIG);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user