From dd7bc3cf859497b6c48874c23899fc0bf8d577a8 Mon Sep 17 00:00:00 2001 From: Heikki Linnakangas Date: Tue, 2 Jun 2009 06:18:06 +0000 Subject: [PATCH] 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. --- src/backend/access/transam/xlog.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index 64e8ead74c..645baed4b6 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -3006,6 +3006,7 @@ RemoveOldXlogFiles(uint32 log, uint32 seg, XLogRecPtr endptr) struct dirent *xlde; char lastoff[MAXFNAMELEN]; char path[MAXPGPATH]; + struct stat statbuf; /* * Initialize info about where to try to recycle to. We allow recycling @@ -3046,11 +3047,13 @@ RemoveOldXlogFiles(uint32 log, uint32 seg, XLogRecPtr endptr) /* * Before deleting the file, see if it can be recycled as a - * future log segment. + * future log segment. Only recycle normal files, pg_standby + * for example can create symbolic links pointing to a + * separate archive directory. */ - if (InstallXLogFileSegment(&endlogId, &endlogSeg, path, - true, &max_advance, - true)) + if (lstat(path, &statbuf) == 0 && S_ISREG(statbuf.st_mode) && + InstallXLogFileSegment(&endlogId, &endlogSeg, path, + true, &max_advance, true)) { ereport(DEBUG2, (errmsg("recycled transaction log file \"%s\"", -- 2.39.5