我已经安装了PostgreSQL 8.4, Postgres客户端和Pgadmin 3。控制台客户端和Pgadmin用户“postgres”身份验证失败。我已经输入用户作为“postgres”和密码“postgres”,因为它以前工作过。但是现在身份验证失败。我以前做过几次都没有这个问题。我该怎么办?发生了什么?

psql -U postgres -h localhost -W
Password for user postgres: 
psql: FATAL:  password authentication failed for user "postgres"
FATAL:  password authentication failed for user "postgres"

当前回答

首先是密码箱

ALTER USER postgres with encrypted password 'postgres';

然后重启服务:

sudo systemctl restart postgresql.service

End.

其他回答

如果我没记错的话,默认情况下,用户postgres在Ubuntu上没有设置数据库密码。也就是说,您只能使用postgres操作系统用户帐户登录该帐户。

假设,你有根访问的盒子,你可以做:

sudo -u postgres psql

如果失败,提示数据库“postgres”不存在,那么你很可能不在Ubuntu或Debian服务器上:-)在这种情况下,只需在命令中添加template1:

sudo -u postgres psql template1

如果这些命令中的任何一个失败,出现错误psql: FATAL: password authentication failed for user "postgres",那么检查/etc/postgresql/8.4/main/pg_hba.conf文件:必须有这样的一行作为第一个非注释行:

local   all         postgres                          ident

对于较新版本的PostgreSQL, ident实际上可能是peer。这也没关系。

在psql shell中,你可以给数据库用户postgres设置一个密码:

ALTER USER postgres PASSWORD 'newPassword';

您可以通过键入CtrlD或使用\q命令离开psql shell。

现在,您应该能够为pgAdmin提供一个有效的数据库超级用户密码,它也会很高兴。: -)

在任何文本编辑器中打开pg_hba.conf(你可以在postgres安装文件夹中找到这个文件); 将所有的方法字段更改为trust(这意味着postgre不需要密码); 在你的控制台运行这个命令: “alter user postgres with password '[my password]';”| psql -U postgres (意思是用参数-U postgres来修改用户[my password]的密码) Et voilà(不要忘记将方法从trust改回最适合你的方法)

我希望有一天这能帮助到别人。

对我来说,这太简单了!我在应用程序JAVA Spring中出错,因为我需要记住数据库超级用户,它在安装过程中显示PostgreSQL,在我的情况下,数据源将是postgres。所以,我正确地添加了名称,它工作!

尽量不要使用-W参数,并让密码为空。有时创建用户时使用无密码。

如果不行,重置密码。有几种方法可以做到这一点,但这适用于许多系统:

$ su root
$ su postgres
$ psql -h localhost
> ALTER USER postgres with password 'YourNewPassword';

如果你看到错误

FATAL:  password authentication failed for user "postgres"

确保密码正确,检查密码是否有特殊字符,特别是“%”或斜杠。 在我的例子中,它是密码字符串中的“%”。删除此符号后,一切正常。