Skip to content

Commit 17cc5f6

Browse files
committed
Fix inconsistent reporting of checkpointer stats.
Previously, the pg_stat_checkpointer view and the checkpoint completion log message could show different numbers for buffers written during checkpoints. The view only counted shared buffers, while the log message included both shared and SLRU buffers, causing inconsistencies. This commit resolves the issue by updating both the view and the log message to separately report shared and SLRU buffers written during checkpoints. A new slru_written column is added to the pg_stat_checkpointer view to track SLRU buffers, while the existing buffers_written column now tracks only shared buffers. This change would help users distinguish between the two types of buffers, in the pg_stat_checkpointer view and the checkpoint complete log message, respectively. Bump catalog version. Author: Nitin Jadhav Reviewed-by: Bharath Rupireddy, Michael Paquier, Kyotaro Horiguchi, Robert Haas Reviewed-by: Andres Freund, vignesh C, Fujii Masao Discussion: https://postgr.es/m/CAMm1aWb18EpT0whJrjG+-nyhNouXET6ZUw0pNYYAe+NezpvsAA@mail.gmail.com
1 parent 506eede commit 17cc5f6

File tree

11 files changed

+47
-16
lines changed

11 files changed

+47
-16
lines changed

doc/src/sgml/monitoring.sgml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3127,7 +3127,16 @@ description | Waiting for a newly initialized WAL file to reach durable storage
31273127
<structfield>buffers_written</structfield> <type>bigint</type>
31283128
</para>
31293129
<para>
3130-
Number of buffers written during checkpoints and restartpoints
3130+
Number of shared buffers written during checkpoints and restartpoints
3131+
</para></entry>
3132+
</row>
3133+
3134+
<row>
3135+
<entry role="catalog_table_entry"><para role="column_definition">
3136+
<structfield>slru_written</structfield> <type>bigint</type>
3137+
</para>
3138+
<para>
3139+
Number of SLRU buffers written during checkpoints and restartpoints
31313140
</para></entry>
31323141
</row>
31333142

src/backend/access/transam/slru.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -716,9 +716,12 @@ SlruInternalWritePage(SlruCtl ctl, int slotno, SlruWriteAll fdata)
716716
if (!ok)
717717
SlruReportIOError(ctl, pageno, InvalidTransactionId);
718718

719-
/* If part of a checkpoint, count this as a buffer written. */
719+
/* If part of a checkpoint, count this as a SLRU buffer written. */
720720
if (fdata)
721-
CheckpointStats.ckpt_bufs_written++;
721+
{
722+
CheckpointStats.ckpt_slru_written++;
723+
PendingCheckpointerStats.slru_written++;
724+
}
722725
}
723726

