安装postgresQL Query Cache

 为了提高公司postgreSQL的读能力,需要加一个Query Cache,目前网上有一个安装资料,这总结下安装和使用的简单方式。

这里给出网上已有的架构图:

现在都是扩展名为rpm的文件,我是在linux(64位)的机器上装,下载了4个相关包如下:

uqc-libevent-1.4.14b-1.x86_64.rpm
uqc-libmemcached-0.43-1.x86_64.rpm
uqc-memcached-1.4.5-1.x86_64.rpm
uqc-querycache-20110223-1.x86_64.rpm

安装是有顺序的,uqc-libmemcached-0.43-1.x86_64.rpm依赖于uqc-memcached-1.4.5-1.x86_64.rpm的。

使用命令:

rpm -ivh *.rpm

安装,默认的安装目录如图:

 进入到etc目录下,有两个文件:pqcd.conf 和pqcd_hba.conf。前者是Query Cache的配置信息,后者是设置远程登录验证配置信息。

启动pqcd:

/opt/uptime/querycache/bin/pqcd

关闭pqcd:

/opt/uptime/querycache/bin/pqcd stop

 

如何使用Query Cache,登录命令就是:

psql -U postgres test -p 9999

注意:登录时需要加上端口号(9999是Query Cache的默认端口号,在配置文件pqcd.conf里),这样才使用到Query Cache的功能。

然后,按照官方的例子操作,相关SQL语句即可。为了方便我转过来了。

Add as a comment at the beginning of SELECT statements

/* cache:refresh */ select * from ……

-<slash> <asterrisk> <space> <hint> <space> <asterisk> <slash>

 

cache:on (default in Active cache mode)

--Looks at the cache first. If not found, then executes on the backend, and puts the result into the cache.

 

cache:off(default in Passive cache mode)

--Doesn't  look at the cache first. Executes on the backend, and doesn't puts the result into the cache.

 

cache:refresh

--Doesn't look at the cache first. Executes on the backend,and puts the result into the cache.

 

cache:expire

--Invalidates query cache for specified statement.(Not implemented yet)

 

cache:expireall

--Invalidates all query cache.(Not implemented yet)

 

这里使用cache的时候要注意就是查询的结果已经缓存在Cache了,这时数据库里的数据被更新后,不会与Query Cache同步(即still an old value in the cache)。

这时如果是需要实时同步的话,是需要主动使用cache:refresh的select方式,重新将数据加载到cache里。

不过在pqcd.conf里,也有一个属性query_cache_expiration表示The timeout value for query cache expiration (in seconds, default is 30).

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值