安装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的。 使用命令: 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). (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |