【发布时间】:2022-01-22 19:48:44
【问题描述】:
我有一个 python 脚本可以将数据添加到 postgres 数据库。在测试期间,我在本地系统中创建了一个数据库,它运行良好。现在我的数据库在 linode 中运行。我不确定如何从本地系统连接到数据库。我将数据库详细信息存储在 python 文件中,如下所示
DATABASE = 'my_database'
HOST = <IP_ADDRESS> # the ip_address of the linode instance
PORT = '5432'
USER = 'database_user'
PASSWORD = 'database_password'
我使用上面的代码访问数据库。如果数据库在本地主机中运行,则主机等于HOST = 'localhost'。
当我从本地系统运行 python 脚本连接到数据库时,这是我得到的消息
psycopg2.OperationalError: connection to server at "<IP_ADDESS>", port 5432 failed: Connection refused
Is the server running on that host and accepting TCP/IP connections?
我不知道如何连接到在 linode 中运行的数据库。
【问题讨论】:
-
A)
postgresql.conf中的服务器listen_addresses设置不正确。请参阅Connections 和/或 B) 有防火墙阻止端口5432。
标签: python postgresql linode