* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.237 2006/04/20 04:07:38 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.238 2006/06/15 19:15:00 momjian Exp $
*
*-------------------------------------------------------------------------
*/
bool use_lock);
static int XLogFileOpen(uint32 log, uint32 seg);
static int XLogFileRead(uint32 log, uint32 seg, int emode);
+static void XLogFileClose(void);
static bool RestoreArchivedFile(char *path, const char *xlogfname,
const char *recovername, off_t expectedSize);
static int PreallocXlogFiles(XLogRecPtr endptr);
*/
Assert(npages == 0);
if (openLogFile >= 0)
- {
- if (close(openLogFile))
- ereport(PANIC,
- (errcode_for_file_access(),
- errmsg("could not close log file %u, segment %u: %m",
- openLogId, openLogSeg)));
- openLogFile = -1;
- }
+ XLogFileClose();
XLByteToPrevSeg(LogwrtResult.Write, openLogId, openLogSeg);
/* create/use new log file */
{
if (openLogFile >= 0 &&
!XLByteInPrevSeg(LogwrtResult.Write, openLogId, openLogSeg))
- {
- if (close(openLogFile))
- ereport(PANIC,
- (errcode_for_file_access(),
- errmsg("could not close log file %u, segment %u: %m",
- openLogId, openLogSeg)));
- openLogFile = -1;
- }
+ XLogFileClose();
if (openLogFile < 0)
{
XLByteToPrevSeg(LogwrtResult.Write, openLogId, openLogSeg);
return -1;
}
+/*
+ * Close the current logfile segment for writing.
+ */
+static void
+XLogFileClose(void)
+{
+ Assert(openLogFile >= 0);
+
+#ifdef _POSIX_ADVISORY_INFO
+ /*
+ * WAL caches will not be accessed in the future, so we advise OS to
+ * free them. But we will not do so if WAL archiving is active,
+ * because archivers might use the caches to read the WAL segment.
+ * While O_DIRECT works for O_SYNC, posix_fadvise() works for fsync()
+ * and O_SYNC, and some platforms only have posix_fadvise().
+ */
+ if (!XLogArchivingActive())
+ posix_fadvise(openLogFile, 0, 0, POSIX_FADV_DONTNEED);
+#endif
+
+ if (close(openLogFile))
+ ereport(PANIC,
+ (errcode_for_file_access(),
+ errmsg("could not close log file %u, segment %u: %m",
+ openLogId, openLogSeg)));
+ openLogFile = -1;
+}
+
/*
* Attempt to retrieve the specified file from off-line archival storage.
* If successful, fill "path" with its complete path (note that this will be
errmsg("could not fsync log file %u, segment %u: %m",
openLogId, openLogSeg)));
if (open_sync_bit != new_sync_bit)
- {
- if (close(openLogFile))
- ereport(PANIC,
- (errcode_for_file_access(),
- errmsg("could not close log file %u, segment %u: %m",
- openLogId, openLogSeg)));
- openLogFile = -1;
- }
+ XLogFileClose();
}
sync_method = new_sync_method;
open_sync_bit = new_sync_bit;