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

相关文章

项目需要,有个数据需要导入,拿到手一开始以为是mysql,结果...
本文小编为大家详细介绍“怎么查看PostgreSQL数据库中所有表...
错误现象问题原因这是在远程连接时pg_hba.conf文件没有配置正...
因本地资源有限,在公共测试环境搭建了PGsql环境,从数据库本...
wamp 环境 这个提示就是说你的版本低于10了。 先打印ph...
psycopg2.OperationalError: SSL SYSCALL error: EOF detect...