Skip to content

Instantly share code, notes, and snippets.

View cank's full-sized avatar

Spencer Thiel cank

  • PagerDuty
  • Los Angeles
View GitHub Profile
@cank
cank / gist:ce64e8ab298e0b53154a8dfd1734042a
Created September 14, 2018 18:41
postgres table hits
-- perform a "select pg_stat_reset();" when you want to reset counter statistics
with
all_tables as
(
SELECT *
FROM (
SELECT 'all'::text as table_name,
sum( (coalesce(heap_blks_read,0) + coalesce(idx_blks_read,0) + coalesce(toast_blks_read,0) + coalesce(tidx_blks_read,0)) ) as from_disk,
sum( (coalesce(heap_blks_hit,0) + coalesce(idx_blks_hit,0) + coalesce(toast_blks_hit,0) + coalesce(tidx_blks_hit,0)) ) as from_cache
FROM pg_statio_all_tables --> change to pg_statio_USER_tables if you want to check only user tables (excluding postgres's own tables)