pg_stat_reset_slru()
是一个系统函数,用于重置由 pg_stat_slru
视图显示的 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()
。
变更历史
- PostgreSQL 17
- PostgreSQL 13
- 已添加 (提交 28cac71b)
示例
给定以下状态的 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)
参考文献
- PostgreSQL 文档: 其他统计函数