PostgreSQL pg_stat_all_tables pg_stat_sys_tables 和 pg_stat_user_tables 统计数据表相关信息

PostgreSQL About 1,921 words

区别

pg_stat_all_tables:统计数据库中所有表的信息。

pg_stat_sys_tables:统计数据库中系统表的信息。

pg_stat_user_tables:统计数据库中用户自定义表的信息。

含义

字段名称 类型 描述
relid oid 表的对象ID。
schemaname name 表所属的模式名。
relname name 表的名称。
seq_scan bigint 表上顺序扫描的次数。
seq_tup_read bigint 顺序扫描读取的元组数。
idx_scan bigint 表上的索引扫描次数。
idx_tup_fetch bigint 索引扫描返回的元组数。
n_tup_ins bigint 插入到表中的元组数。
n_tup_upd bigint 更新到表中的元组数。
n_tup_del bigint 从表中删除的元组数。
n_tup_hot_upd bigint 表中不需要索引重新指向 tuple 的“热点”更新数。
n_live_tup bigint 表中活跃的(当前有效的)元组数。
n_dead_tup bigint 表中死掉的(无效的)元组数。
n_mod_since_analyze bigint 自从上次 ANALYZE 以来表中修改过的元组数。
last_vacuum timestamp with time zone 表上最后一次手动 VACUUM 的时间。
last_autovacuum timestamp with time zone 表上最后一次自动 VACUUM 的时间。
last_analyze timestamp with time zone 表上最后一次手动 ANALYZE 的时间。
last_autoanalyze timestamp with time zone 表上最后一次自动 ANALYZE 的时间。
vacuum_count bigint 表上手动和自动 VACUUM 的次数。
autovacuum_count bigint 表上自动 VACUUM 的次数。
analyze_count bigint 表上手动和自动 ANALYZE 的次数。
autoanalyze_count bigint 表上自动 ANALYZE 的次数。

示例

select * from pg_stat_user_tables;

输出

postgres=# select * from pg_stat_user_tables;
-[ RECORD 1 ]-------+------------------------------
relid               | 30354
schemaname          | public
relname             | pgbench_accounts_4
seq_scan            | 2
seq_tup_read        | 200000
idx_scan            | 39223
idx_tup_fetch       | 238551
n_tup_ins           | 200000
n_tup_upd           | 19611
n_tup_del           | 0
n_tup_hot_upd       | 16293
n_live_tup          | 200000
n_dead_tup          | 3336
n_mod_since_analyze | 19611
n_ins_since_vacuum  | 0
last_vacuum         | 2025-02-08 08:40:00.088113+00
last_autovacuum     |
last_analyze        | 2025-02-08 08:40:00.259183+00
last_autoanalyze    |
vacuum_count        | 1
autovacuum_count    | 0
analyze_count       | 1
autoanalyze_count   | 0

官方文档

https://www.postgresql.org/docs/17/monitoring-stats.html#MONITORING-PG-STAT-ALL-TABLES-VIEW

Views: 228 · Posted: 2025-02-11

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

扫描下方二维码关注公众号和小程序↓↓↓

扫描下方二维码关注公众号和小程序↓↓↓


Today On History
Browsing Refresh