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 intXLogFileOpen(uint32 log, uint32 seg);
442442static int XLogFileRead (uint32 log ,uint32 seg ,int emode );
443443static bool RestoreArchivedFile (char * path ,const char * xlogfname ,
444444const 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 );
447448static XLogRecord * ReadRecord (XLogRecPtr * RecPtr ,int emode );
448449static bool ValidXLOGHeader (XLogPageHeader hdr ,int emode );
449450static 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
20712072PreallocXlogFiles (XLogRecPtr endptr )
20722073{
2074+ int nsegsadded = 0 ;
20732075uint32 _logId ;
20742076uint32 _logSeg ;
20752077int lf ;
@@ -2083,7 +2085,10 @@ PreallocXlogFiles(XLogRecPtr endptr)
20832085use_existent = true;
20842086lf = XLogFileInit (_logId ,_logSeg ,& use_existent , true);
20852087close (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 */
20952100static void
2096- MoveOfflineLogs (uint32 log ,uint32 seg ,XLogRecPtr endptr )
2101+ MoveOfflineLogs (uint32 log ,uint32 seg ,XLogRecPtr endptr ,
2102+ int * nsegsremoved ,int * nsegsrecycled )
20972103{
20982104uint32 endlogId ;
20992105uint32 endlogSeg ;
@@ -2102,6 +2108,9 @@ MoveOfflineLogs(uint32 log, uint32 seg, XLogRecPtr endptr)
21022108char lastoff [MAXFNAMELEN ];
21032109char path [MAXPGPATH ];
21042110
2111+ * nsegsremoved = 0 ;
2112+ * nsegsrecycled = 0 ;
2113+
21052114XLByteToPrevSeg (endptr ,endlogId ,endlogSeg );
21062115
21072116xldir = 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\"" ,
21572166xlde -> d_name )));
2167+ (* nsegsrecycled )++ ;
21582168}
21592169else
21602170{
21612171/* No need for any more future segments... */
2162- ereport (DEBUG1 ,
2172+ ereport (DEBUG2 ,
21632173 (errmsg ("removing transaction log file \"%s\"" ,
21642174xlde -> d_name )));
21652175unlink (path );
2176+ (* nsegsremoved )++ ;
21662177}
21672178
21682179XLogArchiveCleanup (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)
46944705uint32 freespace ;
46954706uint32 _logId ;
46964707uint32 _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 */
48624876END_CRIT_SECTION ();
48634877
4878+ if (!shutdown )
4879+ ereport (DEBUG1 ,
4880+ (errmsg ("checkpoint starting" )));
4881+
48644882CheckPointCLOG ();
48654883CheckPointSUBTRANS ();
48664884FlushBufferPool ();
@@ -4936,7 +4954,8 @@ CreateCheckPoint(bool shutdown, bool force)
49364954if (_logId || _logSeg )
49374955{
49384956PrevLogSeg (_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 */
49474966if (!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)
49574976if (!InRecovery )
49584977TruncateSUBTRANS (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+
49604984LWLockRelease (CheckpointLock );
49614985}
49624986