Skip to content

Commit ee69be4

Browse files
committed
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.
1 parent fe2bfa6 commit ee69be4

File tree

1 file changed

+34
-10
lines changed
  • src/backend/access/transam

1 file changed

+34
-10
lines changed

src/backend/access/transam/xlog.c

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.174 2004/10/14 20:23:43 momjian Exp $
10+
* $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.175 2004/10/29 00:16:08 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -442,8 +442,9 @@ static int XLogFileOpen(uint32 log, uint32 seg);
442442
static int XLogFileRead(uint32 log, uint32 seg, int emode);
443443
static bool RestoreArchivedFile(char *path, const char *xlogfname,
444444
const char *recovername, off_t expectedSize);
445-
static void PreallocXlogFiles(XLogRecPtr endptr);
446-
static void MoveOfflineLogs(uint32 log, uint32 seg, XLogRecPtr endptr);
445+
static int PreallocXlogFiles(XLogRecPtr endptr);
446+
static void MoveOfflineLogs(uint32 log, uint32 seg, XLogRecPtr endptr,
447+
int *nsegsremoved, int *nsegsrecycled);
447448
static XLogRecord *ReadRecord(XLogRecPtr *RecPtr, int emode);
448449
static bool ValidXLOGHeader(XLogPageHeader hdr, int emode);
449450
static XLogRecord *ReadCheckpointRecord(XLogRecPtr RecPtr, int whichChkpt);
@@ -2067,9 +2068,10 @@ RestoreArchivedFile(char *path, const char *xlogfname,
20672068
* Preallocate log files beyond the specified log endpoint, according to
20682069
* the XLOGfile user parameter.
20692070
*/
2070-
static void
2071+
static int
20712072
PreallocXlogFiles(XLogRecPtr endptr)
20722073
{
2074+
int nsegsadded = 0;
20732075
uint32 _logId;
20742076
uint32 _logSeg;
20752077
int lf;
@@ -2083,7 +2085,10 @@ PreallocXlogFiles(XLogRecPtr endptr)
20832085
use_existent = true;
20842086
lf = XLogFileInit(_logId, _logSeg, &use_existent, true);
20852087
close(lf);
2088+
if (!use_existent)
2089+
nsegsadded++;
20862090
}
2091+
return nsegsadded;
20872092
}
20882093

20892094
/*
@@ -2093,7 +2098,8 @@ PreallocXlogFiles(XLogRecPtr endptr)
20932098
* whether we want to recycle rather than delete no-longer-wanted log files.
20942099
*/
20952100
static void
2096-
MoveOfflineLogs(uint32 log, uint32 seg, XLogRecPtr endptr)
2101+
MoveOfflineLogs(uint32 log, uint32 seg, XLogRecPtr endptr,
2102+
int *nsegsremoved, int *nsegsrecycled)
20972103
{
20982104
uint32 endlogId;
20992105
uint32 endlogSeg;
@@ -2102,6 +2108,9 @@ MoveOfflineLogs(uint32 log, uint32 seg, XLogRecPtr endptr)
21022108
char lastoff[MAXFNAMELEN];
21032109
char path[MAXPGPATH];
21042110

2111+
*nsegsremoved = 0;
2112+
*nsegsrecycled = 0;
2113+
21052114
XLByteToPrevSeg(endptr, endlogId, endlogSeg);
21062115

21072116
xldir = AllocateDir(XLogDir);
@@ -2152,17 +2161,19 @@ MoveOfflineLogs(uint32 log, uint32 seg, XLogRecPtr endptr)
21522161
true, XLOGfileslop,
21532162
true))
21542163
{
2155-
ereport(DEBUG1,
2164+
ereport(DEBUG2,
21562165
(errmsg("recycled transaction log file \"%s\"",
21572166
xlde->d_name)));
2167+
(*nsegsrecycled)++;
21582168
}
21592169
else
21602170
{
21612171
/* No need for any more future segments... */
2162-
ereport(DEBUG1,
2172+
ereport(DEBUG2,
21632173
(errmsg("removing transaction log file \"%s\"",
21642174
xlde->d_name)));
21652175
unlink(path);
2176+
(*nsegsremoved)++;
21662177
}
21672178

21682179
XLogArchiveCleanup(xlde->d_name);
@@ -4470,7 +4481,7 @@ StartupXLOG(void)
44704481
/*
44714482
* Preallocate additional log files, if wanted.
44724483
*/
4473-
PreallocXlogFiles(EndOfLog);
4484+
(void) PreallocXlogFiles(EndOfLog);
44744485

44754486
/*
44764487
* Okay, we're officially UP.
@@ -4694,6 +4705,9 @@ CreateCheckPoint(bool shutdown, bool force)
46944705
uint32 freespace;
46954706
uint32 _logId;
46964707
uint32 _logSeg;
4708+
int nsegsadded = 0;
4709+
int nsegsremoved = 0;
4710+
int nsegsrecycled = 0;
46974711

46984712
/*
46994713
* Acquire CheckpointLock to ensure only one checkpoint happens at a
@@ -4861,6 +4875,10 @@ CreateCheckPoint(bool shutdown, bool force)
48614875
*/
48624876
END_CRIT_SECTION();
48634877

4878+
if (!shutdown)
4879+
ereport(DEBUG1,
4880+
(errmsg("checkpoint starting")));
4881+
48644882
CheckPointCLOG();
48654883
CheckPointSUBTRANS();
48664884
FlushBufferPool();
@@ -4936,7 +4954,8 @@ CreateCheckPoint(bool shutdown, bool force)
49364954
if (_logId || _logSeg)
49374955
{
49384956
PrevLogSeg(_logId, _logSeg);
4939-
MoveOfflineLogs(_logId, _logSeg, recptr);
4957+
MoveOfflineLogs(_logId, _logSeg, recptr,
4958+
&nsegsremoved, &nsegsrecycled);
49404959
}
49414960

49424961
/*
@@ -4945,7 +4964,7 @@ CreateCheckPoint(bool shutdown, bool force)
49454964
* necessary.)
49464965
*/
49474966
if (!shutdown)
4948-
PreallocXlogFiles(recptr);
4967+
nsegsadded = PreallocXlogFiles(recptr);
49494968

49504969
/*
49514970
* Truncate pg_subtrans if possible. We can throw away all data
@@ -4957,6 +4976,11 @@ CreateCheckPoint(bool shutdown, bool force)
49574976
if (!InRecovery)
49584977
TruncateSUBTRANS(GetOldestXmin(true));
49594978

4979+
if (!shutdown)
4980+
ereport(DEBUG1,
4981+
(errmsg("checkpoint complete; %d transaction log file(s) added, %d removed, %d recycled",
4982+
nsegsadded, nsegsremoved, nsegsrecycled)));
4983+
49604984
LWLockRelease(CheckpointLock);
49614985
}
49624986

0 commit comments

Comments
 (0)