diff -cpr pgsql-orig/src/backend/access/transam/xlog.c pgsql/src/backend/access/transam/xlog.c *** pgsql-orig/src/backend/access/transam/xlog.c 2006-01-13 01:27:29.000000000 +0900 --- pgsql/src/backend/access/transam/xlog.c 2006-01-13 01:31:56.000000000 +0900 *************** static bool InstallXLogFileSegment(uint3 *** 477,482 **** --- 477,483 ---- 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); *************** XLogWrite(XLogwrtRqst WriteRqst, bool fl *** 1348,1359 **** 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; } XLByteToPrevSeg(LogwrtResult.Write, openLogId, openLogSeg); --- 1349,1355 ---- Assert(npages == 0); if (openLogFile >= 0) { ! XLogFileClose(); } XLByteToPrevSeg(LogwrtResult.Write, openLogId, openLogSeg); *************** XLogWrite(XLogwrtRqst WriteRqst, bool fl *** 1531,1542 **** 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; } if (openLogFile < 0) { --- 1527,1533 ---- if (openLogFile >= 0 && !XLByteInPrevSeg(LogwrtResult.Write, openLogId, openLogSeg)) { ! XLogFileClose(); } if (openLogFile < 0) { *************** XLogFileRead(uint32 log, uint32 seg, int *** 2116,2121 **** --- 2107,2138 ---- } /* + * Close the current logfile segment for writing. + */ + static void + XLogFileClose(void) + { + Assert(openLogFile >= 0); + + #if _POSIX_ADVISORY_INFO >= 0 + /* + * 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. + */ + 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 * a temp file name that doesn't follow the normal naming convention), and *************** assign_xlog_sync_method(const char *meth *** 5523,5534 **** 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; } } sync_method = new_sync_method; --- 5540,5546 ---- openLogId, openLogSeg))); if (open_sync_bit != new_sync_bit) { ! XLogFileClose(); } } sync_method = new_sync_method;