Skip to content

Instantly share code, notes, and snippets.

@rafaelbernard
Last active August 29, 2015 14:07
Show Gist options
  • Save rafaelbernard/090a0ec9b219fa660092 to your computer and use it in GitHub Desktop.
Save rafaelbernard/090a0ec9b219fa660092 to your computer and use it in GitHub Desktop.
Tabelas com maior quantidade de registros em cache - PostgreSQL
SELECT d.datname, c.relname
, pg_size_pretty(count(*) * 8192) as buffered
, round(100.0 * count(*) / ( SELECT setting FROM pg_settings WHERE name='shared_buffers')::integer,1) AS buffers_percent
, round(100.0 * count(*) * 8192 / pg_relation_size(c.oid),1) AS percent_of_relation
FROM pg_class c
INNER JOIN pg_buffercache b ON b.relfilenode = c.relfilenode
INNER JOIN pg_database d ON (b.reldatabase = d.oid)
WHERE pg_relation_size(c.oid) > 0
GROUP BY c.oid, d.datname, c.relname
ORDER BY 4 DESC
LIMIT 10;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment