python-3.x - 尝试连接到数据库 postgres
问题描述
这是我得到它拒绝连接到我的数据库的错误
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 restart 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
我错过了一些步骤吗?
解决方案
默认情况下,# 在 #listen_addresses = '*' 前面。
没看到。
推荐阅读
- terraform - 将所有 DigitalOcean Droplet 实例添加到 Terraform 中的项目
- r - 尽管超过 2 个级别,R 中的 rstatix anova_test 仍会给出对比度错误
- java - 从 Android 应用程序向 Laravel 发出 POST 请求时出现 419 错误代码
- ios - ios UIScrollView 自动滚动到时间线结束
- java - Spring MVC JSP 表单未使用会话中的值进行更新
- angular - 重写嵌套订阅
- python - 我需要处理带有推文的文本。使用正则表达式甚至普通的python代码
- airflow - Can you specify the number of threads for certain tasks in a DAG?
- google-apps-script - How to hide/unhide a named range of columns with Google script
- python - How does the FrameAnimation3d class work in Ursina (a message to pokepetter)