通过远程IP地址连接到PostgreSQL数据库,通过pgAdmin III成功地通过Windows连接,但是每当我尝试使用标准的使用pg_connect()的php-pgsql库从本地CentOS 6 Apache服务器连接时,都会出现错误。
备注:
入境事务处如下:
Host (IP): xx.xx.xx.xx
Port: 5432
DBname: sandbox
Username: abc
Password: ***
MaintenanceDB: template1这是我试图在本地服务器上运行的PHP代码:
pg_connect("host=xx.xx.xx.xx port=5432 dbname=sandbox user=abc password=***");我也试过:
pg_connect("host=xx.xx.xx.xx port=5432 dbname=template1 user=abc password=***");当我试图连接时,我会收到以下错误:
Warning: pg_connect(): Unable to connect to PostgreSQL server: could not connect to server: Permission denied Is the server running on host "xx.xx.xx.xx" and accepting TCP/IP connections on port 5432?我在/etc/php.d/目录和service httpd restart中添加了/未注释的service httpd restart。我甚至已经打开了我的iptables端口,因此毫无疑问本地防火墙端口被阻塞了:
-A INPUT -m state --state NEW -m tcp -p tcp --dport 5432 -j ACCEPT
-A INPUT -m state --state NEW -m udp -p udp --dport 5432 -j ACCEPT预先多谢:-)
发布于 2015-01-10 19:19:51
根据postgresql连接问题,此解决方案可能有效。我只是从php手册中得到了这个答案,但我不确定,所以请看这里是否有更多的http://php.net/manual/en/function.pg-connect.php#38291
,您应该尝试将host=和port=部分排除在连接字符串之外。这听起来很奇怪,但这是Postgre的“选择”。如果您没有激活postgresql.conf中的TCP/IP端口,那么postgresql将不接受来自TCP/IP端口的任何传入请求.。
https://stackoverflow.com/questions/27879939
复制相似问题