v8-0001-Add-checkpoint-restartpoint-status-to-ps-display.patch
application/octet-stream
Filename: v8-0001-Add-checkpoint-restartpoint-status-to-ps-display.patch
Type: application/octet-stream
Part: 0
Patch
Format: format-patch
Series: patch v8-0001
Subject: Add checkpoint/restartpoint status to ps display.
| File | + | − |
|---|---|---|
| src/backend/access/transam/xlog.c | 37 | 0 |
From a2fae8666985d0b4f4dbc157b603327a8594600c Mon Sep 17 00:00:00 2001
From: Nathan Bossart <bossartn@amazon.com>
Date: Fri, 11 Dec 2020 18:51:10 +0000
Subject: [PATCH v8 1/1] Add checkpoint/restartpoint status to ps display.
---
src/backend/access/transam/xlog.c | 37 +++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index 7e81ce4f17..7f8934cfb8 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -8687,6 +8687,31 @@ UpdateCheckPointDistanceEstimate(uint64 nbytes)
(0.90 * CheckPointDistanceEstimate + 0.10 * (double) nbytes);
}
+/*
+ * Update the ps display for a process running a checkpoint or restartpoint.
+ * Note that this routine cannot do any memory allocations, since it may be
+ * called within a critical section.
+ */
+static void
+set_ps_display_for_checkpoint(int flags, bool restartpoint)
+{
+ char activitymsg[128];
+
+ /*
+ * The status is reported only for end-of-recovery/shutdown checkpoints and
+ * shutdown restartpoints since it may not be possible to access
+ * pg_stat_activity in those situations.
+ */
+ if ((flags & (CHECKPOINT_END_OF_RECOVERY | CHECKPOINT_IS_SHUTDOWN)) == 0)
+ return;
+
+ snprintf(activitymsg, sizeof(activitymsg), "performing %s%s%s",
+ (flags & CHECKPOINT_END_OF_RECOVERY) ? "end-of-recovery " : "",
+ (flags & CHECKPOINT_IS_SHUTDOWN) ? "shutdown " : "",
+ restartpoint ? "restartpoint" : "checkpoint");
+ set_ps_display(activitymsg);
+}
+
/*
* Perform a checkpoint --- either during shutdown, or on-the-fly
*
@@ -8905,6 +8930,9 @@ CreateCheckPoint(int flags)
if (log_checkpoints)
LogCheckpointStart(flags, false);
+ /* Update the process title */
+ set_ps_display_for_checkpoint(flags, false);
+
TRACE_POSTGRESQL_CHECKPOINT_START(flags);
/*
@@ -9120,6 +9148,9 @@ CreateCheckPoint(int flags)
/* Real work is done, but log and update stats before releasing lock. */
LogCheckpointEnd(false);
+ /* Reset the process title */
+ set_ps_display("");
+
TRACE_POSTGRESQL_CHECKPOINT_DONE(CheckpointStats.ckpt_bufs_written,
NBuffers,
CheckpointStats.ckpt_segs_added,
@@ -9374,6 +9405,9 @@ CreateRestartPoint(int flags)
if (log_checkpoints)
LogCheckpointStart(flags, true);
+ /* Update the process title */
+ set_ps_display_for_checkpoint(flags, true);
+
CheckPointGuts(lastCheckPoint.redo, flags);
/*
@@ -9492,6 +9526,9 @@ CreateRestartPoint(int flags)
/* Real work is done, but log and update before releasing lock. */
LogCheckpointEnd(true);
+ /* Reset the process title */
+ set_ps_display("");
+
xtime = GetLatestXTime();
ereport((log_checkpoints ? LOG : DEBUG2),
(errmsg("recovery restart point at %X/%X",
--
2.16.6