724727
/*

src/backend/access/transam/xlog.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6727,14 +6727,15 @@ LogCheckpointEnd(bool restartpoint)
67276727
*/
67286728
if (restartpoint)
67296729
ereport(LOG,
6730-
(errmsg("restartpoint complete: wrote %d buffers (%.1f%%); "
6731-
"%d WAL file(s) added, %d removed, %d recycled; "
6732-
"write=%ld.%03d s, sync=%ld.%03d s, total=%ld.%03d s; "
6733-
"sync files=%d, longest=%ld.%03d s, average=%ld.%03d s; "
6734-
"distance=%d kB, estimate=%d kB; "
6735-
"lsn=%X/%X, redo lsn=%X/%X",
6730+
(errmsg("restartpoint complete: wrote %d buffers (%.1f%%), "
6731+
"wrote %d SLRU buffers; %d WAL file(s) added, "
6732+
"%d removed, %d recycled; write=%ld.%03d s, "
6733+
"sync=%ld.%03d s, total=%ld.%03d s; sync files=%d, "
6734+
"longest=%ld.%03d s, average=%ld.%03d s; distance=%d kB, "
6735+
"estimate=%d kB; lsn=%X/%X, redo lsn=%X/%X",
67366736
CheckpointStats.ckpt_bufs_written,
67376737
(double) CheckpointStats.ckpt_bufs_written * 100 / NBuffers,
6738+
CheckpointStats.ckpt_slru_written,
67386739
CheckpointStats.ckpt_segs_added,
67396740
CheckpointStats.ckpt_segs_removed,
67406741
CheckpointStats.ckpt_segs_recycled,
@@ -6750,14 +6751,15 @@ LogCheckpointEnd(bool restartpoint)
67506751
LSN_FORMAT_ARGS(ControlFile->checkPointCopy.redo))));
67516752
else
67526753
ereport(LOG,
6753-
(errmsg("checkpoint complete: wrote %d buffers (%.1f%%); "
6754-
"%d WAL file(s) added, %d removed, %d recycled; "
6755-
"write=%ld.%03d s, sync=%ld.%03d s, total=%ld.%03d s; "
6756-
"sync files=%d, longest=%ld.%03d s, average=%ld.%03d s; "
6757-
"distance=%d kB, estimate=%d kB; "
6758-
"lsn=%X/%X, redo lsn=%X/%X",
6754+
(errmsg("checkpoint complete: wrote %d buffers (%.1f%%), "
6755+
"wrote %d SLRU buffers; %d WAL file(s) added, "
6756+
"%d removed, %d recycled; write=%ld.%03d s, "
6757+
"sync=%ld.%03d s, total=%ld.%03d s; sync files=%d, "
6758+
"longest=%ld.%03d s, average=%ld.%03d s; distance=%d kB, "
6759+
"estimate=%d kB; lsn=%X/%X, redo lsn=%X/%X",
67596760
CheckpointStats.ckpt_bufs_written,
67606761
(double) CheckpointStats.ckpt_bufs_written * 100 / NBuffers,
6762+
CheckpointStats.ckpt_slru_written,
67616763
CheckpointStats.ckpt_segs_added,
67626764
CheckpointStats.ckpt_segs_removed,
67636765
CheckpointStats.ckpt_segs_recycled,

src/backend/catalog/system_views.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,6 +1145,7 @@ CREATE VIEW pg_stat_checkpointer AS
11451145
pg_stat_get_checkpointer_write_time() AS write_time,
11461146
pg_stat_get_checkpointer_sync_time() AS sync_time,
11471147
pg_stat_get_checkpointer_buffers_written() AS buffers_written,
1148+
pg_stat_get_checkpointer_slru_written() AS slru_written,
11481149
pg_stat_get_checkpointer_stat_reset_time() AS stats_reset;
11491150

11501151
CREATE VIEW pg_stat_io AS

src/backend/utils/activity/pgstat_checkpointer.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ pgstat_report_checkpointer(void)
5656
CHECKPOINTER_ACC(write_time);
5757
CHECKPOINTER_ACC(sync_time);
5858
CHECKPOINTER_ACC(buffers_written);
59+
CHECKPOINTER_ACC(slru_written);
5960
#undef CHECKPOINTER_ACC
6061

6162
pgstat_end_changecount_write(&stats_shmem->changecount);
@@ -135,5 +136,6 @@ pgstat_checkpointer_snapshot_cb(void)
135136
CHECKPOINTER_COMP(write_time);
136137
CHECKPOINTER_COMP(sync_time);
137138
CHECKPOINTER_COMP(buffers_written);
139+
CHECKPOINTER_COMP(slru_written);
138140
#undef CHECKPOINTER_COMP
139141
}

src/backend/utils/adt/pgstatfuncs.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,6 +1221,12 @@ pg_stat_get_checkpointer_buffers_written(PG_FUNCTION_ARGS)
12211221
PG_RETURN_INT64(pgstat_fetch_stat_checkpointer()->buffers_written);
12221222
}
12231223

1224+
Datum
1225+
pg_stat_get_checkpointer_slru_written(PG_FUNCTION_ARGS)
1226+
{
1227+
PG_RETURN_INT64(pgstat_fetch_stat_checkpointer()->slru_written);
1228+
}
1229+
12241230
Datum
12251231
pg_stat_get_bgwriter_buf_written_clean(PG_FUNCTION_ARGS)
12261232
{

src/include/access/xlog.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ typedef struct CheckpointStatsData
167167
TimestampTz ckpt_end_t; /* end of checkpoint */
168168

169169
int ckpt_bufs_written; /* # of buffers written */
170+
int ckpt_slru_written; /* # of SLRU buffers written */
170171

171172
int ckpt_segs_added; /* # of new xlog segments created */
172173
int ckpt_segs_removed; /* # of xlog segments deleted */

src/include/catalog/catversion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,6 @@
5757
*/
5858

5959
/* yyyymmddN */
60-
#define CATALOG_VERSION_NO 202409302
60+
#define CATALOG_VERSION_NO 202410021
6161

6262
#endif

src/include/catalog/pg_proc.dat

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5847,6 +5847,11 @@
58475847
proname => 'pg_stat_get_checkpointer_buffers_written', provolatile => 's',
58485848
proparallel => 'r', prorettype => 'int8', proargtypes => '',
58495849
prosrc => 'pg_stat_get_checkpointer_buffers_written' },
5850+
{ oid => '8573',
5851+
descr => 'statistics: number of SLRU buffers written during checkpoints and restartpoints',
5852+
proname => 'pg_stat_get_checkpointer_slru_written', provolatile => 's',
5853+
proparallel => 'r', prorettype => 'int8', proargtypes => '',
5854+
prosrc => 'pg_stat_get_checkpointer_slru_written' },
58505855
{ oid => '6314', descr => 'statistics: last reset for the checkpointer',
58515856
proname => 'pg_stat_get_checkpointer_stat_reset_time', provolatile => 's',
58525857
proparallel => 'r', prorettype => 'timestamptz', proargtypes => '',

src/include/pgstat.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ typedef struct PgStat_CheckpointerStats
301301
PgStat_Counter write_time; /* times in milliseconds */
302302
PgStat_Counter sync_time;
303303
PgStat_Counter buffers_written;
304+
PgStat_Counter slru_written;
304305
TimestampTz stat_reset_timestamp;
305306
} PgStat_CheckpointerStats;
306307

src/test/regress/expected/rules.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1831,6 +1831,7 @@ pg_stat_checkpointer| SELECT pg_stat_get_checkpointer_num_timed() AS num_timed,
18311831
pg_stat_get_checkpointer_write_time() AS write_time,
18321832
pg_stat_get_checkpointer_sync_time() AS sync_time,
18331833
pg_stat_get_checkpointer_buffers_written() AS buffers_written,
1834+
pg_stat_get_checkpointer_slru_written() AS slru_written,
18341835
pg_stat_get_checkpointer_stat_reset_time() AS stats_reset;
18351836
pg_stat_database| SELECT oid AS datid,
18361837
datname,

0 commit comments

Comments
 (0)