Last active
July 2, 2022 13:04
-
-
Save zhjwpku/76515eadc0c0137e2ff2f26b3cf2a3af to your computer and use it in GitHub Desktop.
pg_buffercache usage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create extension pg_buffercache; | |
-- 查看哪个数据库占用的缓存最多 | |
select datname, count(*), count(*) filter (where isdirty = true) as dirty | |
from pg_buffercache as b, pg_database as d | |
where d.oid = b.reldatabase | |
group by rollup (1); | |
-- 查看指定数据库中哪张表占用的缓存最多 | |
select relname, relkind, count(*), count(*) filter (where isdirty = true) as dirty | |
from pg_buffercache as b, pg_database as d, pg_class as c | |
where d.oid = b.reldatabase and c.relfilenode = b.relfilenode and datname = 'postgres' | |
group by 1, 2 | |
order by 3 desc | |
limit 10; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment