我已经在 Fedora 17 上安装了 postgresql 数据库。
当我通过 pgadmin3 创建新的服务器连接时,弹出窗口中出现此错误:
postgresql The server doesn't accept the current user: The server report
Ident authentication failed
The server doesn't accept the current user: The server reports
FATAL: Ident authentication failed for user "pgadmin"
If this message appears, the pg_hba.conf entry found for your
client / user / database combination is set to "ident" authentication.
Some distributions, e.g. Debian, have this by default. To perform ident
based authentication successfully, you need additional setup; see the
PostgreSQL help for this. For a beginner, it might be more appropriate
to use a different authentication method; MD5 encrypted passwords are
a good choice, which can be configured by an entry in pg_hba.conf like
this:
host all all 192.168.0.0/24 md5
This example grants MD5 encrypted password access to all databases to
all users on the private network 192.168.0.0/24.
You can use the pg_hba.conf editor that is built into pgAdmin III to
edit the pg_hba.conf configuration file. After changing pg_hba.conf,
you need to trigger a server configuration reload using pg_ctl or by
stopping and restarting the server process.
我已按照错误消息中提到的方法进行了更改,并将其添加host all all 192.168.0.0/24 md5
到 pg_hba.conf 中。但我仍然收到相同的错误。我做错了什么?
答案1
我犯的错误是忘记取消注释设置主机的其他行,并且没有重新启动 postgresql,以便该文件的新更改生效。以下是我使用的步骤:
找到你的
pg_hba.conf
,我的在/var/lib/pgsql/data/pg_hba.conf
以下是 的原始错误内容
pg_hba.conf
,请注意 IPv4 和 IPv6 的两行主机行:# TYPE DATABASE USER ADDRESS METHOD # "local" is for Unix domain socket connections only local all all peer # IPv4 local connections: host all all 127.0.0.1/32 ident # IPv6 local connections: host all all ::1/128 ident # Allow replication connections from localhost, by a user with the # replication privilege. #local replication postgres peer #host replication postgres 127.0.0.1/32 ident #host replication postgres ::1/128 ident
我必须在该文件末尾添加以下几行
host all all 127.0.0.1/32 md5 #the 32 means only the first 32 bits cannnot change, not the first 24. #I use 32 because only one address will be accessing this server.
如果您不注释掉这里的其他默认行,它将不起作用:
#host all all 127.0.0.1/32 ident # IPv6 local connections: #host all all ::1/128 ident
然后重新启动postgresql。
[root@rosewill samples ]$ systemctl restart postgresql.service
重启后重试,错误已修复。然后我可以使用 pgadmin3 登录服务器。