[PATCH] Expose checkpoint timestamp and duration in pg_stat_checkpointer

From: Soumya S Murali <soumyamurali(dot)work(at)gmail(dot)com>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Cc: melanieplageman(at)gmail(dot)com
Subject: [PATCH] Expose checkpoint timestamp and duration in pg_stat_checkpointer
Date: 2025-11-24 06:10:44
Message-ID: CAMtXxw_W6w2Q1QsCvMPnoq3xCMKzH28Zjk_EmL60oP+sCTkXOw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi all,

While debugging checkpointer write behavior, I recently found some of the
enhancements related to extending pg_stat_checkpointer by including
checkpoint type (manual/timed/immediate), last_checkpoint_time and
checkpoint_total_time information to checkpoint completion logs through SQL
when `log_checkpoints` is enabled. I am attaching my observations,
screenshots and patch in support for this.

1. Log for type of checkpoint occured:

2025-11-20 11:51:06.128 IST [18026] LOG: checkpoint complete
(immediate): wrote 7286 buffers (44.5%), wrote 4 SLRU buffers; 0 WAL
file(s) added, 0 removed, 27 recycled; write=0.095 s, sync=0.034 s,
total=0.279 s; sync files=17, longest=0.004 s, average=0.002 s;
distance=447382 kB, estimate=531349 kB; lsn=0/7F4EDED8, redo
lsn=0/7F4EDE80

2. Log for the checkpoint_total_time and last_checkpoint_time:

checkpoint_total_time | last_checkpoint_time
-----------------------+----------------------------------
175138 | 2025-11-20 11:58:02.879149+05:30
(1 row)

2025-11-20 11:58:02.879 IST [18026] LOG: checkpoint complete
(immediate): wrote 0 buffers (0.0%), wrote 0 SLRU buffers; 0 WAL
file(s) added, 0 removed, 0 recycled; write=0.001 s, sync=0.001 s,
total=0.019 s; sync files=0, longest=0.000 s, average=0.000 s;
distance=0 kB, estimate=478214 kB; lsn=0/7F4EDFE0, redo lsn=0/7F4EDF88

Looking forward to more feedback.

Regards,
Soumya

Attachment Content-Type Size
0001-Added-enhancement-related-to-checkpoint-reason-durat.patch text/x-patch 7.5 KB
0001-Enhance-checkpoint-logs-to-include-reason-manual-tim.patch text/x-patch 3.6 KB
Screenshot from 2025-11-20 11-56-31.png image/png 143.3 KB
image/png 68.9 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Dilip Kumar 2025-11-24 06:21:40 Re: Proposal: Conflict log history table for Logical Replication
Previous Message Junwang Zhao 2025-11-24 06:03:47 Re: SQL Property Graph Queries (SQL/PGQ)