Created
April 22, 2014 12:29
-
-
Save mamachanko/11177082 to your computer and use it in GitHub Desktop.
SQL cache and index performance
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
'index hit rate' as name, | |
(sum(idx_blks_hit) - sum(idx_blks_read)) / | |
sum(idx_blks_hit + idx_blks_read) as ratio | |
FROM pg_statio_user_indexes | |
union all | |
SELECT | |
'cache hit rate' as name, | |
case sum(idx_blks_hit) | |
when 0 then 'NaN'::numeric | |
else to_char((sum(idx_blks_hit) - sum(idx_blks_read)) / sum(idx_blks_hit + idx_blks_read), '99.99')::numeric | |
end as ratio | |
FROM pg_statio_user_indexes; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
relname, | |
100 * idx_scan / (seq_scan + idx_scan) as percent_of_time_index_used, | |
n_live_tup as rows_in_table | |
FROM pg_stat_user_tables | |
WHERE idx_scan > 0 | |
ORDER BY n_live_tup DESC; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment