|
|
|
|
@ -112,10 +112,12 @@ parseCommandLine(int argc, char *argv[]) |
|
|
|
|
|
|
|
|
|
case 'd': |
|
|
|
|
old_cluster.pgdata = pg_strdup(optarg); |
|
|
|
|
old_cluster.pgconfig = pg_strdup(optarg); |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case 'D': |
|
|
|
|
new_cluster.pgdata = pg_strdup(optarg); |
|
|
|
|
new_cluster.pgconfig = pg_strdup(optarg); |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case 'g': |
|
|
|
|
@ -319,3 +321,61 @@ check_required_directory(char **dirpath, char *envVarName, |
|
|
|
|
#endif |
|
|
|
|
(*dirpath)[strlen(*dirpath) - 1] = 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* adjust_data_dir |
|
|
|
|
* |
|
|
|
|
* If a configuration-only directory was specified, find the real data dir |
|
|
|
|
* by quering the running server. This has limited checking because we |
|
|
|
|
* can't check for a running server because we can't find postmaster.pid. |
|
|
|
|
*/ |
|
|
|
|
void |
|
|
|
|
adjust_data_dir(ClusterInfo *cluster) |
|
|
|
|
{ |
|
|
|
|
char filename[MAXPGPATH]; |
|
|
|
|
char cmd[MAXPGPATH], cmd_output[MAX_STRING]; |
|
|
|
|
FILE *fd, *output; |
|
|
|
|
|
|
|
|
|
/* If there is no postgresql.conf, it can't be a config-only dir */ |
|
|
|
|
snprintf(filename, sizeof(filename), "%s/postgresql.conf", cluster->pgconfig); |
|
|
|
|
if ((fd = fopen(filename, "r")) == NULL) |
|
|
|
|
return; |
|
|
|
|
fclose(fd); |
|
|
|
|
|
|
|
|
|
/* If PG_VERSION exists, it can't be a config-only dir */ |
|
|
|
|
snprintf(filename, sizeof(filename), "%s/PG_VERSION", cluster->pgconfig); |
|
|
|
|
if ((fd = fopen(filename, "r")) != NULL) |
|
|
|
|
{ |
|
|
|
|
fclose(fd); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* Must be a configuration directory, so find the real data directory. */ |
|
|
|
|
|
|
|
|
|
prep_status("Finding the real data directory for the %s cluster", |
|
|
|
|
CLUSTER_NAME(cluster)); |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* We don't have a data directory yet, so we can't check the PG |
|
|
|
|
* version, so this might fail --- only works for PG 9.2+. If this |
|
|
|
|
* fails, pg_upgrade will fail anyway because the data files will not |
|
|
|
|
* be found. |
|
|
|
|
*/ |
|
|
|
|
snprintf(cmd, sizeof(cmd), "\"%s/postmaster\" -D \"%s\" -C data_directory", |
|
|
|
|
cluster->bindir, cluster->pgconfig); |
|
|
|
|
|
|
|
|
|
if ((output = popen(cmd, "r")) == NULL || |
|
|
|
|
fgets(cmd_output, sizeof(cmd_output), output) == NULL) |
|
|
|
|
pg_log(PG_FATAL, "Could not get data directory using %s: %s\n", |
|
|
|
|
cmd, getErrorText(errno)); |
|
|
|
|
|
|
|
|
|
pclose(output); |
|
|
|
|
|
|
|
|
|
/* Remove trailing newline */ |
|
|
|
|
if (strchr(cmd_output, '\n') != NULL) |
|
|
|
|
*strchr(cmd_output, '\n') = '\0'; |
|
|
|
|
|
|
|
|
|
cluster->pgdata = pg_strdup(cmd_output); |
|
|
|
|
|
|
|
|
|
check_ok(); |
|
|
|
|
} |
|
|
|
|
|