sqlalchemy.exc.OperationalError:(psycopg2.OperationalError)无法连接到服务器:

时间:2020-04-06 01:38:53

标签: python-3.x postgresql

我正在尝试使用Postgres DB运行python脚本,并不断收到此错误

sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) could not connect to server: Connection refused
        Is the server running on host "Zac92" (127.0.1.1) and accepting
        TCP/IP connections on port 5432?

基于一些答案,我更改了我的postgresql.conf和hba.conf文件。

在我的postgresql.conf文件中,我有listen_address= '*'port = 5432,这是我的pg_hba.conf文件设置的样子

# Database administrative login by Unix domain socket
local   all             postgres                                peer

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     peer
# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
# IPv6 local connections:
host    all             all             ::1/128                 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
local   replication     all                                     peer
host    replication     all             127.0.0.1/32            md5
host    replication     all             ::1/128                 md5
host    all             all             192.168.1.0/24          md5

我还检查了端口是否处于活动状态。

netstat -nlp | grep 5432
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
tcp        0      0 127.0.0.1:5432          0.0.0.0:*               LISTEN      -                   
unix  2      [ ACC ]     STREAM     LISTENING     11972891 - /var/run/postgresql/.s.PGSQL.5432              

最重要的是,我也尝试多次重新启动并重新安装postgres,但似乎没有任何效果。我觉得我已经完成了所有工作,而不仅仅是重启机器。

在撰写此问题时,我注意到在回溯中,地址为127.0.1.1,但是当我使用netstat检查端口时,我看到了另一个IP地址127.0.0.1。这可能是问题的根源吗?任何帮助将不胜感激。

系统信息:Linux Mint 19.1 Postgres 10.12 python 3.6

0 个答案:

没有答案