aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2014-04-04 23:09:38 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2014-04-04 23:09:38 -0400
commit84520f91ccec4d204ffae92af039544eb3541c39 (patch)
treeaae80bb0a12b74b42820a09c7ea879a779b706c9 /src
parent7d1a0f585c233e0e316d99667f97f7af80069837 (diff)
downloadpostgresql-84520f91ccec4d204ffae92af039544eb3541c39.tar.gz
postgresql-84520f91ccec4d204ffae92af039544eb3541c39.zip
Fix tablespace creation WAL replay to work on Windows.
The code segment that removes the old symlink (if present) wasn't clued into the fact that on Windows, symlinks are junction points which have to be removed with rmdir(). Backpatch to 9.0, where the failing code was introduced. MauMau, reviewed by Muhammad Asif Naeem and Amit Kapila
Diffstat (limited to 'src')
-rw-r--r--src/backend/commands/tablespace.c33
1 files changed, 25 insertions, 8 deletions
diff --git a/src/backend/commands/tablespace.c b/src/backend/commands/tablespace.c
index 9be02c1a1ae..ef6df0039ca 100644
--- a/src/backend/commands/tablespace.c
+++ b/src/backend/commands/tablespace.c
@@ -544,6 +544,7 @@ create_tablespace_directories(const char *location, const Oid tablespaceoid)
char *linkloc = palloc(OIDCHARS + OIDCHARS + 1);
char *location_with_version_dir = palloc(strlen(location) + 1 +
strlen(TABLESPACE_VERSION_DIRECTORY) + 1);
+ struct stat st;
sprintf(linkloc, "pg_tblspc/%u", tablespaceoid);
sprintf(location_with_version_dir, "%s/%s", location,
@@ -570,8 +571,6 @@ create_tablespace_directories(const char *location, const Oid tablespaceoid)
if (InRecovery)
{
- struct stat st;
-
/*
* Our theory for replaying a CREATE is to forcibly drop the target
* subdirectory if present, and then recreate it. This may be more
@@ -605,14 +604,32 @@ create_tablespace_directories(const char *location, const Oid tablespaceoid)
location_with_version_dir)));
}
- /* Remove old symlink in recovery, in case it points to the wrong place */
+ /*
+ * In recovery, remove old symlink, in case it points to the wrong place.
+ *
+ * On Windows, junction points act like directories so we must be able to
+ * apply rmdir; in general it seems best to make this code work like the
+ * symlink removal code in destroy_tablespace_directories, except that
+ * failure to remove is always an ERROR.
+ */
if (InRecovery)
{
- if (unlink(linkloc) < 0 && errno != ENOENT)
- ereport(ERROR,
- (errcode_for_file_access(),
- errmsg("could not remove symbolic link \"%s\": %m",
- linkloc)));
+ if (lstat(linkloc, &st) == 0 && S_ISDIR(st.st_mode))
+ {
+ if (rmdir(linkloc) < 0)
+ ereport(ERROR,
+ (errcode_for_file_access(),
+ errmsg("could not remove directory \"%s\": %m",
+ linkloc)));
+ }
+ else
+ {
+ if (unlink(linkloc) < 0 && errno != ENOENT)
+ ereport(ERROR,
+ (errcode_for_file_access(),
+ errmsg("could not remove symbolic link \"%s\": %m",
+ linkloc)));
+ }
}
/*