PostgreSQL Memory for Database Caching(2)

Inspecting the database cache

想让postgresQL 使用shared_buffers database cache ,需要使用pg_buffercache module,这是一个contrib里的可选模块。

Installing pg_buffercache into a database

In order to install this utility or to use it, you will need to be connected to the database as its superuser. Here's a sample that installs pg_buffercache into a new database, presuming the RedHat Linux standard directory installation tree; substitute your own PostgreSQL installation directory here:
$ createdb pgbench
$ psql -d pgbench -f /usr/share/postgresql/contrib/pg_buffercache.sql
注意:在8.x和9.x里都没有pg_buffercache.sql,需要从网上去下载。
安装此sql后,就可以在客户端上查看相关的share memory信息。SQL语句如下:
SELECT name,setting,unit,current_setting(name) FROM pg_settings WHERE name='shared_buffers';
或者
select count(*) from pg_buffercache;

Database disk layout

In order to fully interpret the information returned by utilities such as pg_buffercahe,and therefore use that information to adjust memory sizing,
it's helpful to know a bit about how databases are stored on disk.
使用SQL命令:
show data_directory;
就可以知道数据存放的路径
如果想查看其他文件的存放路径,命令如图:


在data目录下面有一个base目录。
base目录下的内容如图:

 这个目录下的数字术语叫 object identifier or OID.这个标识是唯一的。

这些ID对应一个数据库,如果想知道映射关系,你也可以用SQL语句来查看,命令如图:

补充下,如果查询表的相关信息,是pg_class这张表,SQL就省略了。

你也可以在命令行里查看,命令如图:


Creating a new block in a database

Once you insert something into this table, a page is allocated in the buffer cache to hold that new information, and a standard 8K block is allocated on disk.








  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值