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:
Ian Barwick
2018-02-07 14:37:57 +09:00
parent f9528efdb8
commit 56710f4819
2 changed files with 3 additions and 33 deletions

View File

@@ -280,28 +280,14 @@ create_pg_dir(char *path, bool force)
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 (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);
nftw(path, unlink_dir_callback, 64, FTW_DEPTH | FTW_PHYS);
return true;
}
else
{
return false;
}
return false;
}
else
{