os: ubuntu 16.04
db: postgresql 9.6.8
pgpool-ii: 3.7.2
ip规划
192.168.56.92 node1
192.168.56.90 node2
192.168.56.119 nodevip
登录 pgpool-ii 的 9999 端口时,出现异常
# su - postgres
$ psql -h 127.0.0.1 -p 9999 -U postgres -d postgres
psql: ERROR: unable to read message length
DETAIL: message length (12) in slot 1 does not match with slot 0(8)
这错误让人摸不着头脑.
pool_hba.conf 的内容为
host all all 0.0.0.0/0 md5
pg_hba.conf 的内容为
# IPv4 local connections:
host all all 0.0.0.0/0 md5
后来才发现是因为两台机器的 pg_hba.conf 的 0.0.0.0/0 md5 前手动添加了一条 127.0.0.1/32 trust
两边的日志如下:
2019-04-15 14:57:16.935 CST,,,7697,"127.0.0.1:54304",5cb42b4c.1e11,1,"",2019-04-15 14:57:16 CST,,0,LOG,00000,"connection received: host=127.0.0.1 port=54304",,,,,,,,,""
2019-04-15 14:57:16.939 CST,"postgres","postgres",7697,"127.0.0.1:54304",5cb42b4c.1e11,2,"authentication",2019-04-15 14:57:16 CST,3/1623,0,LOG,00000,"connection authorized: user=postgres database=postgres",,,,,,,,,""
2019-04-15 14:57:16.940 CST,"postgres","postgres",7697,"127.0.0.1:54304",5cb42b4c.1e11,3,"idle",2019-04-15 14:57:16 CST,,0,LOG,00000,"disconnection: session time: 0:00:00.004 user=postgres database=postgres host=127.0.0.1 port=54304",,,,,,,,,"psql"
2019-04-15 14:57:16.880 CST,,,3227,"192.168.56.92:52346",5cb42b4c.c9b,1,"",2019-04-15 14:57:16 CST,,0,LOG,00000,"connection received: host=192.168.56.92 port=52346",,,,,,,,,""
从两台日志输出来看,pgpool 使用了 127.0.0.1:54304 去连接本地 127.0.0.1:5432,使用了 192.168.56.92:52346 去连接另外一台机器 192.168.90:5432.
看日志是一台机器通过了认证,另外一台机器没有通过认证.但是 pool_hba.conf 设置的全是 md5, 怎么也要有个密码提示.
在排查的过程中发现 pgpool.conf 的 backend_hostname0,backend_hostname1 如果设置为主机的hostname 会创建成到 127.0.0.1的连接,如下图:
去掉 pg_hba.conf 的条目 127.0.0.1/32 trust,就ok了.
$ psql -c "select pg_reload_conf();"
$ psql -h 192.168.56.92 -p 9999 -U postgres -d postgres
Password for user postgres:
看上去像是个bug. 有空使用下 pgpool-II 3.7.9,pgpool-II 4.0.4 这两个版本看看还会不会出现这个问题.
参考:
http://www.pgpool.net/docs/37/en/html/auth-pool-hba-conf.html
http://pgpool.net/mantisbt/view.php?id=405
https://dba.stackexchange.com/questions/94548/pgpool-ii-unable-to-read-message-length-between-two-network-interfaces
http://www.sraoss.jp/pipermail/pgpool-general/2015-March/003541.html
http://www.pgpool.net/mediawiki/index.php/Downloads
http://www.pgpool.net/mediawiki/index.php/FAQ