【发布时间】:2023-03-10 00:00:01
【问题描述】:
我正在尝试连接到远程 Postgres 数据库(在本例中为 Heroku Postgres 实例)。我有一个 Fabric 命令,它使用 psycopg2 对数据库执行一些工作。
我的 Postgres 连接是这样发生的:
# conf is a hash derived from the heroku config DATABASE_URL
self.conn = psycopg2.connect(
database=conf.get('database'), # supplied by heroku
user=conf.get('username'), # is the database username supplied by heroku
password=conf.get('password'), # supplied by heroku
host=conf.get('host'), # e.g ec2-00-000-00-00.compute-1.amazonaws.com
port=conf.get('port') # 5492
)
运行脚本出错:
psycopg2.OperationalError: FATAL: password authentication failed for user "my-server-user"
FATAL: no pg_hba.conf entry for host "my-ip-address-here", user "my-server-user", database "database-name-here", SSL off
调查pg_hba.conf,我暂时引入了以下行:
host all all trust
然后用
重新启动 Postgressudo /etc/init.d/postgresql-9.3 restart
但我仍然遇到这个问题。但是,我能够简单地使用命令行客户端进行连接(即使没有更改 pg_hba 配置):
psql -h ec2-00-000-00-00.compute-1.amazonaws.com -p 5492 database-name -W
手动提供密码。
代码在我的 Mac 上本地运行,因此存在配置错误或被阻止的内容。我只是无法弄清楚它可能是什么。欢迎提出任何建议。
(很明显,现实世界的值已被上述示例中的占位符替换)
【问题讨论】:
-
这没有多大意义。您正在使用 Heroku,那么如何修改
pg_hba.conf?您是否修改了本地计算机上无关 PostgreSQL 服务器的pg_hba.conf?或者您实际上并没有尝试使用 Heroku?
标签: python postgresql heroku psycopg2