From f96645ae2ea63c098118d9d003ebf5742ea077a4 Mon Sep 17 00:00:00 2001 From: Nathan Bossart Date: Wed, 9 Dec 2020 18:31:03 +0000 Subject: [PATCH v6 1/1] Add checkpoint/restartpoint status to ps display. --- src/backend/access/transam/xlog.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index 7e81ce4f17..061a3fe787 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -8905,6 +8905,16 @@ CreateCheckPoint(int flags) if (log_checkpoints) LogCheckpointStart(flags, false); + /* Update the process title for end-of-recovery and shutdown checkpoints. */ + if (shutdown) + { + char activitymsg[64]; + snprintf(activitymsg, sizeof(activitymsg), "performing %s%scheckpoint", + (flags & CHECKPOINT_END_OF_RECOVERY) ? "end-of-recovery " : "", + (flags & CHECKPOINT_IS_SHUTDOWN) ? "shutdown " : ""); + set_ps_display(activitymsg); + } + TRACE_POSTGRESQL_CHECKPOINT_START(flags); /* @@ -9120,6 +9130,10 @@ CreateCheckPoint(int flags) /* Real work is done, but log and update stats before releasing lock. */ LogCheckpointEnd(false); + /* Reset the process title. */ + if (shutdown) + set_ps_display(""); + TRACE_POSTGRESQL_CHECKPOINT_DONE(CheckpointStats.ckpt_bufs_written, NBuffers, CheckpointStats.ckpt_segs_added, @@ -9282,6 +9296,7 @@ CreateRestartPoint(int flags) XLogRecPtr endptr; XLogSegNo _logSegNo; TimestampTz xtime; + bool shutdown = (flags & CHECKPOINT_IS_SHUTDOWN); /* * Acquire CheckpointLock to ensure only one restartpoint or checkpoint @@ -9331,7 +9346,7 @@ CreateRestartPoint(int flags) (uint32) lastCheckPoint.redo))); UpdateMinRecoveryPoint(InvalidXLogRecPtr, true); - if (flags & CHECKPOINT_IS_SHUTDOWN) + if (shutdown) { LWLockAcquire(ControlFileLock, LW_EXCLUSIVE); ControlFile->state = DB_SHUTDOWNED_IN_RECOVERY; @@ -9374,6 +9389,10 @@ CreateRestartPoint(int flags) if (log_checkpoints) LogCheckpointStart(flags, true); + /* Update the process title for shutdown restartpoints. */ + if (shutdown) + set_ps_display("performing shutdown restartpoint"); + CheckPointGuts(lastCheckPoint.redo, flags); /* @@ -9416,7 +9435,7 @@ CreateRestartPoint(int flags) minRecoveryPoint = ControlFile->minRecoveryPoint; minRecoveryPointTLI = ControlFile->minRecoveryPointTLI; } - if (flags & CHECKPOINT_IS_SHUTDOWN) + if (shutdown) ControlFile->state = DB_SHUTDOWNED_IN_RECOVERY; UpdateControlFile(); } @@ -9492,6 +9511,10 @@ CreateRestartPoint(int flags) /* Real work is done, but log and update before releasing lock. */ LogCheckpointEnd(true); + /* Reset the process title. */ + if (shutdown) + set_ps_display(""); + xtime = GetLatestXTime(); ereport((log_checkpoints ? LOG : DEBUG2), (errmsg("recovery restart point at %X/%X", -- 2.16.6