我在尝试使用PostgreSQL和Psycopg2时遇到了一个奇怪的情况。出于某种原因,每次尝试通过python连接postgre数据库时,都会出现以下错误:
psycopg2.OperationalError: FATAL: no pg_hba.conf entry for host "127.0.0.1", user "steve", database "steve", SSL on
FATAL: no pg_hba.conf entry for host "127.0.0.1", user "steve", database "steve", SSL off
当然,我检查了pg_hba.conf以查看问题所在,但就我所见,似乎所有配置都正确:
pg_hba.conf:
# TYPE DATABASE USER CIDR-ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all md5
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
另外,我发现我可以通过psql连接到数据库,正如我所期望的那样:
$ psql -U steve -h 127.0.0.1
...
steve=>
有人知道这里会发生什么吗?提前谢谢!
我最近也遇到了同样的问题,我找到了解决这个问题的办法。
系统:
python
、django
、psycopg2
和postgres client 9.6.1
(postgresql-9.6.1.tar.gz
)),例如ip address 10.0.0.1
(私有地址)。aws_rds_host_name
”或任何数据库IP地址。错误:
django.db.utils.OperationalError: FATAL: no pg_hba.conf entry for host
"10.0.0.1", user "your_user", database "your_db", SSL off
解决方案:
在应用服务器
10.0.0.1
中安装postgres client 9.6.1
源包时,我们必须传递一个参数“--with-openssl
”。我建议删除现有的postgres client
,并按以下步骤安装。postgres client source package 9.6.1
(postgresql-9.6.1.tar.gz
)postgresql-9.6.1.tar.gz
。./configure --prefix="your_preferred_postgres_path_if_needed" --with-openssl (this '--with-openssl'
参数对于消除该错误非常重要)psycopg2
运行django项目时,不会发生该错误。我希望这个解决方案能帮助别人。
典型的解释包括:
您连接到了错误的服务器 数据库服务器是否与Python在同一主机上运行?
您得到了错误的端口} 。
如果看到连接尝试,请检查服务器日志。当然,你必须为此记录连接。请参阅config parameter ^{
更改} 或
pg_hba.conf
后您没有重新加载(SIGHUP)服务器,或者重新加载了错误的群集(如果您有多个数据库群集)。在Debian及其衍生物上使用^{
pg_ctlcluser
。相关问题 更多 >
编程相关推荐