Re: [PATCH] Expose checkpoint reason to completion log messages.

From: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
To: Soumya S Murali <soumyamurali(dot)work(at)gmail(dot)com>
Cc: Michael Banck <mbanck(at)gmx(dot)net>, VASUKI M <vasukianand0119(at)gmail(dot)com>, Andres Freund <andres(at)anarazel(dot)de>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Álvaro Herrera <alvherre(at)kurilemu(dot)de>, melanieplageman(at)gmail(dot)com, juanjo(dot)santamaria(at)gmail(dot)com
Subject: Re: [PATCH] Expose checkpoint reason to completion log messages.
Date: 2026-01-13 13:09:49
Message-ID: CAHGQGwHmKOV1qW9sPY49nL6DK7tmgCvbtP2bJQvyrd=k=g_kXQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, Jan 13, 2026 at 3:29 PM Soumya S Murali
<soumyamurali(dot)work(at)gmail(dot)com> wrote:
> Thank you for the detailed review and suggestions.
> I have reworked the patch on a fresh tree, addressed the formatting
> and indentation issues, and aligned the helper implementation with
> PostgreSQL coding conventions. The updated patch has been pgindented
> and validated with make check and the full recovery TAP test suite. I
> am attaching the revised patch for further review.

Thanks for updating the patch!

With this patch, the checkpoint log messages look like this:

LOG: checkpoint starting: fast force wait
LOG: checkpoint complete (fast force wait): ...

The formatting of the checkpoint flags differs between the starting and
complete messages: the complete message wraps them in parentheses,
while the starting message does not. I think it would be better to log
the flags in a consistent way in both messages. For example:

LOG: checkpoint starting: fast force wait
LOG: checkpoint complete: fast force wait: ...

- if ($node_primary->log_contains("checkpoint complete: ", $logstart))
+ if ($node_primary->log_contains(qr/checkpoint complete(?:
\([^)]*\))?:/, $logstart))

If we adopt a format like the above example, this test change would
no longer be needed.

+#define APPEND_REASON(str) \
+ do \
+ { \
+ if (!first) \

Wouldn't it be simpler to just build the string with snprintf() based on
the flags? For example:

---------------------------------------------------
static char buf[128];

snprintf(buf, sizeof(buf), "%s%s%s%s%s%s%s%s",
(flags & CHECKPOINT_IS_SHUTDOWN) ? " shutdown" : "",
(flags & CHECKPOINT_END_OF_RECOVERY) ? " end-of-recovery" : "",
(flags & CHECKPOINT_FAST) ? " fast" : "",
(flags & CHECKPOINT_FORCE) ? " force" : "",
(flags & CHECKPOINT_WAIT) ? " wait" : "",
(flags & CHECKPOINT_CAUSE_XLOG) ? " wal" : "",
(flags & CHECKPOINT_CAUSE_TIME) ? " time" : "",
(flags & CHECKPOINT_FLUSH_UNLOGGED) ? " flush-unlogged" : "");

return buf;
---------------------------------------------------

+ * Format checkpoint reason flags consistently for log messages.
+ * The returned string is suitable for inclusion after
+ * "checkpoint starting:" or inside "checkpoint complete (...)".
+ */
+static const char *
+CheckpointReasonString(int flags)

These flags include more than just the reason a checkpoint was triggered,
so using "reason" here seems misleading. Wouldn't just "flags" be a better term?

Regards,

--
Fujii Masao

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Kevin K Biju 2026-01-13 13:14:45 Re: Allowing ALTER COLUMN TYPE for columns in publication column lists
Previous Message lakshmi 2026-01-13 12:53:16 Re: Proposal: Adding compression of temporary files