天天看點

對pg_buffercache 的利用實驗

先看有沒有髒資料:

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';

為f 的個數是180, 為t的個數仍然為零。

postgres=# select count(*) from pg_buffercache;

4096

有一部分資料是空的。這可能象征着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

17

postgres=# select c.relname from pg_buffercache b, pg_class c where b.relfilenode=c.relfilenode and b.isdirty='t';

relname 

postgres=# select c.relname from pg_buffercache b, pg_class c where b.relfilenode=c.relfilenode;

-----------------------------------

pg_statistic

pg_amop_fam_strat_index

pg_amop_opr_fam_index

pg_amproc_fam_proc_index

pg_aggregate_fnoid_index

pg_cast_source_target_index

testtab

pg_index_indrelid_index

pg_index_indexrelid_index

pg_operator_oid_index

.....

再來修改資料,看髒資料有否:

postgres=# select * from testtab;

id | val 

----+-------

1 | 12345

postgres=# update testtab set val='45678' where id=1;

UPDATE 1

postgres=#

髒資料确實産生了。

本文轉自健哥的資料花園部落格園部落格,原文連結:http://www.cnblogs.com/gaojian/archive/2012/10/25/2738682.html,如需轉載請自行聯系原作者

繼續閱讀