summaryrefslogtreecommitdiff
path: root/src/bin/pg_upgrade/exec.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/bin/pg_upgrade/exec.c')
-rw-r--r--src/bin/pg_upgrade/exec.c79
1 files changed, 49 insertions, 30 deletions
diff --git a/src/bin/pg_upgrade/exec.c b/src/bin/pg_upgrade/exec.c
index 6d04e5671db..55a6f0dfbad 100644
--- a/src/bin/pg_upgrade/exec.c
+++ b/src/bin/pg_upgrade/exec.c
@@ -14,7 +14,7 @@
#include <fcntl.h>
#include <sys/types.h>
-static void check_data_dir(const char *pg_data);
+static void check_data_dir(ClusterInfo *cluster);
static void check_bin_dir(ClusterInfo *cluster);
static void validate_exec(const char *dir, const char *cmdName);
@@ -220,9 +220,9 @@ verify_directories(void)
pg_fatal("You must have read and write access in the current directory.\n");
check_bin_dir(&old_cluster);
- check_data_dir(old_cluster.pgdata);
+ check_data_dir(&old_cluster);
check_bin_dir(&new_cluster);
- check_data_dir(new_cluster.pgdata);
+ check_data_dir(&new_cluster);
}
@@ -253,6 +253,32 @@ win32_check_directory_write_permissions(void)
/*
+ * check_single_dir()
+ *
+ * Check for the presence of a single directory in PGDATA, and fail if
+ * is it missing or not accessible.
+ */
+static void
+check_single_dir(const char *pg_data, const char *subdir)
+{
+ struct stat statBuf;
+ char subDirName[MAXPGPATH];
+
+ snprintf(subDirName, sizeof(subDirName), "%s%s%s", pg_data,
+ /* Win32 can't stat() a directory with a trailing slash. */
+ *subdir ? "/" : "",
+ subdir);
+
+ if (stat(subDirName, &statBuf) != 0)
+ report_status(PG_FATAL, "check for \"%s\" failed: %s\n",
+ subDirName, strerror(errno));
+ else if (!S_ISDIR(statBuf.st_mode))
+ report_status(PG_FATAL, "%s is not a directory\n",
+ subDirName);
+}
+
+
+/*
* check_data_dir()
*
* This function validates the given cluster directory - we search for a
@@ -262,34 +288,27 @@ win32_check_directory_write_permissions(void)
*
*/
static void
-check_data_dir(const char *pg_data)
+check_data_dir(ClusterInfo *cluster)
{
- char subDirName[MAXPGPATH];
- int subdirnum;
-
- /* start check with top-most directory */
- const char *requiredSubdirs[] = {"", "base", "global", "pg_clog",
- "pg_multixact", "pg_subtrans", "pg_tblspc", "pg_twophase",
- "pg_xlog"};
-
- for (subdirnum = 0;
- subdirnum < sizeof(requiredSubdirs) / sizeof(requiredSubdirs[0]);
- ++subdirnum)
- {
- struct stat statBuf;
-
- snprintf(subDirName, sizeof(subDirName), "%s%s%s", pg_data,
- /* Win32 can't stat() a directory with a trailing slash. */
- *requiredSubdirs[subdirnum] ? "/" : "",
- requiredSubdirs[subdirnum]);
-
- if (stat(subDirName, &statBuf) != 0)
- report_status(PG_FATAL, "check for \"%s\" failed: %s\n",
- subDirName, strerror(errno));
- else if (!S_ISDIR(statBuf.st_mode))
- report_status(PG_FATAL, "%s is not a directory\n",
- subDirName);
- }
+ const char *pg_data = cluster->pgdata;
+
+ /* get old and new cluster versions */
+ old_cluster.major_version = get_major_server_version(&old_cluster);
+ new_cluster.major_version = get_major_server_version(&new_cluster);
+
+ check_single_dir(pg_data, "");
+ check_single_dir(pg_data, "base");
+ check_single_dir(pg_data, "global");
+ check_single_dir(pg_data, "pg_multixact");
+ check_single_dir(pg_data, "pg_subtrans");
+ check_single_dir(pg_data, "pg_tblspc");
+ check_single_dir(pg_data, "pg_twophase");
+
+ /* pg_xlog has been renamed to pg_wal in post-10 cluster */
+ if (GET_MAJOR_VERSION(cluster->major_version) < 1000)
+ check_single_dir(pg_data, "pg_xlog");
+ else
+ check_single_dir(pg_data, "pg_wal");
}