40
40
*
41
41
*
42
42
* 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 $
44
44
*
45
45
*-------------------------------------------------------------------------
46
46
*/
@@ -562,6 +562,25 @@ create_tablespace_directories(const char *location, const Oid tablespaceoid)
562
562
location )));
563
563
}
564
564
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
+
565
584
/*
566
585
* The creation of the version directory prevents more than one tablespace
567
586
* in a single location.
@@ -580,6 +599,16 @@ create_tablespace_directories(const char *location, const Oid tablespaceoid)
580
599
location_with_version_dir )));
581
600
}
582
601
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
+
583
612
/*
584
613
* Create the symlink under PGDATA
585
614
*/
0 commit comments