Psycopg2报告pg_hba.conf错误 [英] Psycopg2 reporting pg_hba.conf error
问题描述
在尝试使用PostgreSQL和Psycopg2时遇到了一种奇怪的情况。由于某种原因,每次我尝试通过python连接到postgre数据库时,都会出现以下错误:
I've run into a weird situation while trying to use PostgreSQL and Psycopg2. For some reason, every time I attempt to connect to the postgre database via python, I get the following error:
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以查看问题所在是的,但据我所知一切似乎都已正确配置:
Naturally, I checked pg_hba.conf to see what the issue was, but everything appeared to be configured correctly as far as I can see:
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连接到数据库:
In addition, I've found that I can connect to the database via psql as I would expect:
$ psql -U steve -h 127.0.0.1
...
steve=>
任何人都对这里可能发生的事情有任何想法?
Anyone have any ideas as to what could be going on here? Thanks in advance!
推荐答案
典型的解释包括:
-
您正在连接到错误的服务器。
数据库服务器是否与Python在同一主机上运行?
You are connecting to the wrong server.
Is the DB server running on the same host as Python does?
您得到了错误的端口。
检查服务器日志,是否看到连接尝试。当然,您必须为此记录连接。请参见配置参数 log_connections
。
You got the wrong port.
Check the server log if you see a connection attempt. You have to log connections for that, of course. See the config parameter log_connections
.
更改后您没有重新加载(SIGHUP)服务器 pg_hba.conf
-或重新加载了错误的集群(如果您有多个数据库集群)。
使用 pg_ctl
或 pg_ctlcluser
关于Debian及其衍生工具。
You did not reload (SIGHUP) the server after changing pg_hba.conf
- or reloaded the wrong cluster (if you have multiple DB clusters).
Use pg_ctl
or pg_ctlcluser
on Debian and derivatives for that.
这篇关于Psycopg2报告pg_hba.conf错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!