From aa551d44eabfdf122cf6040628039e5801b5f271 Mon Sep 17 00:00:00 2001 From: Nathan Bossart Date: Fri, 4 Dec 2020 17:12:47 +0000 Subject: [PATCH v5 1/1] Add checkpoint/restartpoint status to ps display. --- src/backend/access/transam/xlog.c | 31 +++++++++++++++++++++++++++++++ src/backend/postmaster/checkpointer.c | 7 +++++++ 2 files changed, 38 insertions(+) diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index 7e81ce4f17..7fde6db4ac 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -8730,6 +8730,7 @@ CreateCheckPoint(int flags) XLogRecPtr last_important_lsn; VirtualTransactionId *vxids; int nvxids; + char activitymsg[64]; /* * An end-of-recovery checkpoint is really a shutdown checkpoint, just @@ -8905,6 +8906,11 @@ CreateCheckPoint(int flags) if (log_checkpoints) LogCheckpointStart(flags, false); + snprintf(activitymsg, sizeof(activitymsg), "creating %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 +9126,16 @@ CreateCheckPoint(int flags) /* Real work is done, but log and update stats before releasing lock. */ LogCheckpointEnd(false); + /* + * Reset the ps status display. We set the status to "idle" for the + * checkpointer process, and we clear it for anything else that runs this + * code. + */ + if (MyBackendType == B_CHECKPOINTER) + set_ps_display("idle"); + else + set_ps_display(""); + TRACE_POSTGRESQL_CHECKPOINT_DONE(CheckpointStats.ckpt_bufs_written, NBuffers, CheckpointStats.ckpt_segs_added, @@ -9282,6 +9298,7 @@ CreateRestartPoint(int flags) XLogRecPtr endptr; XLogSegNo _logSegNo; TimestampTz xtime; + char activitymsg[64]; /* * Acquire CheckpointLock to ensure only one restartpoint or checkpoint @@ -9374,6 +9391,10 @@ CreateRestartPoint(int flags) if (log_checkpoints) LogCheckpointStart(flags, true); + snprintf(activitymsg, sizeof(activitymsg), "creating %srestartpoint", + (flags & CHECKPOINT_IS_SHUTDOWN) ? "shutdown " : ""); + set_ps_display(activitymsg); + CheckPointGuts(lastCheckPoint.redo, flags); /* @@ -9492,6 +9513,16 @@ CreateRestartPoint(int flags) /* Real work is done, but log and update before releasing lock. */ LogCheckpointEnd(true); + /* + * Reset the ps status display. We set the status to "idle" for the + * checkpointer process, and we clear it for anything else that runs this + * code. + */ + if (MyBackendType == B_CHECKPOINTER) + set_ps_display("idle"); + else + set_ps_display(""); + xtime = GetLatestXTime(); ereport((log_checkpoints ? LOG : DEBUG2), (errmsg("recovery restart point at %X/%X", diff --git a/src/backend/postmaster/checkpointer.c b/src/backend/postmaster/checkpointer.c index 429c8010ef..3d154b5d4f 100644 --- a/src/backend/postmaster/checkpointer.c +++ b/src/backend/postmaster/checkpointer.c @@ -59,6 +59,7 @@ #include "storage/spin.h" #include "utils/guc.h" #include "utils/memutils.h" +#include "utils/ps_status.h" #include "utils/resowner.h" @@ -332,6 +333,12 @@ CheckpointerMain(void) */ ProcGlobal->checkpointerLatch = &MyProc->procLatch; + /* + * Initialize ps display. CreateCheckPoint() and CreateRestartPoint() + * handle updating it as needed. + */ + set_ps_display("idle"); + /* * Loop forever */ -- 2.16.6