【问题标题】:Postgresql performance - Index page hitsPostgresql 性能 - 索引页面命中
【发布时间】:2017-10-02 15:47:38
【问题描述】:

我运行以下查询来估计从内存读取的索引页(缓冲区命中)与从磁盘读取的索引页的比率

select
    t.schemaname, 
    t.relname as "Table Name", 
    io_i.indexrelname as "Index Name", 
    case when (io_i.idx_blks_hit <> 0 or io_i.idx_blks_read <> 0) then 
    round(io_i.idx_blks_hit/(io_i.idx_blks_hit::numeric + 
    io_i.idx_blks_read::numeric), 4) else null end as "Index Hit Ratio" 
from 
    pg_stat_user_tables t
    join pg_statio_user_indexes io_i on io_i.relid = t.relid 
order by "Index Hit Ratio" desc;

而且我有几个指数的比率太低(低于 0.7)。 请告知可能的原因以及如何改进它。

【问题讨论】:

    标签: postgresql performance database-indexes database-tuning


    【解决方案1】:

    shared_buffers 不够大,无法包含所有索引,因此查询会访问磁盘(或文件系统缓存,这没关系)。

    可能是这些索引不经常使用,所以 PostgreSQL 不让它们缓存是有意义的。检查 pg_stat_user_indexes 视图中的 idx_scan 以查看自上次统计信息重置后索引的扫描频率。

    如果您可以将shared_buffers 设置得足够高以包含整个数据库,请执行此操作。否则,read the manual 对设置 shared_buffers 有一些建议。

    除此之外,只要性能好并且 I/O 系统没有过载,我不会做任何事情。如果遇到问题,请尝试获取更多 RAM。如果该选项已用尽,请获得更快的存储空间。

    【讨论】:

    • 非常感谢。您的建议非常有帮助,因为我们确实经常遇到高达 100% 的 I/O 利用率峰值。
    猜你喜欢
    • 2020-04-23
    • 1970-01-01
    • 1970-01-01
    • 2013-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多