diff --git a/src/backend/postmaster/checkpointer.c b/src/backend/postmaster/checkpointer.c index aaad5c5228..5eac4aa8e3 100644 --- a/src/backend/postmaster/checkpointer.c +++ b/src/backend/postmaster/checkpointer.c @@ -504,7 +504,6 @@ CheckpointerMain(void) /* Report pending statistics to the cumulative stats system */ pgstat_report_checkpointer(); - pgstat_report_wal(true); /* * If any checkpoint flags have been set, redo the loop to handle the @@ -582,7 +581,6 @@ HandleCheckpointerInterrupts(void) PendingCheckpointerStats.requested_checkpoints++; ShutdownXLOG(0, 0); pgstat_report_checkpointer(); - pgstat_report_wal(true); /* Normal exit from the checkpointer is here */ proc_exit(0); /* done */ diff --git a/src/backend/utils/activity/pgstat_checkpointer.c b/src/backend/utils/activity/pgstat_checkpointer.c index 26dec112f6..fd4a1c1adc 100644 --- a/src/backend/utils/activity/pgstat_checkpointer.c +++ b/src/backend/utils/activity/pgstat_checkpointer.c @@ -24,10 +24,22 @@ PgStat_CheckpointerStats PendingCheckpointerStats = {0}; /* - * Report checkpointer and IO statistics + * Report checkpointer, IO, WAL and SLRU statistics */ void pgstat_report_checkpointer(void) +{ + pgstat_flush_checkpointer(); + pgstat_flush_wal(true); + pgstat_flush_io(true); + pgstat_slru_flush(true); +} + +/* + * Flush out locally pending checkpointer stats + */ +void +pgstat_flush_checkpointer(void) { /* We assume this initializes to zeroes */ static const PgStat_CheckpointerStats all_zeroes; @@ -62,11 +74,6 @@ pgstat_report_checkpointer(void) * Clear out the statistics buffer, so it can be re-used. */ MemSet(&PendingCheckpointerStats, 0, sizeof(PendingCheckpointerStats)); - - /* - * Report IO statistics - */ - pgstat_flush_io(false); } /* diff --git a/src/include/utils/pgstat_internal.h b/src/include/utils/pgstat_internal.h index 6badb2fde4..00851c9474 100644 --- a/src/include/utils/pgstat_internal.h +++ b/src/include/utils/pgstat_internal.h @@ -540,6 +540,7 @@ extern void pgstat_bgwriter_snapshot_cb(void); extern void pgstat_checkpointer_reset_all_cb(TimestampTz ts); extern void pgstat_checkpointer_snapshot_cb(void); +extern void pgstat_flush_checkpointer(void); /* diff --git a/src/test/regress/expected/stats.out b/src/test/regress/expected/stats.out index 937b2101b3..bae1b54b31 100644 --- a/src/test/regress/expected/stats.out +++ b/src/test/regress/expected/stats.out @@ -783,11 +783,14 @@ SELECT sessions > :db_stat_sessions FROM pg_stat_database WHERE datname = (SELEC (1 row) -- Test pg_stat_bgwriter checkpointer-related stats, together with pg_stat_wal +-- and pg_stat_slru SELECT checkpoints_req AS rqst_ckpts_before FROM pg_stat_bgwriter \gset -- Test pg_stat_wal (and make a temp table so our temp schema exists) SELECT wal_bytes AS wal_bytes_before FROM pg_stat_wal \gset CREATE TEMP TABLE test_stats_temp AS SELECT 17; DROP TABLE test_stats_temp; +-- Test pg_stat_slru, checkpoint should generate SLRU flushes +SELECT SUM(flushes) AS slru_flushes_before from pg_stat_slru \gset -- Checkpoint twice: The checkpointer reports stats after reporting completion -- of the checkpoint. But after a second checkpoint we'll see at least the -- results of the first. @@ -805,6 +808,12 @@ SELECT wal_bytes > :wal_bytes_before FROM pg_stat_wal; t (1 row) +SELECT SUM(flushes) > :slru_flushes_before FROM pg_stat_slru; + ?column? +---------- + t +(1 row) + -- Test pg_stat_get_backend_idset() and some allied functions. -- In particular, verify that their notion of backend ID matches -- our temp schema index. diff --git a/src/test/regress/sql/stats.sql b/src/test/regress/sql/stats.sql index 74e592aa8a..dada15835f 100644 --- a/src/test/regress/sql/stats.sql +++ b/src/test/regress/sql/stats.sql @@ -388,6 +388,7 @@ SELECT pg_stat_force_next_flush(); SELECT sessions > :db_stat_sessions FROM pg_stat_database WHERE datname = (SELECT current_database()); -- Test pg_stat_bgwriter checkpointer-related stats, together with pg_stat_wal +-- and pg_stat_slru SELECT checkpoints_req AS rqst_ckpts_before FROM pg_stat_bgwriter \gset -- Test pg_stat_wal (and make a temp table so our temp schema exists) @@ -396,6 +397,9 @@ SELECT wal_bytes AS wal_bytes_before FROM pg_stat_wal \gset CREATE TEMP TABLE test_stats_temp AS SELECT 17; DROP TABLE test_stats_temp; +-- Test pg_stat_slru, checkpoint should generate SLRU flushes +SELECT SUM(flushes) AS slru_flushes_before from pg_stat_slru \gset + -- Checkpoint twice: The checkpointer reports stats after reporting completion -- of the checkpoint. But after a second checkpoint we'll see at least the -- results of the first. @@ -404,6 +408,7 @@ CHECKPOINT; SELECT checkpoints_req > :rqst_ckpts_before FROM pg_stat_bgwriter; SELECT wal_bytes > :wal_bytes_before FROM pg_stat_wal; +SELECT SUM(flushes) > :slru_flushes_before FROM pg_stat_slru; -- Test pg_stat_get_backend_idset() and some allied functions. -- In particular, verify that their notion of backend ID matches