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

Commit c86f467

Browse files
committed
Properly replay CREATE TABLESPACE during crash recovery by deleting
directory/symlink before creation. Report from Tom Lane. Backpatch to 9.0.
1 parent 8ceb68b commit c86f467

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

src/backend/commands/dbcommands.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*
1414
*
1515
* IDENTIFICATION
16-
* $PostgreSQL: pgsql/src/backend/commands/dbcommands.c,v 1.235 2010/02/26 02:00:38 momjian Exp $
16+
* $PostgreSQL: pgsql/src/backend/commands/dbcommands.c,v 1.236 2010/07/20 18:14:16 momjian Exp $
1717
*
1818
*-------------------------------------------------------------------------
1919
*/
@@ -1908,6 +1908,7 @@ dbase_redo(XLogRecPtr lsn, XLogRecord *record)
19081908
if (stat(dst_path, &st) == 0 && S_ISDIR(st.st_mode))
19091909
{
19101910
if (!rmtree(dst_path, true))
1911+
/* If this failed, copydir() below is going to error. */
19111912
ereport(WARNING,
19121913
(errmsg("some useless files may be left behind in old database directory \"%s\"",
19131914
dst_path)));

src/backend/commands/tablespace.c

+30-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
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)
562562
location)));
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)
580599
location_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
*/

0 commit comments

Comments
 (0)