Skip to content

Commit 7c8d7a2

Browse files
committed
Only recycle normal files in pg_xlog as WAL segments. pg_standby creates
symbolic links with the -l option, and as Fujii Masao pointed out we ended up overwriting files in the archive directory before this patch. Patch by Aidan Van Dyk, Fujii Masao and me. Backpatch to 8.3, where pg_standby was introduced.
1 parent db02073 commit 7c8d7a2

File tree

1 file changed

+8
-5
lines changed
  • src/backend/access/transam

1 file changed

+8
-5
lines changed

src/backend/access/transam/xlog.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.341 2009/05/28 11:02:16 heikki Exp $
10+
* $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.342 2009/06/02 06:18:06 heikki Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -3006,6 +3006,7 @@ RemoveOldXlogFiles(uint32 log, uint32 seg, XLogRecPtr endptr)
30063006
struct dirent *xlde;
30073007
char lastoff[MAXFNAMELEN];
30083008
char path[MAXPGPATH];
3009+
struct stat statbuf;
30093010

30103011
/*
30113012
* Initialize info about where to try to recycle to. We allow recycling
@@ -3046,11 +3047,13 @@ RemoveOldXlogFiles(uint32 log, uint32 seg, XLogRecPtr endptr)
30463047

30473048
/*
30483049
* Before deleting the file, see if it can be recycled as a
3049-
* future log segment.
3050+
* future log segment. Only recycle normal files, pg_standby
3051+
* for example can create symbolic links pointing to a
3052+
* separate archive directory.
30503053
*/
3051-
if (InstallXLogFileSegment(&endlogId, &endlogSeg, path,
3052-
true, &max_advance,
3053-
true))
3054+
if (lstat(path, &statbuf) == 0 && S_ISREG(statbuf.st_mode) &&
3055+
InstallXLogFileSegment(&endlogId, &endlogSeg, path,
3056+
true, &max_advance, true))
30543057
{
30553058
ereport(DEBUG2,
30563059
(errmsg("recycled transaction log file \"%s\"",

0 commit comments

Comments
 (0)