pg_prewarm模块可以方便的把相关的数据加载到系统的缓存或者是数据库的缓存中。在数据量大的情况下,内存中的数据可能会排出内存。
我们找一个测试表,里面有10万条数据:
postgres=#
select count(*) from test_prewarm;
count
--------
100000
(1 row)
把表加入到缓存:
postgres=#
select pg_prewarm('test_prewarm','buffer');
pg_prewarm
------------
637
(1 row)
查看缓存内的信息:
postgres=#
select * from pg_buffercache where relfilenode=pg_relation_filenode('test_prewarm');
bufferid | relfilenode | reltablespace | reldatabase | relforknumber | relblocknumber | isdirty | usagecount
----------+-------------+---------------+-------------+---------------+----------------+---------+------------
193 | 17771 | 1663 | 13003 | 0 | 636 | f | 5
194 | 17771 | 1663 | 13003 | 0 | 635 | f | 5
195 | 17771 | 1663 | 13003 | 0 | 634 | f | 5
196 | 17771 | 1663 | 13003 | 0 | 633 | f | 5
197 | 17771 | 1663 | 13003 | 0 | 632 | f | 5
198 | 17771 | 1663 | 13003 | 0 | 631 | f | 5
199 | 17771 | 1663 | 13003 | 0 | 630 | f | 5
省略多行...
831 | 17771 | 1663 | 13003 | 0 | 0 | f | 5
(639 rows)
接下来删除表,重建,不使用pg_prewarm将其加载到缓存中,再看一下缓存信息:
postgres=#
drop table test_prewarm;
DROP TABLE
postgres=#
create table test_prewarm (id int4,name character varying(64),creat_time timestamp(6) without time zone);
CREATE TABLE
postgres=#
insert into test_prewarm select generate_series(1,100000),generate_series(1,100000)|| '_pre',clock_timestamp();
INSERT 0 100000
postgres=#
select * from pg_buffercache where relfilenode=pg_relation_filenode('test_prewarm');
bufferid | relfilenode | reltablespace | reldatabase | relforknumber | relblocknumber | isdirty | usagecount
----------+-------------+---------------+-------------+---------------+----------------+---------+------------
(0 rows)
可以看到缓存中无任何数据信息。
阅读(5317) | 评论(0) | 转发(0) |