python - psycopg2连接远程数据库被拒绝
大家讲道理
大家讲道理 2017-04-18 09:43:52
0
3
543
psycopg2.OperationalError: could not connect to server: Connection refused
    Is the server running on host "45.32.1XX.2XX" and accepting
    TCP/IP connections on port 5432?

远程数据库端口已经打开了:

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根目录找不到这个文件,而且在我另一台我可以连接成功服务器上,也不存在这个文件。

求大神解答!感谢~

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(3)
洪涛

It is recommended to read the official documentation:

https://www.postgresql.org/do...

Generally, the default rules of postgresql are very abnormal and only allow localhost connections. In your case, you really need to modify pg_hba.conf. As for the path of this file, it depends on different Linux distributions and the installation personnel's preferences, but it is certain It must exist, you can simply search for its path

locate pg_hba.conf
或者
find / -type f -iname "pg_hba.conf" 2>/dev/null

After finding it, modify the security policy. Basically, it has simple comments by default, which is easy to understand (release the local IP address)

After modification, restart the postgresql service and it will be OK

PHPzhong

Only modify pg_hba.conf 文件是不够的,还要修改 postgresql.conflisten_addresses configuration items

You can find the PGDATA of postgresql through show data_directory;

小葫芦

Try to see if you can remotely log in to mysqld using mysql -uroot -p - P -hReference question: The linux terminal can connect to the mysql database, but it cannot connect to mysql through the php program

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!