0001-Enhance-checkpoint-logs-to-include-checkpoint-reason.patch
text/x-patch
Filename: 0001-Enhance-checkpoint-logs-to-include-checkpoint-reason.patch
Type: text/x-patch
Part: 0
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: format-patch
Series: patch 0001
Subject: Enhance checkpoint logs to include checkpoint reason with format-compatible tests
| File | + | − |
|---|---|---|
| src/backend/access/transam/xlog.c | 19 | 5 |
| src/test/recovery/t/019_replslot_limit.pl | 1 | 1 |
From 38f52466f82eac74a5844069dfb83c46c947d666 Mon Sep 17 00:00:00 2001
From: Soumya <soumyamurali.work@gmail.com>
Date: Thu, 1 Jan 2026 13:32:26 +0530
Subject: [PATCH] Enhance checkpoint logs to include checkpoint reason with
format-compatible tests
Signed-off-by: Soumya <soumyamurali.work@gmail.com>
---
src/backend/access/transam/xlog.c | 24 ++++++++++++++++++-----
src/test/recovery/t/019_replslot_limit.pl | 2 +-
2 files changed, 20 insertions(+), 6 deletions(-)
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index 22d0a2e8c3..6107e5d993 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -56,6 +56,7 @@
#include "access/transam.h"
#include "access/twophase.h"
#include "access/xact.h"
+#include "access/xlog.h"
#include "access/xlog_internal.h"
#include "access/xlogarchive.h"
#include "access/xloginsert.h"
@@ -6750,7 +6751,7 @@ LogCheckpointStart(int flags, bool restartpoint)
* Log end of a checkpoint.
*/
static void
-LogCheckpointEnd(bool restartpoint)
+LogCheckpointEnd(bool restartpoint, int flags)
{
long write_msecs,
sync_msecs,
@@ -6758,6 +6759,17 @@ LogCheckpointEnd(bool restartpoint)
longest_msecs,
average_msecs;
uint64 average_sync_time;
+ const char *ckpt_reason = "timed";
+
+ /* Determine checkpoint reason */
+ if (flags & CHECKPOINT_IS_SHUTDOWN)
+ ckpt_reason = "shutdown";
+ else if (flags & CHECKPOINT_END_OF_RECOVERY)
+ ckpt_reason = "end-of-recovery";
+ else if (flags & CHECKPOINT_FAST)
+ ckpt_reason = "immediate";
+ else if (flags & CHECKPOINT_FORCE)
+ ckpt_reason = "forced";
CheckpointStats.ckpt_end_t = GetCurrentTimestamp();
@@ -6800,12 +6812,13 @@ LogCheckpointEnd(bool restartpoint)
*/
if (restartpoint)
ereport(LOG,
- (errmsg("restartpoint complete: wrote %d buffers (%.1f%%), "
+ (errmsg("restartpoint complete (%s): wrote %d buffers (%.1f%%), "
"wrote %d SLRU buffers; %d WAL file(s) added, "
"%d removed, %d recycled; write=%ld.%03d s, "
"sync=%ld.%03d s, total=%ld.%03d s; sync files=%d, "
"longest=%ld.%03d s, average=%ld.%03d s; distance=%d kB, "
"estimate=%d kB; lsn=%X/%08X, redo lsn=%X/%08X",
+ ckpt_reason,
CheckpointStats.ckpt_bufs_written,
(double) CheckpointStats.ckpt_bufs_written * 100 / NBuffers,
CheckpointStats.ckpt_slru_written,
@@ -6824,12 +6837,13 @@ LogCheckpointEnd(bool restartpoint)
LSN_FORMAT_ARGS(ControlFile->checkPointCopy.redo))));
else
ereport(LOG,
- (errmsg("checkpoint complete: wrote %d buffers (%.1f%%), "
+ (errmsg("checkpoint complete (%s): wrote %d buffers (%.1f%%), "
"wrote %d SLRU buffers; %d WAL file(s) added, "
"%d removed, %d recycled; write=%ld.%03d s, "
"sync=%ld.%03d s, total=%ld.%03d s; sync files=%d, "
"longest=%ld.%03d s, average=%ld.%03d s; distance=%d kB, "
"estimate=%d kB; lsn=%X/%08X, redo lsn=%X/%08X",
+ ckpt_reason,
CheckpointStats.ckpt_bufs_written,
(double) CheckpointStats.ckpt_bufs_written * 100 / NBuffers,
CheckpointStats.ckpt_slru_written,
@@ -7418,7 +7432,7 @@ CreateCheckPoint(int flags)
TruncateSUBTRANS(GetOldestTransactionIdConsideredRunning());
/* Real work is done; log and update stats. */
- LogCheckpointEnd(false);
+ LogCheckpointEnd(false, flags);
/* Reset the process title */
update_checkpoint_display(flags, false, true);
@@ -7886,7 +7900,7 @@ CreateRestartPoint(int flags)
TruncateSUBTRANS(GetOldestTransactionIdConsideredRunning());
/* Real work is done; log and update stats. */
- LogCheckpointEnd(true);
+ LogCheckpointEnd(true, flags);
/* Reset the process title */
update_checkpoint_display(flags, true, true);
diff --git a/src/test/recovery/t/019_replslot_limit.pl b/src/test/recovery/t/019_replslot_limit.pl
index 6468784b83..ccc363157e 100644
--- a/src/test/recovery/t/019_replslot_limit.pl
+++ b/src/test/recovery/t/019_replslot_limit.pl
@@ -203,7 +203,7 @@ is($result, "rep1|f|t|lost|",
my $checkpoint_ended = 0;
for (my $i = 0; $i < 10 * $PostgreSQL::Test::Utils::timeout_default; $i++)
{
- if ($node_primary->log_contains("checkpoint complete: ", $logstart))
+ if ($node_primary->log_contains(qr/checkpoint complete(?: \([^)]*\))?:/, $logstart))
{
$checkpoint_ended = 1;
last;
--
2.34.1