]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Log checkpoint request flags in checkpoint completion messages.
authorFujii Masao <fujii@postgresql.org>
Thu, 19 Feb 2026 14:55:12 +0000 (23:55 +0900)
committerFujii Masao <fujii@postgresql.org>
Thu, 19 Feb 2026 14:55:12 +0000 (23:55 +0900)
Checkpoint completion log messages include more detail than checkpoint
start messages, but previously omitted the checkpoint request flags,
which were only logged at checkpoint start. As a result, users had to
correlate completion messages with earlier start messages to see
the full context.

This commit includes the checkpoint request flags in the checkpoint
completion log message as well. This duplicates some information,
but makes the completion message self-contained and easier to interpret.

Author: Soumya S Murali <soumyamurali.work@gmail.com>
Reviewed-by: Michael Banck <mbanck@gmx.net>
Reviewed-by: Yuan Li <carol.li2025@outlook.com>
Reviewed-by: Fujii Masao <masao.fujii@gmail.com>
Discussion: https://postgr.es/m/CAMtXxw9tPwV=NBv5S9GZXMSKPeKv5f9hRhSjZ8__oLsoS5jcuA@mail.gmail.com

src/backend/access/transam/xlog.c

index 13ec6225b859f9c04fd8c6152f200441b1136b88..13cce9b49f16e994f947f6551df648642425bfb6 100644 (file)
@@ -6768,6 +6768,28 @@ ShutdownXLOG(int code, Datum arg)
        }
 }
 
+/*
+ * Format checkpoint request flags as a space-separated string for
+ * log messages.
+ */
+static const char *
+CheckpointFlagsString(int flags)
+{
+       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;
+}
+
 /*
  * Log start of a checkpoint.
  */
@@ -6776,35 +6798,21 @@ LogCheckpointStart(int flags, bool restartpoint)
 {
        if (restartpoint)
                ereport(LOG,
-               /* translator: the placeholders show checkpoint options */
-                               (errmsg("restartpoint starting:%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" : "")));
+               /* translator: the placeholder shows checkpoint options */
+                               (errmsg("restartpoint starting:%s",
+                                               CheckpointFlagsString(flags))));
        else
                ereport(LOG,
-               /* translator: the placeholders show checkpoint options */
-                               (errmsg("checkpoint starting:%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" : "")));
+               /* translator: the placeholder shows checkpoint options */
+                               (errmsg("checkpoint starting:%s",
+                                               CheckpointFlagsString(flags))));
 }
 
 /*
  * Log end of a checkpoint.
  */
 static void
-LogCheckpointEnd(bool restartpoint)
+LogCheckpointEnd(bool restartpoint, int flags)
 {
        long            write_msecs,
                                sync_msecs,
@@ -6854,12 +6862,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",
+                                               CheckpointFlagsString(flags),
                                                CheckpointStats.ckpt_bufs_written,
                                                (double) CheckpointStats.ckpt_bufs_written * 100 / NBuffers,
                                                CheckpointStats.ckpt_slru_written,
@@ -6878,12 +6887,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",
+                                               CheckpointFlagsString(flags),
                                                CheckpointStats.ckpt_bufs_written,
                                                (double) CheckpointStats.ckpt_bufs_written * 100 / NBuffers,
                                                CheckpointStats.ckpt_slru_written,
@@ -7480,7 +7490,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);
@@ -7951,7 +7961,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);