Created
September 15, 2023 09:18
-
-
Save Jeetah/58c78442902a6b36641f9505874ad67c to your computer and use it in GitHub Desktop.
Analyze Postgres index usage
This file contains 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) percent_of_times_index_used, | |
n_live_tup rows_in_table | |
FROM | |
pg_stat_user_tables | |
WHERE | |
seq_scan + idx_scan \> 0 | |
ORDER BY | |
n_live_tup DESC; | |
SELECT | |
sum(idx_blks_read) as idx_read, | |
sum(idx_blks_hit) as idx_hit, | |
(sum(idx_blks_hit) - sum(idx_blks_read)) / sum(idx_blks_hit) as ratio | |
FROM | |
pg_statio_user_indexes; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment