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
根目录找不到这个文件,而且在我另一台我可以连接成功服务器上,也不存在这个文件。
求大神解答!感谢~
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
Only modify
pg_hba.conf
文件是不够的,还要修改postgresql.conf
的listen_addresses
configuration itemsYou 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 -h
Reference question: The linux terminal can connect to the mysql database, but it cannot connect to mysql through the php program