select
*
from
(
select
io_ut.relname,
ut.seq_scan,
ut.seq_tup_read,
case
when ut.seq_scan > 0 then ut.seq_tup_read / ut.seq_scan
else null
end as tup_per_read,
ut.n_live_tup,
case
when io_ut.heap_blks_read > 0 then round(io_ut.heap_blks_hit * 100 / (io_ut.heap_blks_hit + io_ut.heap_blks_read), 2)
else null
end as cache_hit_ratio
from
pg_statio_user_tables io_ut
left join pg_stat_user_tables ut on io_ut.relname = ut.relname
) h
order by
seq_scan desc
;