且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

对pg_buffercache 的利用实验

更新时间:2022-09-16 16:41:31

先看有没有脏数据:

postgres=# select isdirty from pg_buffercache where isdirty='t';
isdirty 
---------
(0 rows)

此时尚未有脏数据。

进一步确认:

postgres=# select count(*) from pg_buffercache where isdirty='f';
count 
-------
180
(1 row)

postgres=# select count(*) from pg_buffercache where isdirty='t';
count 
-------
0
(1 row)

为f 的个数是180, 为t的个数仍然为零。

postgres=# select count(*) from pg_buffercache;
count 
-------
4096
(1 row)

有一部分数据是空的。这可能象征着buffer中尚未被使用的数据区域。

建表,插入数据, 再看有没有脏数据,这是有了17条。

但是一旦关联 pg_class, 发现一条也无,估计是一些内部数据,暂时不理:

postgres=# create table testtab(id integer, val varchar(10));
CREATE TABLE
postgres=# insert into testtab values(1,'12345');
INSERT 0 1
postgres=# select count(*) from pg_buffercache where isdirty='t';
count 
-------
17
(1 row)

 


postgres=# select c.relname from pg_buffercache b, pg_class c where b.relfilenode=c.relfilenode and b.isdirty='t';
relname 
---------
(0 rows)

postgres=# select c.relname from pg_buffercache b, pg_class c where b.relfilenode=c.relfilenode;
relname 
-----------------------------------
pg_statistic
pg_statistic
pg_amop_fam_strat_index
pg_amop_fam_strat_index
pg_amop_fam_strat_index
pg_amop_opr_fam_index
pg_amop_opr_fam_index
pg_amop_opr_fam_index
pg_amproc_fam_proc_index
pg_amproc_fam_proc_index
pg_amproc_fam_proc_index
pg_aggregate_fnoid_index
pg_aggregate_fnoid_index
pg_cast_source_target_index
pg_cast_source_target_index
testtab
pg_index_indrelid_index
pg_index_indrelid_index
pg_index_indexrelid_index
pg_index_indexrelid_index
pg_operator_oid_index

.....

再来修改数据,看脏数据有否:

postgres=# select * from testtab;
id | val 
----+-------
1 | 12345
(1 row)

postgres=# update testtab set val='45678' where id=1;
UPDATE 1
postgres=# select c.relname from pg_buffercache b, pg_class c where b.relfilenode=c.relfilenode and b.isdirty='t';
relname 
---------
testtab
(1 row)

postgres=#

脏数据确实产生了。







本文转自健哥的数据花园博客园博客,原文链接:http://www.cnblogs.com/gaojian/archive/2012/10/25/2738682.html,如需转载请自行联系原作者