微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

安装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).

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