*** pgsql/src/backend/postmaster/bgwriter.c 2009/01/01 17:23:46 1.55 --- pgsql/src/backend/postmaster/bgwriter.c 2009/02/18 15:58:41 1.56 *************** *** 37,43 **** * * * IDENTIFICATION ! * $PostgreSQL: pgsql/src/backend/postmaster/bgwriter.c,v 1.54 2008/11/23 01:40:19 tgl Exp $ * *------------------------------------------------------------------------- */ --- 37,43 ---- * * * IDENTIFICATION ! * $PostgreSQL: pgsql/src/backend/postmaster/bgwriter.c,v 1.55 2009/01/01 17:23:46 momjian Exp $ * *------------------------------------------------------------------------- */ *************** *** 49,54 **** --- 49,55 ---- #include #include "access/xlog_internal.h" + #include "catalog/pg_control.h" #include "libpq/pqsignal.h" #include "miscadmin.h" #include "pgstat.h" *************** BackgroundWriterMain(void) *** 423,432 **** --- 424,443 ---- */ if (do_checkpoint) { + bool ckpt_performed = false; + bool do_restartpoint; + /* use volatile pointer to prevent code rearrangement */ volatile BgWriterShmemStruct *bgs = BgWriterShmem; /* + * Check if we should perform a checkpoint or a restartpoint. + * As a side-effect, RecoveryInProgress() initializes + * TimeLineID if it's not set yet. + */ + do_restartpoint = RecoveryInProgress(); + + /* * Atomically fetch the request flags to figure out what kind of a * checkpoint we should perform, and increase the started-counter * to acknowledge that we've started a new checkpoint. *************** BackgroundWriterMain(void) *** 444,450 **** * implementation will not generate warnings caused by * CheckPointTimeout < CheckPointWarning. */ ! if ((flags & CHECKPOINT_CAUSE_XLOG) && elapsed_secs < CheckPointWarning) ereport(LOG, (errmsg("checkpoints are occurring too frequently (%d seconds apart)", --- 455,462 ---- * implementation will not generate warnings caused by * CheckPointTimeout < CheckPointWarning. */ ! if (!do_restartpoint && ! (flags & CHECKPOINT_CAUSE_XLOG) && elapsed_secs < CheckPointWarning) ereport(LOG, (errmsg("checkpoints are occurring too frequently (%d seconds apart)", *************** BackgroundWriterMain(void) *** 455,468 **** * Initialize bgwriter-private variables used during checkpoint. */ ckpt_active = true; ! ckpt_start_recptr = GetInsertRecPtr(); ckpt_start_time = now; ckpt_cached_elapsed = 0; /* * Do the checkpoint. */ ! CreateCheckPoint(flags); /* * After any checkpoint, close all smgr files. This is so we --- 467,487 ---- * Initialize bgwriter-private variables used during checkpoint. */ ckpt_active = true; ! if (!do_restartpoint) ! ckpt_start_recptr = GetInsertRecPtr(); ckpt_start_time = now; ckpt_cached_elapsed = 0; /* * Do the checkpoint. */ ! if (!do_restartpoint) ! { ! CreateCheckPoint(flags); ! ckpt_performed = true; ! } ! else ! ckpt_performed = CreateRestartPoint(flags); /* * After any checkpoint, close all smgr files. This is so we *************** BackgroundWriterMain(void) *** 477,490 **** bgs->ckpt_done = bgs->ckpt_started; SpinLockRelease(&bgs->ckpt_lck); ! ckpt_active = false; ! /* ! * Note we record the checkpoint start time not end time as ! * last_checkpoint_time. This is so that time-driven checkpoints ! * happen at a predictable spacing. ! */ ! last_checkpoint_time = now; } else BgBufferSync(); --- 496,522 ---- bgs->ckpt_done = bgs->ckpt_started; SpinLockRelease(&bgs->ckpt_lck); ! if (ckpt_performed) ! { ! /* ! * Note we record the checkpoint start time not end time as ! * last_checkpoint_time. This is so that time-driven ! * checkpoints happen at a predictable spacing. ! */ ! last_checkpoint_time = now; ! } ! else ! { ! /* ! * We were not able to perform the restartpoint (checkpoints ! * throw an ERROR in case of error). Most likely because we ! * have not received any new checkpoint WAL records since the ! * last restartpoint. Try again in 15 s. ! */ ! last_checkpoint_time = now - CheckPointTimeout + 15; ! } ! ckpt_active = false; } else BgBufferSync(); *************** CheckArchiveTimeout(void) *** 507,513 **** pg_time_t now; pg_time_t last_time; ! if (XLogArchiveTimeout <= 0) return; now = (pg_time_t) time(NULL); --- 539,545 ---- pg_time_t now; pg_time_t last_time; ! if (XLogArchiveTimeout <= 0 || RecoveryInProgress()) return; now = (pg_time_t) time(NULL); *************** IsCheckpointOnSchedule(double progress) *** 714,729 **** * However, it's good enough for our purposes, we're only calculating an * estimate anyway. */ ! recptr = GetInsertRecPtr(); ! elapsed_xlogs = ! (((double) (int32) (recptr.xlogid - ckpt_start_recptr.xlogid)) * XLogSegsPerFile + ! ((double) recptr.xrecoff - (double) ckpt_start_recptr.xrecoff) / XLogSegSize) / ! CheckPointSegments; ! ! if (progress < elapsed_xlogs) { ! ckpt_cached_elapsed = elapsed_xlogs; ! return false; } /* --- 746,764 ---- * However, it's good enough for our purposes, we're only calculating an * estimate anyway. */ ! if (!RecoveryInProgress()) { ! recptr = GetInsertRecPtr(); ! elapsed_xlogs = ! (((double) (int32) (recptr.xlogid - ckpt_start_recptr.xlogid)) * XLogSegsPerFile + ! ((double) recptr.xrecoff - (double) ckpt_start_recptr.xrecoff) / XLogSegSize) / ! CheckPointSegments; ! ! if (progress < elapsed_xlogs) ! { ! ckpt_cached_elapsed = elapsed_xlogs; ! return false; ! } } /*