pg_stat_reset_slru()

重置 SLRU 统计信息的函数

pg_stat_reset_slru() 是一个用于重置 SLRU 缓存统计信息的系统函数,这些统计信息显示在 pg_stat_slru 视图中。

pg_stat_reset_slru()PostgreSQL 13 中添加。

用法

PostgreSQL 17 及更高版本

pg_stat_reset_slru ( target text DEFAULT NULL ) → void

PostgreSQL 16 及更早版本

pg_stat_reset_slru ( text ) → void

如果提供的参数为 NULL,则重置所有 SLRU 缓存统计信息。

可以通过提供以下其中一个(区分大小写)值作为参数来重置单个统计信息

PostgreSQL 13 ~ 16 PostgreSQL 17 ~
CommitTs commit_timestamp
MultiXactMember multixact_member
MultiXactOffset multixact_offset
Notify notify
Serial serializable
Subtrans subtransaction
Xact transaction

如果提供了无效值,则不会引发任何错误或警告。

PostgreSQL 17 开始,pg_stat_reset_shared('slru') 等效于执行不带任何参数的 pg_stat_reset_slru()

更改历史记录

示例

假设 SLRU 统计信息处于以下状态

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)

可以使用例如以下命令重置单个 SLRU 缓存的统计信息:

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)

重置所有缓存的统计信息(请注意,从 PostgreSQL 17 开始,无需显式提供 NULL

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)

提供不存在的 SLRU 缓存的名称

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

分类

内存服务器统计信息系统函数

另请参阅

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

反馈

提交关于 "pg_stat_reset_slru()" 的任何评论、建议或更正 此处