您的位置:首页 > 数据库

PostgreSQL问题解决--连接失败

2016-06-26 17:22 302 查看



问题

在pgAdmin中,将本地数据库连接的host由
localhost
127.0.0.1
改为自己的真实ip–
10.xxx.xxx.xxx
后,连接失败,报错如下:

psql: could not connect to server: Connection refused
Is the server running on host "my host name" (IP) and accepting
TCP/IP connections on port 5432?


解决

出现上述问题时,需修改postgresql.conf和pg_hba.conf文件。

此文件位于postgresql数据文件目录中,默认为
/var/lib/pgsql/data/
。将postgresql.conf修改如下:
listen_addresses = '*'


pg_hba.conf中增加需要连接该数据库主机的ip地址。如下所示,增加对主机
10.xxx.xxx.xxx
的信任。

host    all             all             10.xxx.xxx.xxx/32         trust


如上设置后,使用
10.xxx.xxx.xxx
可正常连接。

解释

原来,在客户端访问PostgreSQL数据库时,PostgreSQL会读取文件
pg_hba.conf
判断是否信任该主机,故所有需要连接PostgreSQL Server的主机都应当在
pg_hba.conf
中添加对其信任,即使是Server主机也不例外!

参考

Postgresql连接失败和设置系统shmmax的方法

初识Postgresql和Sqoop

PostgreSQL数据库远程连接功能的开启
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  postgresql