postgresql pgadmin3:致命:用户“postgres”的身份验证失败

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12489036/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 00:19:14  来源:igfitidea点击:

pgadmin3: FATAL: Ident authentification failed for user "postgres"

postgresqlauthenticationpgadmin

提问by DSblizzard

I'm trying to register new server in pgadmin3 with following settings:

我正在尝试使用以下设置在 pgadmin3 中注册新服务器:

Name: postgres
Host: localhost
Username: postgres
Password: <password which works for psql>
Service: empty or postgres

But it shows error:

但它显示错误:

FATAL: Ident authentification failed for user "postgres"

I've restarted postgresql service, but to no avail.

我已经重新启动了 postgresql 服务,但无济于事。

Contents of /var/lib/pgsql/data/pg_hba.conf:

/var/lib/pgsql/data/pg_hba.conf 的内容:

# TYPE  DATABASE    USER        CIDR-ADDRESS          METHOD

# "local" is for Unix domain socket connections only
local   all         all                               trust
# IPv4 local connections:
host    all         all         127.0.0.1/32          trust
# IPv6 local connections:
host    all         all         ::1/128               ident

EDIT: Tools -> Server Configuration -> pg_hba.conf is greyed out.

编辑:工具 -> 服务器配置 -> pg_hba.conf 是灰色的。

采纳答案by Craig Ringer

It looks like PgAdmin-III is probably connecting over IPv6 by default, so it's using the identline that matches the IPv6 address for localhost, ::1/128.

看起来 PgAdmin-III 可能默认通过 IPv6 连接,因此它使用ident与 localhost 的 IPv6 地址匹配的行::1/128

If you want to use password authentication, you probably want:

如果您想使用密码认证,您可能需要:

# IPv4 local connections:
host    all         all         127.0.0.1/32          md5
# IPv6 local connections:
host    all         all         ::1/128               md5

I'm not sure why you have the unix domain socket line set to trust, but that's probably OK if it's just a development machine, so leave it unchanged. It's really much safer to have it as ident(if you want the unix user to have to be the same as the Pg user) or md5(for password auth on local unix sockets) though.

我不确定为什么您将 unix 域套接字行设置为trust,但如果它只是一台开发机器,那可能没问题,所以保持不变。但是,将其作为ident(如果您希望 unix 用户必须与 Pg 用户相同)或md5(对于本地 unix 套接字上的密码身份验证)确实要安全得多。

You'll need to edit pg_hba.confdirectly in a text editor if PgAdmin-III doesn't have permissions to edit it. You could run PgAdmin-III as user postgresvia sudo, but it's way safer (and probably easier) to just use nanoor a similar command-line text editor to modify pg_hba.conf.

pg_hba.conf如果 PgAdmin-III 没有编辑权限,您将需要直接在文本编辑器中进行编辑。您可以postgres通过以用户身份运行 PgAdmin-III sudo,但仅使用nano或类似的命令行文本编辑器来修改pg_hba.conf.

The password works for psqlbecause psqlwill, unless told otherwise, connect over a unix domain socket, and you have that set to trust. You'll probably find you could give anypassword to psqland it'll still work, because it's never being asked to actually give the password, it's just being automatically trusted.

密码有效,psql因为psql除非另有说明,否则将通过 unix 域套接字连接,并且您已将其设置为trust. 你可能会发现你可以给它任何密码psql并且它仍然可以工作,因为它从来没有被要求实际提供密码,它只是被自动信任。

回答by Jay Modi

Yes this type of error is seen by every newbie user to pgadmin. I have found this solution and it worked for me.

是的,每个 pgadmin 新手用户都会看到这种类型的错误。我找到了这个解决方案,它对我有用。

sudo -u postgres psql

This will ask for your system password and then you will get the postgres prompt.

这将询问您的系统密码,然后您将收到 postgres 提示。

and then in psql type below command to change the password.

然后在 psql 中键入下面的命令来更改密码。

\password

now enter the new password and re-enter it.

现在输入新密码并重新输入。

回答by smaudet

PostGreSQL Account Debugging Steps (Linux Specific):

PostGreSQL 账户调试步骤(Linux 特定):

  1. Make sure you actually have it installed (not just the client, the server too).
  2. Make sure it is running.
  3. Make sure you know wherethis is - usually in /var/lib/pgsql/data- however this could be anywhere - /var/lib/pgsql/unrelated-instance. Check your postgres processto see which directory (-D argument) this is.
  4. Modify the pg_hba.conffile in the directory from the last step. I have no idea why this step isn't in the postgres documentation.
  5. The specific configuration has been covered in e.g. Jay and Craig Ringer's answer. Make sure to configure bothIPV4 and IPV6.
  6. Restart the server.
  7. Test that your configuration worked. Repeat 5-7 until you can login successfully.
  8. ImportantDon't stop! Now you should configure a more secure password option - postgres may be fine for doing quick local setup, but you want to be using a more secure, configurable authentication mechanism, like LDAP, Kerberos, or GSSAPI. Additionally, you want to make sure you have SSL turned on.
  1. 确保您确实安装了它(不仅仅是客户端,还有服务器)。
  2. 确保它正在运行。
  3. 确保您知道它在哪里- 通常在/var/lib/pgsql/data 中- 但是这可能在任何地方 - /var/lib/pgsql/unrelated-instance。检查您的postgres 进程以查看这是哪个目录(-D 参数)。
  4. 修改上一步目录下的pg_hba.conf文件。我不知道为什么这一步不在 postgres 文档中。
  5. 具体配置已在例如 Jay 和 Craig Ringer 的回答中介绍。确保配置IPv4和IPv6。
  6. 重新启动服务器。
  7. 测试您的配置是否有效。重复5-7,直到登录成功。
  8. 重要不要停止!现在您应该配置一个更安全的密码选项 - postgres 可能适合进行快速本地设置,但您希望使用更安全、可配置的身份验证机制,如 LDAP、Kerberos 或 GS​​SAPI。此外,您要确保已打开 SSL。