Created
September 13, 2019 09:05
-
-
Save unavailabl3/ca63a8b7bc101b8ab3754fa180ef7c1d to your computer and use it in GitHub Desktop.
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 | |
idstat.relname AS TABLE_NAME, -- имя таблицы | |
indexrelname AS index_name, -- индекс | |
idstat.idx_scan AS index_scans_count, -- число сканирований по этому индексу | |
pg_size_pretty(pg_relation_size(indexrelid)) AS index_size, -- размер индекса | |
tabstat.idx_scan AS table_reads_index_count, -- индексных чтений по таблице | |
tabstat.seq_scan AS table_reads_seq_count, -- последовательных чтений по таблице | |
tabstat.seq_scan + tabstat.idx_scan AS table_reads_count, -- чтений по таблице | |
n_tup_upd + n_tup_ins + n_tup_del AS table_writes_count, -- операций записи | |
pg_size_pretty(pg_relation_size(idstat.relid)) AS table_size -- размер таблицы | |
FROM | |
pg_stat_user_indexes AS idstat | |
JOIN | |
pg_indexes | |
ON | |
indexrelname = indexname | |
AND | |
idstat.schemaname = pg_indexes.schemaname | |
JOIN | |
pg_stat_user_tables AS tabstat | |
ON | |
idstat.relid = tabstat.relid | |
WHERE | |
indexdef !~* 'unique' | |
ORDER BY | |
idstat.idx_scan DESC, | |
pg_relation_size(indexrelid) DESC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment