This article is half-done without your Comment! *** Please share your thoughts via Comment ***
In this post, I am sharing a script to find the size and usage statistics of Greenplum Indexes. Having the complete knowledge of our database indexes is imperative. We should check the size and usage of indexes.
Recently, I started my work with Greenplum which based on PostgreSQL 8.2, so I am sharing a script to check index usage in Greenplum.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
SELECT t.schemaname AS schema_name ,t.tablename AS table_name ,indexname AS index_name ,c.reltuples AS num_rows ,pg_size_pretty(pg_relation_size(quote_ident(t.tablename)::text)) AS table_size ,pg_size_pretty(pg_relation_size(quote_ident(indexrelname)::text)) AS index_size ,CASE WHEN indisunique THEN 'Y' ELSE 'N' END AS UNIQUE ,idx_scan AS number_of_scans ,idx_tup_read AS tuples_read ,idx_tup_fetch AS tuples_fetched FROM pg_tables t LEFT OUTER JOIN pg_class c ON t.tablename=c.relname LEFT OUTER JOIN ( SELECT c.relname AS ctablename, ipg.relname AS indexname, x.indnatts AS number_of_columns, idx_scan, idx_tup_read, idx_tup_fetch, indexrelname, indisunique FROM pg_index x JOIN pg_class c ON c.oid = x.indrelid JOIN pg_class ipg ON ipg.oid = x.indexrelid JOIN pg_stat_all_indexes psai ON x.indexrelid = psai.indexrelid ) AS t1 ON t.tablename = t1.ctablename; |