这是我收到的错误,它拒绝连接到数据库
Traceback (most recent call last):
File "db.py", line 2, in <module>
conn = psycopg2.connect(host="176.58.104.XXX",database="XXXX", user="XXXXX", password="XXXXX")
File "c://addr", line 130, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: could not connect to server: Connection refused (0x0000274D/10061)
Is the server running on host "176.58.104.XXX" and accepting
TCP/IP connections on port 5432?
我已经尽可能地诊断出原因。 我的postgresql.conf文件在这里,所以我将它们全部更新了,除了示例
locate postgresql.conf
/etc/postgresql/9.5/main/postgresql.conf
/usr/lib/tmpfiles.d/postgresql.conf
/usr/share/postgresql/9.5/postgresql.conf.sample
与
#------------------------------------------------------------------------------
# CONNECTIONS AND AUTHENTICATION
#------------------------------------------------------------------------------
# - Connection Settings -
#listen_addresses = '*' # what IP address(es) to listen on;
# comma-separated list of addresses;
# defaults to 'localhost'; use '*' for all
然后更新pg_hba.conf
host all all 0.0.0.0/0 md5
host all all ::/0 md5
并重新启动sudo systemctl重新启动PostgreSQL
我遵循了这些说明https://zaiste.net/postgresql_allow_remote_connections/
但是我仍然遇到错误
这是我的netstat -nlt,我仍然可以看到我的连接与127.0.0.1绑定
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN
我错过了一些步骤吗?
答案 0 :(得分:0)
默认情况下,#位于#listen_addresses ='*'前面。
没看到。