Skip to content

Instantly share code, notes, and snippets.

@bfolkens
Created September 23, 2019 22:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bfolkens/9e72ab25ae41f2a552720502b0e2f048 to your computer and use it in GitHub Desktop.
Save bfolkens/9e72ab25ae41f2a552720502b0e2f048 to your computer and use it in GitHub Desktop.
Show Postgres buffer sizes
CREATE EXTENSION pg_buffercache;
SELECT 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,
round(100.0 * count(*) * 8192 / pg_table_size(c.oid),1) AS percent_of_table
FROM pg_class c
INNER JOIN pg_buffercache b
ON b.relfilenode = c.relfilenode
INNER JOIN pg_database d
ON (b.reldatabase = d.oid AND d.datname = current_database())
GROUP BY c.oid,c.relname
ORDER BY 3 DESC
LIMIT 10;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment