为什么postgresql连接失败

PostgreSQL 是一个免费的对象-关系数据库服务器(ORDBMS),在灵活的BSD许可证下发行。

在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可正常连接。

推荐学习《

Python教程

》。

来源:PY学习网:原文地址:https://www.py.cn/article.html

hmoban主题是根据ripro二开的主题,极致后台体验,无插件,集成会员系统
自学咖网 » 为什么postgresql连接失败