PostgreSQL流复制参数max_wal_senders详解

前端之家收集整理的这篇文章主要介绍了PostgreSQL流复制参数max_wal_senders详解前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
环境:
Postgresql 9.2.4
主机:192.25.10.76
从机:192.25.10.71

做postgresql的流复制主从时,会遇到调整max_wal_sengers这个参数,官方文档对这个参数做了一个简要的说明(9.2.4比早先版本多了几句话并做了一些微调),但没有实际的例子。
1.参数说明
Specifies the maximum number of concurrent connections from standby servers or streaming base backup clients (i.e.,the maximum number of simultaneously running WAL sender processes). The default is zero,meaning replication is disabled. WAL sender processes count towards the total number of connections,so the parameter cannot be set higher than max_connections. This parameter can only be set at server start. wal_level must be set to archive or hot_standby to allow connections from standby servers.
也就是说,这个参数是在主机上设置的,是从机连接到主机的并发连接数之总和,所以这个参数是个正整型。默认值是0,也即默认没有流复制功能。该并发连接数从进程上看,就是各个wal sender进程数之和,可以通过ps -ef|grep senders来查看,所以该值不能超过系统的最大连接数(max_connections,该BUG在9.1.5被修复),可以允许超过实际的流复制用户数。该参数更改需要重启DB,比如我只配了一个从机:
[postgres@ndb2 database]$ ps -ef|grep sender
postgres 21257 21247  0 20:57 ?        00:00:00 postgres: wal sender process repuser 192.25.10.71(46161) streaming 0/4018ED8
postgres 22193 20949  0 23:02 pts/0    00:00:00 grep sender
2.异常情况
很多时候配置主从的时候会遗漏这个参数,或者没有设置正确(比如实际配的从机数超过设置的连接数),这个时候一般会报错 number of requested standby connections exceeds max_wal_senders (currently X): 备机上显示的日志异常:
2013-08-12 20:53:42.132 CST,8859,5208dad6.229b,1,2013-08-12 20:53:42 CST,FATAL,XX000,"could not connect to the primary server: FATAL:  number of requested standby connections exceeds max_wal_senders (currently 0)
",""
2013-08-12 20:53:47.137 CST,8861,5208dadb.229d,2013-08-12 20:53:47 CST,""
2013-08-12 20:53:52.142 CST,8862,5208dae0.229e,2013-08-12 20:53:52 CST,""
2013-08-12 20:53:57.148 CST,8864,5208dae5.22a0,2013-08-12 20:53:57 CST,"
主机上显示的日志异常:
receiver"
2013-08-12 20:43:26.937 CST,21064,"",5208d86e.5248,2013-08-12 20:43:26 CST,LOG,00000,"connection received: host=192.25.10.71 port=46085",""
2013-08-12 20:43:26.938 CST,"repuser","192.25.10.71:46085",2,"authentication",2/1195,"replication connection authorized: user=repuser",3,"startup",2/0,53300,"number of requested standby connections exceeds max_wal_senders (currently 0)","walreceiver"
2013-08-12 20:43:26.939 CST,4,"disconnection: session time: 0:00:00.002 user=repuser database= host=192.25.10.71 port=46085","wa
lreceiver"
2013-08-12 20:43:41.513 CST,21066,5208d87d.524a,2013-08-12 20:43:41 CST,"connection received: host=192.25.10.71 port=46086",""
2013-08-12 20:43:41.514 CST,"192.25.10.71:46086",2/1198,"walreceiver"
2013-08-12 20:43:41.515 CST,"disconnection: session time: 0:00:00.002 user=repuser database= host=192.25.10.71 port=46086","wa
lreceiver"
...
遇到如此问题,则需要检查postgresql.conf文件的max _wal_senders参数了。

3.参数生效
文档上说明需要重启DB使之生效,如果动态使之生效会报错如下:
[postgres@proxy1 ]$ psql
psql (9.2.4)
Type "help" for help.

postgres=# show max_wal_senders ;
 max_wal_senders 
-----------------
 0
(1 row)

postgres=# set max_wal_senders=1;
ERROR:  parameter "max_wal_senders" cannot be changed without restarting the server
postgres=#

参考:
http://www.postgresql.org/docs/9.2/static/runtime-config-replication.html
http://www.pablowe.net/2012/08/postgresql-9-1-max_wal_senders-the-missing-documentation/

原文链接:https://www.f2er.com/postgresql/196123.html

猜你在找的Postgre SQL相关文章