4040 *
4141 *
4242 * IDENTIFICATION
43- * $PostgreSQL: pgsql/src/backend/commands/tablespace.c,v 1.77 2010/07/18 04:47:46 momjian Exp $
43+ * $PostgreSQL: pgsql/src/backend/commands/tablespace.c,v 1.78 2010/07/20 18:14:16 momjian Exp $
4444 *
4545 *-------------------------------------------------------------------------
4646 */
@@ -562,6 +562,25 @@ create_tablespace_directories(const char *location, const Oid tablespaceoid)
562562location )));
563563}
564564
565+ if (InRecovery )
566+ {
567+ struct stat st ;
568+
569+ /*
570+ * Our theory for replaying a CREATE is to forcibly drop the target
571+ * subdirectory if present, and then recreate it. This may be
572+ * more work than needed, but it is simple to implement.
573+ */
574+ if (stat (location_with_version_dir ,& st )== 0 && S_ISDIR (st .st_mode ))
575+ {
576+ if (!rmtree (location_with_version_dir , true))
577+ /* If this failed, mkdir() below is going to error. */
578+ ereport (WARNING ,
579+ (errmsg ("some useless files may be left behind in old database directory \"%s\"" ,
580+ location_with_version_dir )));
581+ }
582+ }
583+
565584/*
566585 * The creation of the version directory prevents more than one tablespace
567586 * in a single location.
@@ -580,6 +599,16 @@ create_tablespace_directories(const char *location, const Oid tablespaceoid)
580599location_with_version_dir )));
581600}
582601
602+ /* Remove old symlink in recovery, in case it points to the wrong place */
603+ if (InRecovery )
604+ {
605+ if (unlink (linkloc )< 0 && errno != ENOENT )
606+ ereport (ERROR ,
607+ (errcode_for_file_access (),
608+ errmsg ("could not remove symbolic link \"%s\": %m" ,
609+ linkloc )));
610+ }
611+
583612/*
584613 * Create the symlink under PGDATA
585614 */