Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/356.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用psycopg2与postgresql的连接被拒绝_Python_Postgresql_Python 3.x - Fatal编程技术网

Python 使用psycopg2与postgresql的连接被拒绝

Python 使用psycopg2与postgresql的连接被拒绝,python,postgresql,python-3.x,Python,Postgresql,Python 3.x,psycopg2.OperationalError:无法连接到服务器:连接被拒绝 服务器是否在主机“45.32.1XX.2XX”上运行,并在端口5432上接受TCP/IP连接 这里,我打开了插座 tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN 11516/postgres tcp6 0 0 ::1:5432 :::*

psycopg2.OperationalError:无法连接到服务器:连接被拒绝

服务器是否在主机“45.32.1XX.2XX”上运行,并在端口5432上接受TCP/IP连接

这里,我打开了插座

tcp        0      0 127.0.0.1:5432          0.0.0.0:*  LISTEN      11516/postgres                
tcp6       0      0 ::1:5432                :::*       LISTEN      11516/postgres
我在谷歌上搜索到我应该修改这个
pg_hba.conf
,但是在我的
postgresql
根文件中,我根本没有找到这个文件

我还成功地连接了我的另一台服务器

谢谢


在这里,我修改了
pg_hba.conf
,更新了这个
主机所有218.3.A.B信任并重新加载。但它也不起作用。

您的netstat输出显示postgres正在收听
127.0.0.1
,但您的错误表明您正在尝试连接到
45.32.1XX.2XX
。我敢肯定你已经诊断出你的问题了

您需要修改
listen\u addresses
设置您的
postgresql.conf
文件(而不是
pg\u hba.conf
)。
postgresql.conf
文件位于您的postgresql数据目录中,该目录通常类似于
/var/lib/postgresql/data
/var/lib/pgsql/data

listen\u addresses
参数已记录在案。

也检查端口

可能您的应用程序没有在默认的
5432
上运行


端口配置在Ubuntu 14.04中运行postgresql?的哪个操作系统下的
postgresql.conf
file

上。非常感谢。最后,我将这个
listen\u addresses='*'
附加到
postgresql.conf
中。它运行良好。接受的答案对我不起作用。但是在修改了
pg_hba.conf
文件之后,它就工作了。另外,我正在使用postgresql 11
1. Modify two configure files
# vi /var/lib/pgsql/data/postgresql.conf
 Replace the line:
listen_addresses = 'localhost'  -> listen_addresses = '*'
# vi /var/lib/pgsql/data/pg_hba.conf
 Add the line at the very end:
host all all 0.0.0.0/0 trust
(If IPv6:
host all all ::/0 trust) 
2. Restart the database service
# service postgresql restart
3. Disable the firewall
# rcSuSEfirewall2 stop
# chkconfig SuSEfirewall2 off
# chkconfig SuSEfirewall2_init off