diff -rpcd a/src/backend/commands/tablespace.c b/src/backend/commands/tablespace.c *** a/src/backend/commands/tablespace.c 2014-03-21 05:17:03.000000000 +0900 --- b/src/backend/commands/tablespace.c 2014-03-21 17:26:38.348000000 +0900 *************** create_tablespace_directories(const char *** 559,564 **** --- 559,565 ---- { char *linkloc; char *location_with_version_dir; + struct stat st; linkloc = psprintf("pg_tblspc/%u", tablespaceoid); location_with_version_dir = psprintf("%s/%s", location, *************** create_tablespace_directories(const char *** 620,633 **** location_with_version_dir))); } ! /* Remove old symlink in recovery, in case it points to the wrong place */ if (InRecovery) { ! if (unlink(linkloc) < 0 && errno != ENOENT) ! ereport(ERROR, ! (errcode_for_file_access(), ! errmsg("could not remove symbolic link \"%s\": %m", ! linkloc))); } /* --- 621,651 ---- location_with_version_dir))); } ! /* ! * Remove old symlink in recovery, in case it points to the wrong place. ! * We must however deal with the possibility that it's a directory ! * instead of a symlink --- this could happen during WAL replay, and ! * it is also the case on Windows where junction points lstat() as ! * directories. ! */ if (InRecovery) { ! 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))); ! } } /*