|
11 | 11 |
|
12 | 12 | #include "pg_upgrade.h"
|
13 | 13 |
|
| 14 | +#include <sys/types.h> |
| 15 | + |
14 | 16 | static void get_tablespace_paths(void);
|
15 | 17 | static void set_tablespace_directory_suffix(ClusterInfo *cluster);
|
16 | 18 |
|
@@ -65,9 +67,39 @@ get_tablespace_paths(void)
|
65 | 67 | i_spclocation = PQfnumber(res, "spclocation");
|
66 | 68 |
|
67 | 69 | for (tblnum = 0; tblnum < os_info.num_old_tablespaces; tblnum++)
|
| 70 | + { |
| 71 | + struct stat statBuf; |
| 72 | + |
68 | 73 | os_info.old_tablespaces[tblnum] = pg_strdup(
|
69 | 74 | PQgetvalue(res, tblnum, i_spclocation));
|
70 | 75 |
|
| 76 | + /* |
| 77 | + * Check that the tablespace path exists and is a directory. |
| 78 | + * Effectively, this is checking only for tables/indexes in |
| 79 | + * non-existent tablespace directories. Databases located in |
| 80 | + * non-existent tablespaces already throw a backend error. |
| 81 | + * Non-existent tablespace directories can occur when a data |
| 82 | + * directory that contains user tablespaces is moved as part |
| 83 | + * of pg_upgrade preparation and the symbolic links are not |
| 84 | + * updated. |
| 85 | + */ |
| 86 | + if (stat(os_info.old_tablespaces[tblnum], &statBuf) != 0) |
| 87 | + { |
| 88 | + if (errno == ENOENT) |
| 89 | + report_status(PG_FATAL, |
| 90 | + "tablespace directory \"%s\" does not exist\n", |
| 91 | + os_info.old_tablespaces[tblnum]); |
| 92 | + else |
| 93 | + report_status(PG_FATAL, |
| 94 | + "cannot stat() tablespace directory \"%s\": %s\n", |
| 95 | + os_info.old_tablespaces[tblnum], getErrorText(errno)); |
| 96 | + } |
| 97 | + if (!S_ISDIR(statBuf.st_mode)) |
| 98 | + report_status(PG_FATAL, |
| 99 | + "tablespace path \"%s\" is not a directory\n", |
| 100 | + os_info.old_tablespaces[tblnum]); |
| 101 | + } |
| 102 | + |
71 | 103 | PQclear(res);
|
72 | 104 |
|
73 | 105 | PQfinish(conn);
|
|
0 commit comments