pg_buffercache 主要是用来查看pgsql数据库 shared_pool 的使用情况,注意:是查看使用情况
create extension pg_buffercache
;
select *
from pg_buffercache
;
SELECT name,setting,unit,current_setting(name)
FROM pg_settings
WHERE 1=1
and name='shared_buffers'
;
name | setting | unit | current_setting |
---|---|---|---|
shared_buffers | 16384 | 8kB | 128MB |
计算
select 16384*8/1024 = 128
;
?column? |
---|
true |
查看使用情况
select d.datname,
c.relname,
c.relkind,
count(*) as buffers
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())
where 1=1
group by d.datname,
c.relname,
c.relkind
order by d.datname,4 desc
;