| From: | Xuneng Zhou <xunengzhou(at)gmail(dot)com> |
|---|---|
| To: | pgsql-hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
| Subject: | log_checkpoints: count WAL segment creations from all processes |
| Date: | 2026-03-23 07:39:51 |
| Message-ID: | CABPTF7XBgnOGQDno-kOx1_wZ=7iqQaR7h7RdRPgXhKURf3wbLw@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi hackers,
This patch implements a suggestion from Andres' "Desired Changes" list
[1] regarding the misleading nature of the WAL segment creation
count in 'log_checkpoints' output. The "WAL file(s) added" field in
checkpoint/restartpoint log output currently counts only segments
added through PreallocXlogFiles(). It does not include segments
created by other paths such as backend WAL growth, walreceiver, or
timeline initialization, so on a write-heavy system the reported value
can stay at 0 or 1 even when many new WAL segments were actually
created.
This version fixes the accounting by adding a shared-memory atomic
counter, walSegmentsCreated, to XLogCtlData. The counter is
incremented in the WAL-segment creation/install paths,
XLogFileInitInternal() and XLogFileCopy() (used for timeline
switches). Each checkpoint or restartpoint reports WAL file(s) added
as the difference between the current counter value and a saved
baseline, walSegsCreatedLastCheckpoint, then advances that baseline.
Because the baseline is initialized to 0, the first checkpoint after
startup counts all segments created since startup, including
timeline-initialization segments created before the end-of-recovery
checkpoint is requested.
The semantic change is intentional: 'ckpt_segs_added' (and arg2 of the
TRACE_POSTGRESQL_CHECKPOINT_DONE probe) now means "new WAL segments
created since the previous successful checkpoint or restartpoint, by
any process." The probe arity is unchanged. config.sgml and
monitoring.sgml are updated accordingly.
Patch attached. Any feedback is welcome.
--
Best,
Xuneng
| Attachment | Content-Type | Size |
|---|---|---|
| v1-0001-Count-WAL-segment-creations-by-all-processes-in-l.patch | application/x-patch | 8.0 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Peter Eisentraut | 2026-03-23 07:45:00 | Re: headerscheck ccache support |
| Previous Message | Antonin Houska | 2026-03-23 07:22:14 | Teach isolation tester about injection points in background workers |