Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit c1275cf

Browse files
committed
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.
1 parent 52e7574 commit c1275cf

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

contrib/pg_upgrade/tablespace.c

+32
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
#include "pg_upgrade.h"
1313

14+
#include <sys/types.h>
15+
1416
static void get_tablespace_paths(void);
1517
static void set_tablespace_directory_suffix(ClusterInfo *cluster);
1618

@@ -65,9 +67,39 @@ get_tablespace_paths(void)
6567
i_spclocation = PQfnumber(res, "spclocation");
6668

6769
for (tblnum = 0; tblnum < os_info.num_old_tablespaces; tblnum++)
70+
{
71+
struct stat statBuf;
72+
6873
os_info.old_tablespaces[tblnum] = pg_strdup(
6974
PQgetvalue(res, tblnum, i_spclocation));
7075

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+
71103
PQclear(res);
72104

73105
PQfinish(conn);

0 commit comments

Comments
 (0)