-
-
Save tommy-muehle/e7c1ae397b614efb9ff29be5aab0bae6 to your computer and use it in GitHub Desktop.
PostgreSQL Index Usage Analysis
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 AS TableName, | |
to_char(seq_scan, '999,999,999,999') AS TotalSeqScan, | |
to_char(idx_scan, '999,999,999,999') AS TotalIndexScan, | |
to_char(n_live_tup, '999,999,999,999') AS TableRows, | |
pg_size_pretty(pg_relation_size(relname :: regclass)) AS TableSize | |
FROM pg_stat_all_tables | |
WHERE schemaname = 'public' | |
AND 50 * seq_scan > idx_scan -- more then 2% | |
AND n_live_tup > 10000 | |
AND pg_relation_size(relname :: regclass) > 5000000 | |
ORDER BY relname ASC; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment