pg_stat_recovery_prefetch
是一个 统计视图,显示备机在恢复期间预取WAL块的信息。
pg_stat_recovery_prefetch
在 PostgreSQL 15 中添加。
用法
WAL预取默认情况下是禁用的,必须通过将recovery_prefetch
设置为 on
来启用。它仅在提供有效的 posix_fadvise
操作系统级函数的系统上可用。
按PostgreSQL版本定义
pg_stat_recovery_prefetch (PostgreSQL 17)
View "pg_catalog.pg_stat_recovery_prefetch" Column | Type | Collation | Nullable | Default ----------------+--------------------------+-----------+----------+--------- stats_reset | timestamp with time zone | | | prefetch | bigint | | | hit | bigint | | | skip_init | bigint | | | skip_new | bigint | | | skip_fpw | bigint | | | skip_rep | bigint | | | wal_distance | integer | | | block_distance | integer | | | io_depth | integer | | |
pg_stat_recovery_prefetch (PostgreSQL 16)
View "pg_catalog.pg_stat_recovery_prefetch" Column | Type | Collation | Nullable | Default ----------------+--------------------------+-----------+----------+--------- stats_reset | timestamp with time zone | | | prefetch | bigint | | | hit | bigint | | | skip_init | bigint | | | skip_new | bigint | | | skip_fpw | bigint | | | skip_rep | bigint | | | wal_distance | integer | | | block_distance | integer | | | io_depth | integer | | |
pg_stat_recovery_prefetch (PostgreSQL 15)
View "pg_catalog.pg_stat_recovery_prefetch" Column | Type | Collation | Nullable | Default ----------------+--------------------------+-----------+----------+--------- stats_reset | timestamp with time zone | | | prefetch | bigint | | | hit | bigint | | | skip_init | bigint | | | skip_new | bigint | | | skip_fpw | bigint | | | skip_rep | bigint | | | wal_distance | integer | | | block_distance | integer | | | io_depth | integer | | |
变更历史
- PostgreSQL 15
- 添加 (提交 5dc0418f)
示例
当 recovery_prefetch
在备机上设置为 on
或 try
且满足其他先决条件时,pg_stat_recovery_prefetch
的内容
postgres=# SELECT * FROM pg_stat_recovery_prefetch\gx -[ RECORD 1 ]--+------------------------------ stats_reset | 2022-04-30 20:45:30.247883+01 prefetch | 25 hit | 676 skip_init | 733 skip_new | 14349 skip_fpw | 59 skip_rep | 186202 wal_distance | 0 block_distance | 0 io_depth | 0
当 recovery_prefetch
设置为 off
(禁用)或节点不是备机时,pg_stat_recovery_prefetch
的内容
postgres=# SELECT * FROM pg_stat_recovery_prefetch\gx -[ RECORD 1 ]--+------------------------------ stats_reset | 2022-04-30 20:45:26.440076+01 prefetch | 0 hit | 0 skip_init | 0 skip_new | 0 skip_fpw | 0 skip_rep | 0 wal_distance | 0 block_distance | 0 io_depth | 0
请注意,如果启用了 recovery_prefetch
然后又将其禁用,pg_stat_recovery_prefetch
将继续显示上次可用的统计信息,直到后端统计信息重置。
参考
- PostgreSQL 文档: pg_stat_recovery_prefetch