Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pg_buffercache report #28

Open
NikolayS opened this issue Sep 29, 2018 · 2 comments
Open

pg_buffercache report #28

NikolayS opened this issue Sep 29, 2018 · 2 comments

Comments

@NikolayS
Copy link
Owner

proposal (quick and dirty draft):

with a as (
SELECT reldatabase, c.relname, count(*) AS buffers
FROM pg_buffercache b INNER JOIN pg_class c
ON b.relfilenode = pg_relation_filenode(c.oid)
GROUP BY 1, 2
ORDER BY 3 DESC
)
select *, sum(buffers) over ()
from a
order by buffers desc
limit 20;
@oleg9301
Copy link

oleg9301 commented Nov 8, 2019

Once more with pg_buffercashe(from pg pro)

SELECT c.relname,
  count(*) blocks,
  round( 100.0 * 8192 * count(*) / pg_table_size(c.oid) ) "% of rel",
  round( 100.0 * 8192 * count(*) FILTER (WHERE b.usagecount > 3) / pg_table_size(c.oid) ) "% hot" 
FROM pg_buffercache b
  JOIN pg_class c ON pg_relation_filenode(c.oid) = b.relfilenode
WHERE  b.reldatabase IN (
         0, (SELECT oid FROM pg_database WHERE datname = current_database())
       )
AND    b.usagecount is not null
GROUP BY c.relname, c.oid
ORDER BY 2 DESC
LIMIT 10;

@NikolayS
Copy link
Owner Author

thanks @oleg9301!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants