PHP实战中知识总结 / PgSQL - pg_statio_all_tables(系统表)

pg_statio_all_tables视图将为当前数据库中的每个表(包括 TOAST 表)包含一行,该行显示指定表上有关 I/O 的统计信息。pg_statio_user_tables和pg_statio_sys_tables视图包含相同的信息,但是被过滤得分别只显示用户表和系统表。

列名示例值说明
relid16390表的OID
schemanamepublic模式名
relnamepgbench_accounts表名
heap_blks_read414012从磁盘中读入表的块数
idx_heap_blks_hit44710713指在shared_buffer中命中表的块数
idx_blks_read67997从磁盘中读入索引的块数
idx_blks_hit89424015在shared_buffer中命中的索引的块数
toast_blks_read从磁盘中读入toast表的块数
toast_blks_hit指在shared_buffer中命中toast表的块数
tidx_blks_read从磁盘中读入toast表索引的块数
tidx_blks_hit指在shared_buffer中命中toast表索引的块数

如果heap_blks_read、idx_blks_read很高,说明shared buffer较小,存在频繁从磁盘或者page cache读取到shared buffer中命中toast表的块数

postgres=# select * from pg_statio_user_tables;
relid | schemaname | relname | heap_blks_read | heap_blks_hit | idx_blks_read | idx_blks_hit | toast_blks_read | toast_blks_hit | tidx_blks_read | tidx_blks_hit
-------+------------+---------+----------------+---------------+---------------+--------------+-----------------+----------------+----------------+---------------
16532 | public   | goods  |       21 |     3164 |      10 |     3644 |        0 |       0 |       1 |       1
16384 | public   | test  |      1303 |    118098 |     1069 |    434292 |         |        |        |
16391 | public   | alerts |     230130 |    1365837 |     35401 |   20835500 |        0 |       0 |       1 |       1
(3 rows)

PHP实战中知识总结