Skip to content

Commit df9274a

Browse files
committed
Add some checkpoint/restartpoint status to ps display
This is done for end-of-recovery and shutdown checkpoints/restartpoints (end-of-recovery restartpoints don't exist) rather than all types of checkpoints, in cases where it may not be possible to rely on pg_stat_activity to get a status from the startup or checkpointer processes. For example, at the end of a crash recovery, this is useful to know if a checkpoint is running in the startup process, while previously the ps display may only show some information about "recovering" something, that can be confusing while a checkpoint runs. Author: Justin Pryzby Reviewed-by: Nathan Bossart, Kirk Jamison, Fujii Masao, Michael Paquier Discussion: https://postgr.es/m/20200818225238.GP17022@telsasoft.com
1 parent a1b8aa1 commit df9274a

File tree

1 file changed

+45
-0
lines changed
  • src/backend/access/transam

1 file changed

+45
-0
lines changed

src/backend/access/transam/xlog.c

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8687,6 +8687,39 @@ UpdateCheckPointDistanceEstimate(uint64 nbytes)
86878687
(0.90 * CheckPointDistanceEstimate + 0.10 * (double) nbytes);
86888688
}
86898689

8690+
/*
8691+
* Update the ps display for a process running a checkpoint. Note that
8692+
* this routine should not do any allocations so as it can be called
8693+
* from a critical section.
8694+
*/
8695+
static void
8696+
update_checkpoint_display(int flags, bool restartpoint, bool reset)
8697+
{
8698+
/*
8699+
* The status is reported only for end-of-recovery and shutdown
8700+
* checkpoints or shutdown restartpoints. Updating the ps display is
8701+
* useful in those situations as it may not be possible to rely on
8702+
* pg_stat_activity to see the status of the checkpointer or the startup
8703+
* process.
8704+
*/
8705+
if ((flags & (CHECKPOINT_END_OF_RECOVERY | CHECKPOINT_IS_SHUTDOWN)) == 0)
8706+
return;
8707+
8708+
if (reset)
8709+
set_ps_display("");
8710+
else
8711+
{
8712+
char activitymsg[128];
8713+
8714+
snprintf(activitymsg, sizeof(activitymsg), "performing %s%s%s",
8715+
(flags & CHECKPOINT_END_OF_RECOVERY) ? "end-of-recovery " : "",
8716+
(flags & CHECKPOINT_IS_SHUTDOWN) ? "shutdown " : "",
8717+
restartpoint ? "restartpoint" : "checkpoint");
8718+
set_ps_display(activitymsg);
8719+
}
8720+
}
8721+
8722+
86908723
/*
86918724
* Perform a checkpoint --- either during shutdown, or on-the-fly
86928725
*
@@ -8905,6 +8938,9 @@ CreateCheckPoint(int flags)
89058938
if (log_checkpoints)
89068939
LogCheckpointStart(flags, false);
89078940

8941+
/* Update the process title */
8942+
update_checkpoint_display(flags, false, false);
8943+
89088944
TRACE_POSTGRESQL_CHECKPOINT_START(flags);
89098945

89108946
/*
@@ -9120,6 +9156,9 @@ CreateCheckPoint(int flags)
91209156
/* Real work is done, but log and update stats before releasing lock. */
91219157
LogCheckpointEnd(false);
91229158

9159+
/* Reset the process title */
9160+
update_checkpoint_display(flags, false, true);
9161+
91239162
TRACE_POSTGRESQL_CHECKPOINT_DONE(CheckpointStats.ckpt_bufs_written,
91249163
NBuffers,
91259164
CheckpointStats.ckpt_segs_added,
@@ -9374,6 +9413,9 @@ CreateRestartPoint(int flags)
93749413
if (log_checkpoints)
93759414
LogCheckpointStart(flags, true);
93769415

9416+
/* Update the process title */
9417+
update_checkpoint_display(flags, true, false);
9418+
93779419
CheckPointGuts(lastCheckPoint.redo, flags);
93789420

93799421
/*
@@ -9492,6 +9534,9 @@ CreateRestartPoint(int flags)
94929534
/* Real work is done, but log and update before releasing lock. */
94939535
LogCheckpointEnd(true);
94949536

9537+
/* Reset the process title */
9538+
update_checkpoint_display(flags, true, true);
9539+
94959540
xtime = GetLatestXTime();
94969541
ereport((log_checkpoints ? LOG : DEBUG2),
94979542
(errmsg("recovery restart point at %X/%X",

0 commit comments

Comments
 (0)