|
7 | 7 | * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
|
8 | 8 | * Portions Copyright (c) 1994, Regents of the University of California
|
9 | 9 | *
|
10 |
| - * $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.199 2005/06/09 22:36:27 momjian Exp $ |
| 10 | + * $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.200 2005/06/15 01:36:08 momjian Exp $ |
11 | 11 | *
|
12 | 12 | *-------------------------------------------------------------------------
|
13 | 13 | */
|
@@ -450,6 +450,7 @@ static bool RestoreArchivedFile(char *path, const char *xlogfname,
|
450 | 450 | staticintPreallocXlogFiles(XLogRecPtrendptr);
|
451 | 451 | staticvoidMoveOfflineLogs(uint32log,uint32seg,XLogRecPtrendptr,
|
452 | 452 | int*nsegsremoved,int*nsegsrecycled);
|
| 453 | +staticvoidRemoveOldBackupHistory(void); |
453 | 454 | staticXLogRecord*ReadRecord(XLogRecPtr*RecPtr,intemode);
|
454 | 455 | staticboolValidXLOGHeader(XLogPageHeaderhdr,intemode);
|
455 | 456 | staticXLogRecord*ReadCheckpointRecord(XLogRecPtrRecPtr,intwhichChkpt);
|
@@ -2355,6 +2356,61 @@ MoveOfflineLogs(uint32 log, uint32 seg, XLogRecPtr endptr,
|
2355 | 2356 | FreeDir(xldir);
|
2356 | 2357 | }
|
2357 | 2358 |
|
| 2359 | +/* |
| 2360 | + * Remove previous backup history files |
| 2361 | + */ |
| 2362 | +staticvoid |
| 2363 | +RemoveOldBackupHistory(void) |
| 2364 | +{ |
| 2365 | +DIR*xldir; |
| 2366 | +structdirent*xlde; |
| 2367 | +charpath[MAXPGPATH]; |
| 2368 | + |
| 2369 | +xldir=AllocateDir(XLogDir); |
| 2370 | +if (xldir==NULL) |
| 2371 | +ereport(ERROR, |
| 2372 | +(errcode_for_file_access(), |
| 2373 | +errmsg("could not open transaction log directory \"%s\": %m", |
| 2374 | +XLogDir))); |
| 2375 | + |
| 2376 | +errno=0; |
| 2377 | +while ((xlde=readdir(xldir))!=NULL) |
| 2378 | +{ |
| 2379 | +if (strlen(xlde->d_name)>24&& |
| 2380 | +strspn(xlde->d_name,"0123456789ABCDEF")==24&& |
| 2381 | +strcmp(xlde->d_name+strlen(xlde->d_name)-strlen(".backup"), |
| 2382 | +".backup")==0) |
| 2383 | +{ |
| 2384 | +/* Remove any *.backup files that have been archived. */ |
| 2385 | +if (!XLogArchivingActive()||XLogArchiveIsDone(xlde->d_name)) |
| 2386 | +{ |
| 2387 | +ereport(DEBUG2, |
| 2388 | + (errmsg("removing transaction log backup history file \"%s\"", |
| 2389 | +xlde->d_name))); |
| 2390 | +snprintf(path,MAXPGPATH,"%s/%s",XLogDir,xlde->d_name); |
| 2391 | +unlink(path); |
| 2392 | +XLogArchiveCleanup(xlde->d_name); |
| 2393 | +} |
| 2394 | +} |
| 2395 | +errno=0; |
| 2396 | +} |
| 2397 | +#ifdefWIN32 |
| 2398 | + |
| 2399 | +/* |
| 2400 | + * This fix is in mingw cvs (runtime/mingwex/dirent.c rev 1.4), but |
| 2401 | + * not in released version |
| 2402 | + */ |
| 2403 | +if (GetLastError()==ERROR_NO_MORE_FILES) |
| 2404 | +errno=0; |
| 2405 | +#endif |
| 2406 | +if (errno) |
| 2407 | +ereport(ERROR, |
| 2408 | +(errcode_for_file_access(), |
| 2409 | +errmsg("could not read transaction log directory \"%s\": %m", |
| 2410 | +XLogDir))); |
| 2411 | +FreeDir(xldir); |
| 2412 | +} |
| 2413 | + |
2358 | 2414 | /*
|
2359 | 2415 | * Restore the backup blocks present in an XLOG record, if any.
|
2360 | 2416 | *
|
@@ -5738,6 +5794,8 @@ pg_stop_backup(PG_FUNCTION_ARGS)
|
5738 | 5794 | errmsg("could not remove file \"%s\": %m",
|
5739 | 5795 | labelfilepath)));
|
5740 | 5796 |
|
| 5797 | +RemoveOldBackupHistory(); |
| 5798 | + |
5741 | 5799 | /*
|
5742 | 5800 | * Notify archiver that history file may be archived immediately
|
5743 | 5801 | */
|
|