Index: src/backend/access/transam/xlog.c =================================================================== RCS file: /cvsroot/pgsql/src/backend/access/transam/xlog.c,v retrieving revision 1.198 diff -c -c -r1.198 xlog.c *** src/backend/access/transam/xlog.c 8 Jun 2005 15:50:26 -0000 1.198 --- src/backend/access/transam/xlog.c 9 Jun 2005 14:52:11 -0000 *************** *** 450,455 **** --- 450,456 ---- static int PreallocXlogFiles(XLogRecPtr endptr); static void MoveOfflineLogs(uint32 log, uint32 seg, XLogRecPtr endptr, int *nsegsremoved, int *nsegsrecycled); + static void RemoveOldBackupHistory(void); static XLogRecord *ReadRecord(XLogRecPtr *RecPtr, int emode); static bool ValidXLOGHeader(XLogPageHeader hdr, int emode); static XLogRecord *ReadCheckpointRecord(XLogRecPtr RecPtr, int whichChkpt); *************** *** 2356,2361 **** --- 2357,2417 ---- } /* + * Remove previous backup history files + */ + static void + RemoveOldBackupHistory(void) + { + DIR *xldir; + struct dirent *xlde; + char path[MAXPGPATH]; + + xldir = AllocateDir(XLogDir); + if (xldir == NULL) + ereport(ERROR, + (errcode_for_file_access(), + errmsg("could not open transaction log directory \"%s\": %m", + XLogDir))); + + errno = 0; + while ((xlde = readdir(xldir)) != NULL) + { + if (strlen(xlde->d_name) > 24 && + strspn(xlde->d_name, "0123456789ABCDEF") == 24 && + strcmp(xlde->d_name + strlen(xlde->d_name) - strlen(".backup"), + ".backup") == 0) + { + /* Remove any *.backup files that have been archived. */ + if (!XLogArchivingActive() || XLogArchiveIsDone(xlde->d_name)) + { + ereport(DEBUG2, + (errmsg("removing transaction log backup history file \"%s\"", + xlde->d_name))); + snprintf(path, MAXPGPATH, "%s/%s", XLogDir, xlde->d_name); + unlink(path); + XLogArchiveCleanup(xlde->d_name); + } + } + errno = 0; + } + #ifdef WIN32 + + /* + * This fix is in mingw cvs (runtime/mingwex/dirent.c rev 1.4), but + * not in released version + */ + if (GetLastError() == ERROR_NO_MORE_FILES) + errno = 0; + #endif + if (errno) + ereport(ERROR, + (errcode_for_file_access(), + errmsg("could not read transaction log directory \"%s\": %m", + XLogDir))); + FreeDir(xldir); + } + + /* * Restore the backup blocks present in an XLOG record, if any. * * We assume all of the record has been read into memory at *record. *************** *** 5737,5742 **** --- 5793,5800 ---- errmsg("could not remove file \"%s\": %m", labelfilepath))); + RemoveOldBackupHistory(); + /* * Notify archiver that history file may be archived immediately */