Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

表视图——pg_stat/ratio_user_tables

  • pg_stat_user_tables 视图

    SELECT *
    FROM pg_stat_user_tables;
    
    • 查看每一个表的历史总体情况
    • 整体信息
      • relid 表的oid
      • schemaname 模式名(一般是public)
      • relname 表的名字
    • 扫描相关
      • seq_scan 该表通过 全表扫描 的总次数
        • 如果值很高(相对于 idx_scan ),说明存在大量全表
      • seq_tup_read 该表通过 全表扫描 的总行数
      • idx_scan 该表通过 索引扫描返回 的总次数
      • idx_tup_fetch 该表通过 索引扫描返回 的总行数
    • 行数相关
      • n_tup_ins 插入 的行数
      • n_tup_upd 更新 的行数
      • n_tup_del 删除 的行数
      • n_tup_hot_upd 热更新 的行数
        • 这个值与 n_tup_upd 相近最好,代表不需要更新索引,性能好
      • n_live_tup 活的行数量
      • n_dead_tup 死的行数量
      • n_mod_since_analyze 上次 analyze分析以来 修改的行数
    • 时间信息
      • last_vacuum 上次 手动vacuum 的时机
      • last_autovacuum 上次 自动vacuum 的时机
      • last_analyze 上次 手动analyze 的时机
      • last_autoanalyze 上次 自动analyze 的时机
  • pg_statio_user_tables 视图

    SELECT *
    FROM pg_statio_user_tables;
    
    • 查看每一个表的详细磁盘读取情况
    • 整体信息
      • relid 表的oid
      • schemaname 模式名(一般是public)
      • relname 表的名字
    • 堆读取信息
      • heap_blks_read 从 page cache 或 磁盘 读取的块数
        • 如果值很高,说明 shared buffer 较小,需要频繁从磁盘读取
      • heap_blks_hit 从 shared buffer 命中的块数
    • 索引读取信息
      • idx_blks_read 从 page cache 或 磁盘 读取的索引块数
        • 如果值很高,说明 shared buffer 较小,需要频繁从磁盘读取
      • idx_blks_hit 从 shared buffer 命中的索引块数
    • toast读取信息
      • toast_blks_read 从 page cache 或 磁盘 读取toast表的块数
      • toast_blks_hit 从 shared buffer 命中toast表的块数
    • toast索引读取信息
      • tidx_blks_read 从 page cache 或 磁盘 读取的toast表索引块数
      • tidx_blks_hit 从 shared buffer 命中的toast表索引块数