mirror of
https://github.com/postgres/postgres.git
synced 2025-07-07 00:36:50 +03:00
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
This commit is contained in:
@ -3127,7 +3127,16 @@ description | Waiting for a newly initialized WAL file to reach durable storage
|
||||
<structfield>buffers_written</structfield> <type>bigint</type>
|
||||
</para>
|
||||
<para>
|
||||
Number of buffers written during checkpoints and restartpoints
|
||||
Number of shared buffers written during checkpoints and restartpoints
|
||||
</para></entry>
|
||||
</row>
|
||||
|
||||
<row>
|
||||
<entry role="catalog_table_entry"><para role="column_definition">
|
||||
<structfield>slru_written</structfield> <type>bigint</type>
|
||||
</para>
|
||||
<para>
|
||||
Number of SLRU buffers written during checkpoints and restartpoints
|
||||
</para></entry>
|
||||
</row>
|
||||
|
||||
|
@ -716,9 +716,12 @@ SlruInternalWritePage(SlruCtl ctl, int slotno, SlruWriteAll fdata)
|
||||
if (!ok)
|
||||
SlruReportIOError(ctl, pageno, InvalidTransactionId);
|
||||
|
||||
/* If part of a checkpoint, count this as a buffer written. */
|
||||
/* If part of a checkpoint, count this as a SLRU buffer written. */
|
||||
if (fdata)
|
||||
CheckpointStats.ckpt_bufs_written++;
|
||||
{
|
||||
CheckpointStats.ckpt_slru_written++;
|
||||
PendingCheckpointerStats.slru_written++;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -6727,14 +6727,15 @@ LogCheckpointEnd(bool restartpoint)
|
||||
*/
|
||||
if (restartpoint)
|
||||
ereport(LOG,
|
||||
(errmsg("restartpoint complete: wrote %d buffers (%.1f%%); "
|
||||
"%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/%X, redo lsn=%X/%X",
|
||||
(errmsg("restartpoint complete: 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/%X, redo lsn=%X/%X",
|
||||
CheckpointStats.ckpt_bufs_written,
|
||||
(double) CheckpointStats.ckpt_bufs_written * 100 / NBuffers,
|
||||
CheckpointStats.ckpt_slru_written,
|
||||
CheckpointStats.ckpt_segs_added,
|
||||
CheckpointStats.ckpt_segs_removed,
|
||||
CheckpointStats.ckpt_segs_recycled,
|
||||
@ -6750,14 +6751,15 @@ LogCheckpointEnd(bool restartpoint)
|
||||
LSN_FORMAT_ARGS(ControlFile->checkPointCopy.redo))));
|
||||
else
|
||||
ereport(LOG,
|
||||
(errmsg("checkpoint complete: wrote %d buffers (%.1f%%); "
|
||||
"%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/%X, redo lsn=%X/%X",
|
||||
(errmsg("checkpoint complete: 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/%X, redo lsn=%X/%X",
|
||||
CheckpointStats.ckpt_bufs_written,
|
||||
(double) CheckpointStats.ckpt_bufs_written * 100 / NBuffers,
|
||||
CheckpointStats.ckpt_slru_written,
|
||||
CheckpointStats.ckpt_segs_added,
|
||||
CheckpointStats.ckpt_segs_removed,
|
||||
CheckpointStats.ckpt_segs_recycled,
|
||||
|
@ -1145,6 +1145,7 @@ CREATE VIEW pg_stat_checkpointer AS
|
||||
pg_stat_get_checkpointer_write_time() AS write_time,
|
||||
pg_stat_get_checkpointer_sync_time() AS sync_time,
|
||||
pg_stat_get_checkpointer_buffers_written() AS buffers_written,
|
||||
pg_stat_get_checkpointer_slru_written() AS slru_written,
|
||||
pg_stat_get_checkpointer_stat_reset_time() AS stats_reset;
|
||||
|
||||
CREATE VIEW pg_stat_io AS
|
||||
|
@ -56,6 +56,7 @@ pgstat_report_checkpointer(void)
|
||||
CHECKPOINTER_ACC(write_time);
|
||||
CHECKPOINTER_ACC(sync_time);
|
||||
CHECKPOINTER_ACC(buffers_written);
|
||||
CHECKPOINTER_ACC(slru_written);
|
||||
#undef CHECKPOINTER_ACC
|
||||
|
||||
pgstat_end_changecount_write(&stats_shmem->changecount);
|
||||
@ -135,5 +136,6 @@ pgstat_checkpointer_snapshot_cb(void)
|
||||
CHECKPOINTER_COMP(write_time);
|
||||
CHECKPOINTER_COMP(sync_time);
|
||||
CHECKPOINTER_COMP(buffers_written);
|
||||
CHECKPOINTER_COMP(slru_written);
|
||||
#undef CHECKPOINTER_COMP
|
||||
}
|
||||
|
@ -1221,6 +1221,12 @@ pg_stat_get_checkpointer_buffers_written(PG_FUNCTION_ARGS)
|
||||
PG_RETURN_INT64(pgstat_fetch_stat_checkpointer()->buffers_written);
|
||||
}
|
||||
|
||||
Datum
|
||||
pg_stat_get_checkpointer_slru_written(PG_FUNCTION_ARGS)
|
||||
{
|
||||
PG_RETURN_INT64(pgstat_fetch_stat_checkpointer()->slru_written);
|
||||
}
|
||||
|
||||
Datum
|
||||
pg_stat_get_bgwriter_buf_written_clean(PG_FUNCTION_ARGS)
|
||||
{
|
||||
|
@ -167,6 +167,7 @@ typedef struct CheckpointStatsData
|
||||
TimestampTz ckpt_end_t; /* end of checkpoint */
|
||||
|
||||
int ckpt_bufs_written; /* # of buffers written */
|
||||
int ckpt_slru_written; /* # of SLRU buffers written */
|
||||
|
||||
int ckpt_segs_added; /* # of new xlog segments created */
|
||||
int ckpt_segs_removed; /* # of xlog segments deleted */
|
||||
|
@ -57,6 +57,6 @@
|
||||
*/
|
||||
|
||||
/* yyyymmddN */
|
||||
#define CATALOG_VERSION_NO 202409302
|
||||
#define CATALOG_VERSION_NO 202410021
|
||||
|
||||
#endif
|
||||
|
@ -5847,6 +5847,11 @@
|
||||
proname => 'pg_stat_get_checkpointer_buffers_written', provolatile => 's',
|
||||
proparallel => 'r', prorettype => 'int8', proargtypes => '',
|
||||
prosrc => 'pg_stat_get_checkpointer_buffers_written' },
|
||||
{ oid => '8573',
|
||||
descr => 'statistics: number of SLRU buffers written during checkpoints and restartpoints',
|
||||
proname => 'pg_stat_get_checkpointer_slru_written', provolatile => 's',
|
||||
proparallel => 'r', prorettype => 'int8', proargtypes => '',
|
||||
prosrc => 'pg_stat_get_checkpointer_slru_written' },
|
||||
{ oid => '6314', descr => 'statistics: last reset for the checkpointer',
|
||||
proname => 'pg_stat_get_checkpointer_stat_reset_time', provolatile => 's',
|
||||
proparallel => 'r', prorettype => 'timestamptz', proargtypes => '',
|
||||
|
@ -301,6 +301,7 @@ typedef struct PgStat_CheckpointerStats
|
||||
PgStat_Counter write_time; /* times in milliseconds */
|
||||
PgStat_Counter sync_time;
|
||||
PgStat_Counter buffers_written;
|
||||
PgStat_Counter slru_written;
|
||||
TimestampTz stat_reset_timestamp;
|
||||
} PgStat_CheckpointerStats;
|
||||
|
||||
|
@ -1831,6 +1831,7 @@ pg_stat_checkpointer| SELECT pg_stat_get_checkpointer_num_timed() AS num_timed,
|
||||
pg_stat_get_checkpointer_write_time() AS write_time,
|
||||
pg_stat_get_checkpointer_sync_time() AS sync_time,
|
||||
pg_stat_get_checkpointer_buffers_written() AS buffers_written,
|
||||
pg_stat_get_checkpointer_slru_written() AS slru_written,
|
||||
pg_stat_get_checkpointer_stat_reset_time() AS stats_reset;
|
||||
pg_stat_database| SELECT oid AS datid,
|
||||
datname,
|
||||
|
Reference in New Issue
Block a user