pg_stat_reset_slru()

A function for resetting SLRU statistics

pg_stat_reset_slru() is a system function for resetting SLRU cache statistics as displayed by the pg_stat_slru view.

pg_stat_reset_slru() was added in PostgreSQL 13.

Usage

pg_stat_reset_slru ( text ) → void

If the provided argument is NULL, all SLRU cache statistics are reset.

Individual statistics can be reset by providing one of the following (case-sensitive) values as the argument:

  • CommitTs
  • MultiXactMember
  • MultiXactOffset
  • Notify
  • Serial
  • Subtrans
  • Xact

No kind of error or warning will be raised if an invalid value is provided.

Change history

Examples

Given SLRU statistics in the following state:

postgres=# SELECT * FROM pg_stat_slru;
      name       | blks_zeroed | blks_hit | blks_read | blks_written | blks_exists | flushes | truncates |          stats_reset          
-----------------+-------------+----------+-----------+--------------+-------------+---------+-----------+-------------------------------
 CommitTs        |           1 |       95 |         0 |            0 |           0 |       0 |         0 | 2021-11-03 11:08:05.213091+01
 MultiXactMember |           0 |        0 |         0 |            0 |           0 |       0 |         0 | 2021-11-03 11:08:05.213091+01
 MultiXactOffset |           0 |        0 |         0 |            0 |           0 |       0 |         0 | 2021-11-03 11:08:05.213091+01
 Notify          |           1 |        5 |         0 |            0 |           0 |       0 |         0 | 2021-11-03 11:08:05.213091+01
 Serial          |           0 |        0 |         0 |            0 |           0 |       0 |         0 | 2021-11-03 11:08:05.213091+01
 Subtrans        |           0 |        0 |         0 |            0 |           0 |       0 |         0 | 2021-11-03 11:08:05.213091+01
 Xact            |           0 |     1131 |         0 |            0 |           0 |       0 |         0 | 2021-11-03 11:08:05.213091+01
 other           |           0 |        0 |         0 |            0 |           0 |       0 |         0 | 2021-11-03 11:08:05.213091+01
(8 rows)

the statistics for a single SLRU cache can be reset with e.g.:

postgres=# SELECT pg_stat_reset_slru('Notify');
 pg_stat_reset_slru 
--------------------
 
(1 row)

Time: 5.560 ms
postgres=# SELECT * FROM pg_stat_slru;
      name       | blks_zeroed | blks_hit | blks_read | blks_written | blks_exists | flushes | truncates |          stats_reset          
-----------------+-------------+----------+-----------+--------------+-------------+---------+-----------+-------------------------------
 CommitTs        |           1 |       95 |         0 |            0 |           0 |       0 |         0 | 2021-11-03 11:08:05.213091+01
 MultiXactMember |           0 |        0 |         0 |            0 |           0 |       0 |         0 | 2021-11-03 11:08:05.213091+01
 MultiXactOffset |           0 |        0 |         0 |            0 |           0 |       0 |         0 | 2021-11-03 11:08:05.213091+01
 Notify          |           0 |        0 |         0 |            0 |           0 |       0 |         0 | 2021-11-22 01:17:05.79368+01
 Serial          |           0 |        0 |         0 |            0 |           0 |       0 |         0 | 2021-11-03 11:08:05.213091+01
 Subtrans        |           0 |        0 |         0 |            0 |           0 |       0 |         0 | 2021-11-03 11:08:05.213091+01
 Xact            |           0 |     1131 |         0 |            0 |           0 |       0 |         0 | 2021-11-03 11:08:05.213091+01
 other           |           0 |        0 |         0 |            0 |           0 |       0 |         0 | 2021-11-03 11:08:05.213091+01
(8 rows)

Resetting statistics for all caches:

postgres=# SELECT pg_stat_reset_slru(NULL);
 pg_stat_reset_slru 
--------------------
 
(1 row)

postgres=# SELECT * FROM pg_stat_slru;
      name       | blks_zeroed | blks_hit | blks_read | blks_written | blks_exists | flushes | truncates |          stats_reset          
-----------------+-------------+----------+-----------+--------------+-------------+---------+-----------+-------------------------------
 CommitTs        |           0 |        0 |         0 |            0 |           0 |       0 |         0 | 2021-11-22 01:18:05.565189+01
 MultiXactMember |           0 |        0 |         0 |            0 |           0 |       0 |         0 | 2021-11-22 01:18:05.565189+01
 MultiXactOffset |           0 |        0 |         0 |            0 |           0 |       0 |         0 | 2021-11-22 01:18:05.565189+01
 Notify          |           0 |        0 |         0 |            0 |           0 |       0 |         0 | 2021-11-22 01:18:05.565189+01
 Serial          |           0 |        0 |         0 |            0 |           0 |       0 |         0 | 2021-11-22 01:18:05.565189+01
 Subtrans        |           0 |        0 |         0 |            0 |           0 |       0 |         0 | 2021-11-22 01:18:05.565189+01
 Xact            |           0 |        0 |         0 |            0 |           0 |       0 |         0 | 2021-11-22 01:18:05.565189+01
 other           |           0 |        0 |         0 |            0 |           0 |       0 |         0 | 2021-11-22 01:18:05.565189+01
(8 rows)

Providing the name of a non-existent SLRU cache:

postgres=# SELECT pg_stat_reset_slru('foo');
 pg_stat_reset_slru 
--------------------
 
(1 row)

Categories

Memory, Server statistics, System function

See also

pg_stat_reset(), pg_stat_reset_shared(), pg_stat_reset_single_function_counters(), pg_stat_reset_single_table_counters(), pg_stat_reset_replication_slot()