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

Commit dd85acf

Browse files
committed
Make recovery rename tablespace_map to *.old if backup_label is not present.
If tablespace_map file is present without backup_label file, there is no use of such file. There is no harm in retaining it, but it is better to get rid of the map file so that we don't have any redundant file in data directory and it will avoid any sort of confusion. It seems prudent though to just rename the file out of the way rather than delete it completely, also we ignore any error that occurs in rename operation as even if map file is present without backup_label file, it is harmless. Back-patch to 9.5 where tablespace_map file was introduced. Amit Kapila, reviewed by Robert Haas, Alvaro Herrera and me.
1 parent 0e42397 commit dd85acf

File tree

1 file changed

+28
-0
lines changed
  • src/backend/access/transam

1 file changed

+28
-0
lines changed

src/backend/access/transam/xlog.c

+28
Original file line numberDiff line numberDiff line change
@@ -5912,6 +5912,7 @@ StartupXLOG(void)
59125912
XLogReaderState *xlogreader;
59135913
XLogPageReadPrivate private;
59145914
bool fast_promoted = false;
5915+
struct stat st;
59155916

59165917
/*
59175918
* Read control file and check XLOG status looks valid.
@@ -6138,6 +6139,33 @@ StartupXLOG(void)
61386139
}
61396140
else
61406141
{
6142+
/*
6143+
* If tablespace_map file is present without backup_label file, there
6144+
* is no use of such file. There is no harm in retaining it, but it
6145+
* is better to get rid of the map file so that we don't have any
6146+
* redundant file in data directory and it will avoid any sort of
6147+
* confusion. It seems prudent though to just rename the file out
6148+
* of the way rather than delete it completely, also we ignore any
6149+
* error that occurs in rename operation as even if map file is
6150+
* present without backup_label file, it is harmless.
6151+
*/
6152+
if (stat(TABLESPACE_MAP, &st) == 0)
6153+
{
6154+
unlink(TABLESPACE_MAP_OLD);
6155+
if (rename(TABLESPACE_MAP, TABLESPACE_MAP_OLD) == 0)
6156+
ereport(LOG,
6157+
(errmsg("ignoring \"%s\" file because no \"%s\" file exists",
6158+
TABLESPACE_MAP, BACKUP_LABEL_FILE),
6159+
errdetail("\"%s\" was renamed to \"%s\".",
6160+
TABLESPACE_MAP, TABLESPACE_MAP_OLD)));
6161+
else
6162+
ereport(LOG,
6163+
(errmsg("ignoring \"%s\" file because no \"%s\" file exists",
6164+
TABLESPACE_MAP, BACKUP_LABEL_FILE),
6165+
errdetail("Could not rename file \"%s\" to \"%s\": %m.",
6166+
TABLESPACE_MAP, TABLESPACE_MAP_OLD)));
6167+
}
6168+
61416169
/*
61426170
* It's possible that archive recovery was requested, but we don't
61436171
* know how far we need to replay the WAL before we reach consistency.

0 commit comments

Comments
 (0)