中午开发人员说PHP连接不上了,他的连接方式:
'connectionString' =>"pgsql:host=172.25.*.*;port=5432;dbname=test",'username' => 'develop','password' => 'develop'
捕捉到的报错信息:
PDOException Object ( [message:protected] => sqlSTATE[08006] [7] timeout expired[string:private] => [code:protected] => 7 [file:protected] => /home/shnx/bid.test.com/index.PHP [line:protected] => 3 [trace:private] => Array ( [0] => Array ( [file] => /home/shnx/bid.test.com/index.PHP [line] => 3 [function] => __construct [class] => PDO [type] => -> [args] => Array ( [0] => pgsql:host=localhost;port=5432;dbname=test [1] => develop [2] => develop ) ) ) [errorInfo] => )
LOG: could not receive data from client: Connection reset by peer
LOG: unexpected EOF on client connection
LOG: could not receive data from client: Connection reset by peer
LOG: unexpected EOF on client connection
先ping下服务器,是通的,再检查数据库是否有问题,使用psql本地登录:
[postgres@greentea]$ psql -U develop -d test psql (9.1.2) Type "help" for help. test=>
数据库是可以连接的。看到他的连接信息多了一项host连接,遂也加了测试,发现问题来了,一直卡在这里,也很难掐掉,最终会报错:
[postgres@greentea ~]$ psql -h localhost -U develop -d test psql: could not connect to server: 连接超时 Is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP connections on port 5432?
把localhost换成本地IP或者127.0.0.1结果都一样,hang在那里不动了。
此时测试了一下别的主机ping它,以及它ping别的主机都是正常的。但是 ping 127.0.0.1 或者 ping localhost 或者ping 自己的IP 却都是不通的,很奇怪。再检查一下主机名的设置,pg_hba和postgres.conf配置,都没问题。再检查一下IP设置,此时惊奇发现IP的回环LO没了。只有eth0和eth1的信息。难怪。
增加回环:
ifconfig lo 127.0.0.1
再测试,正常了。想起之前服务器有重启,但是网卡没起来,当时重启了下网卡(ifdown eth0 和ifup eth0),但是倒是第一次遇到ip回环丢失的情况。暂时还不清楚原因,有了解的麻烦留个信
原文链接:https://www.f2er.com/postgresql/196644.html