1010 * fill WAL segments; the checkpointer itself doesn't watch for the
1111 * condition.)
1212 *
13- * The checkpointer is started by the postmaster as soon as the startup subprocess
14- * finishes, or as soon as recovery begins if we are doing archive recovery.
15- * It remains alive until the postmaster commands it to terminate.
16- * Normal termination is by SIGUSR2, which instructs the checkpointer to execute
17- * a shutdown checkpoint and then exit(0). (All backends must be stopped
18- * before SIGUSR2 is issued!) Emergency termination is by SIGQUIT; like any
19- * backend, the checkpointer will simply abort and exit on SIGQUIT.
13+ * The checkpointer is started by the postmaster as soon as the startup
14+ *subprocess finishes, or as soon as recovery begins if we are doing archive
15+ *recovery. It remains alive until the postmaster commands it to terminate.
16+ * Normal termination is by SIGUSR2, which instructs the checkpointer to
17+ *execute a shutdown checkpoint and then exit(0). (All backends must be
18+ *stopped before SIGUSR2 is issued!) Emergency termination is by SIGQUIT;
19+ *like any backend, the checkpointer will simply abort and exit on SIGQUIT.
2020 *
2121 * If the checkpointer exits unexpectedly, the postmaster treats that the same
2222 * as a backend crash: shared memory may be corrupted, so remaining backends
6565 *
6666 * The ckpt counters allow backends to watch for completion of a checkpoint
6767 * request they send. Here's how it works:
68- ** At start of a checkpoint, checkpointer reads (and clears) the request flags
69- * and increments ckpt_started, while holding ckpt_lck.
68+ ** At start of a checkpoint, checkpointer reads (and clears) the request
69+ *flags and increments ckpt_started, while holding ckpt_lck.
7070 ** On completion of a checkpoint, checkpointer sets ckpt_done to
7171 * equal ckpt_started.
7272 ** On failure of a checkpoint, checkpointer increments ckpt_failed
9595 * by user backend processes. This counter should be wide enough that it
9696 * can't overflow during a single processing cycle. num_backend_fsync
9797 * counts the subset of those writes that also had to do their own fsync,
98- * because thebackground writer failed to absorb their request.
98+ * because thecheckpointer failed to absorb their request.
9999 *
100100 * The requests array holds fsync requests sent by backends and not yet
101101 * absorbed by the checkpointer.
@@ -200,8 +200,8 @@ CheckpointerMain(void)
200200
201201/*
202202 * If possible, make this process a group leader, so that the postmaster
203- * can signal any child processes too. (checkpointer probably never has any
204- * child processes, but for consistency we make all postmaster child
203+ * can signal any child processes too. (checkpointer probably never has
204+ *any child processes, but for consistency we make all postmaster child
205205 * processes do this.)
206206 */
207207#ifdef HAVE_SETSID
@@ -216,9 +216,6 @@ CheckpointerMain(void)
216216 * system shutdown cycle, init will SIGTERM all processes at once.We
217217 * want to wait for the backends to exit, whereupon the postmaster will
218218 * tell us it's okay to shut down (via SIGUSR2).
219- *
220- * SIGUSR1 is presently unused; keep it spare in case someday we want this
221- * process to participate in ProcSignal signalling.
222219 */
223220pqsignal (SIGHUP ,ChkptSigHupHandler );/* set flag to read config file */
224221pqsignal (SIGINT ,ReqCheckpointHandler );/* request checkpoint */
@@ -302,12 +299,12 @@ CheckpointerMain(void)
302299if (ckpt_active )
303300{
304301/* use volatile pointer to prevent code rearrangement */
305- volatile CheckpointerShmemStruct * bgs = CheckpointerShmem ;
302+ volatile CheckpointerShmemStruct * cps = CheckpointerShmem ;
306303
307- SpinLockAcquire (& bgs -> ckpt_lck );
308- bgs -> ckpt_failed ++ ;
309- bgs -> ckpt_done = bgs -> ckpt_started ;
310- SpinLockRelease (& bgs -> ckpt_lck );
304+ SpinLockAcquire (& cps -> ckpt_lck );
305+ cps -> ckpt_failed ++ ;
306+ cps -> ckpt_done = cps -> ckpt_started ;
307+ SpinLockRelease (& cps -> ckpt_lck );
311308
312309ckpt_active = false;
313310}
@@ -455,7 +452,7 @@ CheckpointerMain(void)
455452bool do_restartpoint ;
456453
457454/* use volatile pointer to prevent code rearrangement */
458- volatile CheckpointerShmemStruct * bgs = CheckpointerShmem ;
455+ volatile CheckpointerShmemStruct * cps = CheckpointerShmem ;
459456
460457/*
461458 * Check if we should perform a checkpoint or a restartpoint. As a
@@ -469,11 +466,11 @@ CheckpointerMain(void)
469466 * checkpoint we should perform, and increase the started-counter
470467 * to acknowledge that we've started a new checkpoint.
471468 */
472- SpinLockAcquire (& bgs -> ckpt_lck );
473- flags |=bgs -> ckpt_flags ;
474- bgs -> ckpt_flags = 0 ;
475- bgs -> ckpt_started ++ ;
476- SpinLockRelease (& bgs -> ckpt_lck );
469+ SpinLockAcquire (& cps -> ckpt_lck );
470+ flags |=cps -> ckpt_flags ;
471+ cps -> ckpt_flags = 0 ;
472+ cps -> ckpt_started ++ ;
473+ SpinLockRelease (& cps -> ckpt_lck );
477474
478475/*
479476 * The end-of-recovery checkpoint is a real checkpoint that's
@@ -528,9 +525,9 @@ CheckpointerMain(void)
528525/*
529526 * Indicate checkpoint completion to any waiting backends.
530527 */
531- SpinLockAcquire (& bgs -> ckpt_lck );
532- bgs -> ckpt_done = bgs -> ckpt_started ;
533- SpinLockRelease (& bgs -> ckpt_lck );
528+ SpinLockAcquire (& cps -> ckpt_lck );
529+ cps -> ckpt_done = cps -> ckpt_started ;
530+ SpinLockRelease (& cps -> ckpt_lck );
534531
535532if (ckpt_performed )
536533{
@@ -559,7 +556,11 @@ CheckpointerMain(void)
559556CheckArchiveTimeout ();
560557
561558/*
562- * Send off activity statistics to the stats collector
559+ * Send off activity statistics to the stats collector. (The reason
560+ * why we re-use bgwriter-related code for this is that the bgwriter
561+ * and checkpointer used to be just one process. It's probably not
562+ * worth the trouble to split the stats support into two independent
563+ * stats message types.)
563564 */
564565pgstat_send_bgwriter ();
565566
@@ -651,13 +652,13 @@ ImmediateCheckpointRequested(void)
651652{
652653if (checkpoint_requested )
653654{
654- volatile CheckpointerShmemStruct * bgs = CheckpointerShmem ;
655+ volatile CheckpointerShmemStruct * cps = CheckpointerShmem ;
655656
656657/*
657658 * We don't need to acquire the ckpt_lck in this case because we're
658659 * only looking at a single flag bit.
659660 */
660- if (bgs -> ckpt_flags & CHECKPOINT_IMMEDIATE )
661+ if (cps -> ckpt_flags & CHECKPOINT_IMMEDIATE )
661662return true;
662663}
663664return false;
@@ -698,7 +699,7 @@ CheckpointWriteDelay(int flags, double progress)
698699{
699700got_SIGHUP = false;
700701ProcessConfigFile (PGC_SIGHUP );
701- /* updateglobal shmemstate for sync rep */
702+ /* update shmemcopies of config variables */
702703UpdateSharedMemoryConfig ();
703704}
704705
@@ -708,7 +709,7 @@ CheckpointWriteDelay(int flags, double progress)
708709CheckArchiveTimeout ();
709710
710711/*
711- *Checkpoint sleep used to be connected to bgwriter_delay at 200ms.
712+ *This sleep used to be connected to bgwriter_delay, typically 200ms.
712713 * That resulted in more frequent wakeups if not much work to do.
713714 * Checkpointer and bgwriter are no longer related so take the Big Sleep.
714715 */
@@ -894,7 +895,7 @@ ReqShutdownHandler(SIGNAL_ARGS)
894895
895896/*
896897 * CheckpointerShmemSize
897- *Compute space needed forbgwriter -related shared memory
898+ *Compute space needed forcheckpointer -related shared memory
898899 */
899900Size
900901CheckpointerShmemSize (void )
@@ -913,15 +914,15 @@ CheckpointerShmemSize(void)
913914
914915/*
915916 * CheckpointerShmemInit
916- *Allocate and initializebgwriter -related shared memory
917+ *Allocate and initializecheckpointer -related shared memory
917918 */
918919void
919920CheckpointerShmemInit (void )
920921{
921922bool found ;
922923
923924CheckpointerShmem = (CheckpointerShmemStruct * )
924- ShmemInitStruct ("Background Writer Data" ,
925+ ShmemInitStruct ("Checkpointer Data" ,
925926CheckpointerShmemSize (),
926927& found );
927928
955956RequestCheckpoint (int flags )
956957{
957958/* use volatile pointer to prevent code rearrangement */
958- volatile CheckpointerShmemStruct * bgs = CheckpointerShmem ;
959+ volatile CheckpointerShmemStruct * cps = CheckpointerShmem ;
959960int ntries ;
960961int old_failed ,
961962old_started ;
@@ -989,13 +990,13 @@ RequestCheckpoint(int flags)
989990 * a "stronger" request by another backend. The flag senses must be
990991 * chosen to make this work!
991992 */
992- SpinLockAcquire (& bgs -> ckpt_lck );
993+ SpinLockAcquire (& cps -> ckpt_lck );
993994
994- old_failed = bgs -> ckpt_failed ;
995- old_started = bgs -> ckpt_started ;
996- bgs -> ckpt_flags |=flags ;
995+ old_failed = cps -> ckpt_failed ;
996+ old_started = cps -> ckpt_started ;
997+ cps -> ckpt_flags |=flags ;
997998
998- SpinLockRelease (& bgs -> ckpt_lck );
999+ SpinLockRelease (& cps -> ckpt_lck );
9991000
10001001/*
10011002 * Send signal to request checkpoint. It's possible that the checkpointer
@@ -1043,9 +1044,9 @@ RequestCheckpoint(int flags)
10431044/* Wait for a new checkpoint to start. */
10441045for (;;)
10451046{
1046- SpinLockAcquire (& bgs -> ckpt_lck );
1047- new_started = bgs -> ckpt_started ;
1048- SpinLockRelease (& bgs -> ckpt_lck );
1047+ SpinLockAcquire (& cps -> ckpt_lck );
1048+ new_started = cps -> ckpt_started ;
1049+ SpinLockRelease (& cps -> ckpt_lck );
10491050
10501051if (new_started != old_started )
10511052break ;
@@ -1061,10 +1062,10 @@ RequestCheckpoint(int flags)
10611062{
10621063int new_done ;
10631064
1064- SpinLockAcquire (& bgs -> ckpt_lck );
1065- new_done = bgs -> ckpt_done ;
1066- new_failed = bgs -> ckpt_failed ;
1067- SpinLockRelease (& bgs -> ckpt_lck );
1065+ SpinLockAcquire (& cps -> ckpt_lck );
1066+ new_done = cps -> ckpt_done ;
1067+ new_failed = cps -> ckpt_failed ;
1068+ SpinLockRelease (& cps -> ckpt_lck );
10681069
10691070if (new_done - new_started >=0 )
10701071break ;
@@ -1178,7 +1179,7 @@ ForwardFsyncRequest(RelFileNodeBackend rnode, ForkNumber forknum,
11781179static bool
11791180CompactCheckpointerRequestQueue (void )
11801181{
1181- struct BgWriterSlotMapping
1182+ struct CheckpointerSlotMapping
11821183{
11831184CheckpointerRequest request ;
11841185int slot ;
@@ -1197,7 +1198,7 @@ CompactCheckpointerRequestQueue(void)
11971198/* Initialize temporary hash table */
11981199MemSet (& ctl ,0 ,sizeof (ctl ));
11991200ctl .keysize = sizeof (CheckpointerRequest );
1200- ctl .entrysize = sizeof (struct BgWriterSlotMapping );
1201+ ctl .entrysize = sizeof (struct CheckpointerSlotMapping );
12011202ctl .hash = tag_hash ;
12021203htab = hash_create ("CompactCheckpointerRequestQueue" ,
12031204CheckpointerShmem -> num_requests ,
@@ -1223,7 +1224,7 @@ CompactCheckpointerRequestQueue(void)
12231224for (n = 0 ;n < CheckpointerShmem -> num_requests ;++ n )
12241225{
12251226CheckpointerRequest * request ;
1226- struct BgWriterSlotMapping * slotmap ;
1227+ struct CheckpointerSlotMapping * slotmap ;
12271228bool found ;
12281229
12291230request = & CheckpointerShmem -> requests [n ];