Add DEBUG1-level logging of checkpoint start and end. Also, reduce the

'recycled log files' and 'removed log files' messages from DEBUG1 to
DEBUG2, replacing them with a count of files added/removed/recycled in
the checkpoint end message, as per suggestion from Simon Riggs.
This commit is contained in:
Tom Lane 2004-10-29 00:16:08 +00:00
parent fe2bfa6332
commit ee69be44d5
1 changed files with 34 additions and 10 deletions

View File

@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.174 2004/10/14 20:23:43 momjian Exp $ * $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.175 2004/10/29 00:16:08 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -442,8 +442,9 @@ static int XLogFileOpen(uint32 log, uint32 seg);
static int XLogFileRead(uint32 log, uint32 seg, int emode); static int XLogFileRead(uint32 log, uint32 seg, int emode);
static bool RestoreArchivedFile(char *path, const char *xlogfname, static bool RestoreArchivedFile(char *path, const char *xlogfname,
const char *recovername, off_t expectedSize); const char *recovername, off_t expectedSize);
static void PreallocXlogFiles(XLogRecPtr endptr); static int PreallocXlogFiles(XLogRecPtr endptr);
static void MoveOfflineLogs(uint32 log, uint32 seg, XLogRecPtr endptr); static void MoveOfflineLogs(uint32 log, uint32 seg, XLogRecPtr endptr,
int *nsegsremoved, int *nsegsrecycled);
static XLogRecord *ReadRecord(XLogRecPtr *RecPtr, int emode); static XLogRecord *ReadRecord(XLogRecPtr *RecPtr, int emode);
static bool ValidXLOGHeader(XLogPageHeader hdr, int emode); static bool ValidXLOGHeader(XLogPageHeader hdr, int emode);
static XLogRecord *ReadCheckpointRecord(XLogRecPtr RecPtr, int whichChkpt); static XLogRecord *ReadCheckpointRecord(XLogRecPtr RecPtr, int whichChkpt);
@ -2067,9 +2068,10 @@ RestoreArchivedFile(char *path, const char *xlogfname,
* Preallocate log files beyond the specified log endpoint, according to * Preallocate log files beyond the specified log endpoint, according to
* the XLOGfile user parameter. * the XLOGfile user parameter.
*/ */
static void static int
PreallocXlogFiles(XLogRecPtr endptr) PreallocXlogFiles(XLogRecPtr endptr)
{ {
int nsegsadded = 0;
uint32 _logId; uint32 _logId;
uint32 _logSeg; uint32 _logSeg;
int lf; int lf;
@ -2083,7 +2085,10 @@ PreallocXlogFiles(XLogRecPtr endptr)
use_existent = true; use_existent = true;
lf = XLogFileInit(_logId, _logSeg, &use_existent, true); lf = XLogFileInit(_logId, _logSeg, &use_existent, true);
close(lf); close(lf);
if (!use_existent)
nsegsadded++;
} }
return nsegsadded;
} }
/* /*
@ -2093,7 +2098,8 @@ PreallocXlogFiles(XLogRecPtr endptr)
* whether we want to recycle rather than delete no-longer-wanted log files. * whether we want to recycle rather than delete no-longer-wanted log files.
*/ */
static void static void
MoveOfflineLogs(uint32 log, uint32 seg, XLogRecPtr endptr) MoveOfflineLogs(uint32 log, uint32 seg, XLogRecPtr endptr,
int *nsegsremoved, int *nsegsrecycled)
{ {
uint32 endlogId; uint32 endlogId;
uint32 endlogSeg; uint32 endlogSeg;
@ -2102,6 +2108,9 @@ MoveOfflineLogs(uint32 log, uint32 seg, XLogRecPtr endptr)
char lastoff[MAXFNAMELEN]; char lastoff[MAXFNAMELEN];
char path[MAXPGPATH]; char path[MAXPGPATH];
*nsegsremoved = 0;
*nsegsrecycled = 0;
XLByteToPrevSeg(endptr, endlogId, endlogSeg); XLByteToPrevSeg(endptr, endlogId, endlogSeg);
xldir = AllocateDir(XLogDir); xldir = AllocateDir(XLogDir);
@ -2152,17 +2161,19 @@ MoveOfflineLogs(uint32 log, uint32 seg, XLogRecPtr endptr)
true, XLOGfileslop, true, XLOGfileslop,
true)) true))
{ {
ereport(DEBUG1, ereport(DEBUG2,
(errmsg("recycled transaction log file \"%s\"", (errmsg("recycled transaction log file \"%s\"",
xlde->d_name))); xlde->d_name)));
(*nsegsrecycled)++;
} }
else else
{ {
/* No need for any more future segments... */ /* No need for any more future segments... */
ereport(DEBUG1, ereport(DEBUG2,
(errmsg("removing transaction log file \"%s\"", (errmsg("removing transaction log file \"%s\"",
xlde->d_name))); xlde->d_name)));
unlink(path); unlink(path);
(*nsegsremoved)++;
} }
XLogArchiveCleanup(xlde->d_name); XLogArchiveCleanup(xlde->d_name);
@ -4470,7 +4481,7 @@ StartupXLOG(void)
/* /*
* Preallocate additional log files, if wanted. * Preallocate additional log files, if wanted.
*/ */
PreallocXlogFiles(EndOfLog); (void) PreallocXlogFiles(EndOfLog);
/* /*
* Okay, we're officially UP. * Okay, we're officially UP.
@ -4694,6 +4705,9 @@ CreateCheckPoint(bool shutdown, bool force)
uint32 freespace; uint32 freespace;
uint32 _logId; uint32 _logId;
uint32 _logSeg; uint32 _logSeg;
int nsegsadded = 0;
int nsegsremoved = 0;
int nsegsrecycled = 0;
/* /*
* Acquire CheckpointLock to ensure only one checkpoint happens at a * Acquire CheckpointLock to ensure only one checkpoint happens at a
@ -4861,6 +4875,10 @@ CreateCheckPoint(bool shutdown, bool force)
*/ */
END_CRIT_SECTION(); END_CRIT_SECTION();
if (!shutdown)
ereport(DEBUG1,
(errmsg("checkpoint starting")));
CheckPointCLOG(); CheckPointCLOG();
CheckPointSUBTRANS(); CheckPointSUBTRANS();
FlushBufferPool(); FlushBufferPool();
@ -4936,7 +4954,8 @@ CreateCheckPoint(bool shutdown, bool force)
if (_logId || _logSeg) if (_logId || _logSeg)
{ {
PrevLogSeg(_logId, _logSeg); PrevLogSeg(_logId, _logSeg);
MoveOfflineLogs(_logId, _logSeg, recptr); MoveOfflineLogs(_logId, _logSeg, recptr,
&nsegsremoved, &nsegsrecycled);
} }
/* /*
@ -4945,7 +4964,7 @@ CreateCheckPoint(bool shutdown, bool force)
* necessary.) * necessary.)
*/ */
if (!shutdown) if (!shutdown)
PreallocXlogFiles(recptr); nsegsadded = PreallocXlogFiles(recptr);
/* /*
* Truncate pg_subtrans if possible. We can throw away all data * Truncate pg_subtrans if possible. We can throw away all data
@ -4957,6 +4976,11 @@ CreateCheckPoint(bool shutdown, bool force)
if (!InRecovery) if (!InRecovery)
TruncateSUBTRANS(GetOldestXmin(true)); TruncateSUBTRANS(GetOldestXmin(true));
if (!shutdown)
ereport(DEBUG1,
(errmsg("checkpoint complete; %d transaction log file(s) added, %d removed, %d recycled",
nsegsadded, nsegsremoved, nsegsrecycled)));
LWLockRelease(CheckpointLock); LWLockRelease(CheckpointLock);
} }