O'Reilly logo
  • Zak Fortier thinks this is interesting:

SELECT schemaname,
relname,
indexrelname,
idx_scan,
pg_size_pretty(pg_relation_size(indexrelid)),
pg_size_pretty(sum(pg_relation_size(indexrelid))
OVER (ORDER BY idx_scan, indexrelid)) AS total
FROM pg_stat_user_indexes
ORDER BY 6 ;

From

Cover of Mastering PostgreSQL 9.6

Note

There should not be an ORDER BY clause on this query. As it is written this will lexically sort the output on the cumulative total column, which kind of defeats the purpose. Leaving out the ORDER BY lets it sort numerically.