aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Momjian <bruce@momjian.us>2014-04-17 11:42:21 -0400
committerBruce Momjian <bruce@momjian.us>2014-04-17 11:42:21 -0400
commit071d9f085089f3fbae1b472debd38c555cd4a436 (patch)
tree67100b0587cfb3fb924a4273293e8bf3c76112f3
parent95aa823eb611a1280c1ab80c651c1ae62719b3e2 (diff)
downloadpostgresql-071d9f085089f3fbae1b472debd38c555cd4a436.tar.gz
postgresql-071d9f085089f3fbae1b472debd38c555cd4a436.zip
pg_upgrade: throw an error for non-existent tablespace directories
Non-existent tablespace directory references can occur if user tablespaces are created inside data directories and the data directory is renamed in preparation for running pg_upgrade, and the symbolic links are not updated. Backpatch to 9.3.
-rw-r--r--contrib/pg_upgrade/tablespace.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/contrib/pg_upgrade/tablespace.c b/contrib/pg_upgrade/tablespace.c
index 4747e7906e7..74cbbaa71bd 100644
--- a/contrib/pg_upgrade/tablespace.c
+++ b/contrib/pg_upgrade/tablespace.c
@@ -11,6 +11,8 @@
#include "pg_upgrade.h"
+#include <sys/types.h>
+
static void get_tablespace_paths(void);
static void set_tablespace_directory_suffix(ClusterInfo *cluster);
@@ -66,9 +68,39 @@ get_tablespace_paths(void)
i_spclocation = PQfnumber(res, "spclocation");
for (tblnum = 0; tblnum < os_info.num_old_tablespaces; tblnum++)
+ {
+ struct stat statBuf;
+
os_info.old_tablespaces[tblnum] = pg_strdup(
PQgetvalue(res, tblnum, i_spclocation));
+ /*
+ * Check that the tablespace path exists and is a directory.
+ * Effectively, this is checking only for tables/indexes in
+ * non-existent tablespace directories. Databases located in
+ * non-existent tablespaces already throw a backend error.
+ * Non-existent tablespace directories can occur when a data
+ * directory that contains user tablespaces is moved as part
+ * of pg_upgrade preparation and the symbolic links are not
+ * updated.
+ */
+ if (stat(os_info.old_tablespaces[tblnum], &statBuf) != 0)
+ {
+ if (errno == ENOENT)
+ report_status(PG_FATAL,
+ "tablespace directory \"%s\" does not exist\n",
+ os_info.old_tablespaces[tblnum]);
+ else
+ report_status(PG_FATAL,
+ "cannot stat() tablespace directory \"%s\": %s\n",
+ os_info.old_tablespaces[tblnum], getErrorText(errno));
+ }
+ if (!S_ISDIR(statBuf.st_mode))
+ report_status(PG_FATAL,
+ "tablespace path \"%s\" is not a directory\n",
+ os_info.old_tablespaces[tblnum]);
+ }
+
PQclear(res);
PQfinish(conn);