Guest User

Untitled

a guest
Sep 26th, 2016
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. -- Index hit rate
  2. WITH idx_hit_rate as (
  3. SELECT
  4. relname as table_name,
  5. n_live_tup,
  6. round(100.0 * idx_scan / (seq_scan + idx_scan),2) as idx_hit_rate
  7. FROM pg_stat_user_tables
  8. ORDER BY n_live_tup DESC
  9. ),
  10.  
  11. -- Cache hit rate
  12. cache_hit_rate as (
  13. SELECT
  14. relname as table_name,
  15. heap_blks_read + heap_blks_hit as reads,
  16. round(100.0 * sum (heap_blks_read + heap_blks_hit) over (ORDER BY heap_blks_read + heap_blks_hit DESC) / sum(heap_blks_read + heap_blks_hit) over (),4) as cumulative_pct_reads,
  17. round(100.0 * heap_blks_hit / (heap_blks_hit + heap_blks_read),2) as cache_hit_rate
  18. FROM pg_statio_user_tables
  19. WHERE heap_blks_hit + heap_blks_read > 0
  20. ORDER BY 2 DESC
  21. )
  22.  
  23. SELECT
  24. idx_hit_rate.table_name,
  25. idx_hit_rate.n_live_tup as size,
  26. cache_hit_rate.reads,
  27. cache_hit_rate.cumulative_pct_reads,
  28. idx_hit_rate.idx_hit_rate,
  29. cache_hit_rate.cache_hit_rate
  30. FROM idx_hit_rate, cache_hit_rate
  31. WHERE idx_hit_rate.table_name = cache_hit_rate.table_name
  32. AND cumulative_pct_reads < 100.0
  33. ORDER BY reads DESC;
Add Comment
Please, Sign In to add comment