查看缓冲区缓存的内容:
create extension pg_buffercache;

select c.relname, count(1) as buffers from pg_class c join pg_buffercache b on b.relfilenode=c.relfilenode inner join pg_database d on (b.reldatabase=d.oid and d.datname=current_database()) group by c.relname order by 2 desc;
-[ RECORD 1 ]------------------------------
relname | pg_depend_reference_index
buffers | 12
-[ RECORD 2 ]------------------------------
relname | pg_depend
buffers | 10
-[ RECORD 3 ]------------------------------
relname | pg_rewrite
buffers | 6
-[ RECORD 4 ]------------------------------
relname | pg_extension
buffers | 5
-[ RECORD 5 ]------------------------------
relname | pg_init_privs
buffers | 5
-[ RECORD 6 ]------------------------------
relname | pg_statistic
buffers | 5
-[ RECORD 7 ]------------------------------
relname | pg_amop
buffers | 5
-[ RECORD 8 ]------------------------------
relname | pg_operator_oprname_l_r_n_index
buffers | 5
-[ RECORD 9 ]------------------------------
relname | pg_depend_depender_index
buffers | 5

缓存的都是数据字典视图。

排除掉此类视图 :

select c.relname, count(1) as buffers from pg_class c 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 c.relname not like 'pg%' group by c.relname order by 2 desc;

 relname | buffers
---------+---------
(0 rows)

创建自己的表,然后插入记录:
create table test(id numeric,name text);

insert into test values(1,'dxmy');
test=# select * from test;
 id | name
----+------
  1 | dxmy
(1 row)

然后再查询:
test=# select c.relname,b.isdirty, count(1) as buffers from pg_class c 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 c.relname not like 'pg%' group by c.relname,b.isdirty order by 2 desc;
 relname | isdirty | buffers
---------+---------+---------
 test    | t       |       1
(1 row)

发现我们新建的表及插入的数据缓存了:
其中,isdirty是f,意思就是不脏,来修改一下:
update test set id=2;
test=# update test set id=2;
UPDATE 1

再查一次:
test=# select c.relname,b.isdirty, count(1) as buffers from pg_class c 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 c.relname not like 'pg%' group by c.relname,b.isdirty order by 2 desc;
 relname | isdirty | buffers
---------+---------+---------
 test    | t       |       1
(1 row)

isdirty变为了t,说明是脏数据了。
来个检查点:
test=# checkpoint;
CHECKPOINT

再查一次:
test=# select c.relname,b.isdirty, count(1) as buffers from pg_class c 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 c.relname not like 'pg%' group by c.relname,b.isdirty order by 2 desc;
 relname | isdirty | buffers
---------+---------+---------
 test    | f       |       1
(1 row)

又不脏了。

有兴趣可以自己做实验玩。

pg_buffercache的更多相关文章

  1. 使用pg_buffercache查看缓存区缓存

    PG提供了一个扩展pg_buffercache来查看缓存区的内容. create database test; CREATE DATABASE create extension pg_bufferca ...

  2. postgres安装pg_buffercache扩展

    1.查看是否安装了pg_buffercache postgres=# \dx List of installed extensions Name | Version | Schema | Descri ...

  3. ERROR: relation "pg_buffercache" does not exist

    创建pg_buffercache后,查询时报错: postgres=# create extension pg_buffercache; postgres=# select * from pg_buf ...

  4. PostgreSQL 磁盘使用大小监控

    表大小信息 postgres=# SELECT *, pg_size_pretty(total_bytes) AS totalpostgres-# , pg_size_pretty(index_byt ...

  5. pg 资料大全1

    https://github.com/ty4z2008/Qix/blob/master/pg.md?from=timeline&isappinstalled=0 PostgreSQL(数据库) ...

  6. 在CentOS上编译安装PostgreSQL

    http://my.oschina.net/tashi/blog 第一步:准备阶段 获取必需软件包: CentOS中查看是否安装了某个软件的命令:rpm -qa | grep 软件名.which命令可 ...

  7. 深入理解Postgres中的cache

    众所周知,缓存是提高数据库性能的一个重要手段.本文着重讲一讲PostgreSQL中的缓存相关的东西.当然万变不离其宗,原理都是共同的,理解了这些,你也很容易把它运用到其它数据库中. What is a ...

  8. # postgresql-shared_buffers

    关于shared_buffers 什么是shred_buffer,我们为什么需要shared_buffers? 1.在数据库系统中,我们主要关注磁盘io,大多数oltp工作负载都是随机io,因此从磁盘 ...

  9. PostgreSQL 扩展开发基础教程

    搭建基础结构 安装扩展 sudo apt-get install postgresql-contribcreatedb stupsql stucreate extension pg_buffercac ...

随机推荐

  1. Django-form进阶+详细版

    Django的Form主要具有一下几大功能: 生成HTML标签 验证用户数据(显示错误信息) HTML Form提交保留上次提交数据 初始化页面显示内容 一.创建Form类 #!/usr/bin/en ...

  2. Python:virtualenv介绍

    virtualenv 在开发Python应用程序的时候,系统安装的Python3只有一个版本:3.4.所有第三方的包都会被pip安装到Python3的site-packages目录下. 如果我们要同时 ...

  3. mongodb-2.6.0 在win7 64下的安装和服务启动

    转自: http://blog.csdn.net/lingchen214/article/details/24537629 1   自定义安装到C:\mongodb目录下. 2  手动在C:\mong ...

  4. adas--智能驾驶辅助系统

    先进驾驶辅助系统(Advanced Driver AssistantSystem),简称ADAS,是利用安装于车上的各式各样的传感器(可侦测光.热.压力等变数), 在第一时间收集车内外的环境数据, 进 ...

  5. C#中ReferenceEquals和Equals的区别

    ReferenceEquals()判断两个字符串是否指向相同的内存地址:(判断引用) Equals,先判断两个字符串有相同的内存位置,是则两个字符串相等:否则逐字符比较两个字符串,判断是否相等(先判断 ...

  6. Windows 下c获取文件目录

    由于要插数据库,构建sql语句,需要文件名,在网上找了半天,无奈都是Linux下的专用函数,伤心,,还有那个下载URL ,还木搞好,就要走啦,心焦哇 #include<iostream> ...

  7. Ubuntu 14.04上架IPSec+L2TP的方法

    最简单的方法是使用脚本一步一步地进行配置.我用的是philplckthun写的脚本,修改了一下获取服务器IP的方法:脚本文件. 在ubuntu下运行: sh setup.sh 配置配置完成后,服务器端 ...

  8. Please make sure the TESSDATA_PREFIX environment variable is set to your "tessdata" directory.

    tesseract的一个操作问题,简单记录 类似坑尽量少踩 运行 .\tesseract.exe .\1356445914_9857.jpg tstimg  报错如下:Please make sure ...

  9. 安装MySQL 5.6

    记录安装mysql 5.6的全过程 下载安装包(尝试过使用mysql的yum源去安装--如果你的网络够好的话...) 注:我的系统是Centos 7.2的 如下,根据自己的需求去下载 CentOS L ...

  10. Windows Server 2008 R2服务器遗忘管理员密码解决方案

     A goal is a dream with a deadline. Much effort, much prosperity.  在日常的工作中,对于一个网络管理员来讲最悲哀的事情莫过于在没有备用 ...