重庆思庄Oracle、Redhat认证学习论坛
标题: PG 如何主动把表放入缓冲区? [打印本页]
作者: 郑全 时间: 2024-10-7 17:01
标题: PG 如何主动把表放入缓冲区?
如题,对如此问题,我们可以使用 一个叫 pg_prewarm 的插件来实现,不过,该插件,需要我们手工创建,下面具体举例。1.创建 pg_prewarm 扩展
create extensionpg_prewarm;
2.创建缓冲区使用查看视图
当然,前提是创建 pg_buffercache 扩展的
create view pg_buffercache_v as
select bufferid,
(select c.relname
from pg_class c
where pg_relation_filenode(c.oid) = b.relfilenode
) relname,
case relforknumber
when 0 then 'main'
when 1 then 'fsm'
when 2 then 'vm'
end relfork,
relblocknumber,
isdirty,
usagecount
from pg_buffercache b
where b.reldatabase in (0,(select oid from pg_database where datname=current_database()))
and b.usagecount is not null;
3.查看某表
select * frompg_buffercache_v where relname = 'test';
如果没有执行这个表,这个表是不在缓冲区里面
4.加入缓冲区
select pg_prewarm('test');
5.确认已经加入缓冲区
select * frompg_buffercache_v where relname = 'test';
bufferid | relname | relfork |relblocknumber | isdirty | usagecount
----------+---------+---------+----------------+---------+------------
303 | test | main | 0 | f | 1
304 | test | main | 1 | f | 1
305 | test | main | 2 | f | 1
欢迎光临 重庆思庄Oracle、Redhat认证学习论坛 (http://bbs.cqsztech.com/) |
Powered by Discuz! X3.2 |