我已经安装了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"

当前回答

进入postgres shell后,输入以下命令

postgres=# \password postgres

输入此命令后,将提示您设置密码,只需设置密码,然后尝试。

其他回答

对于那些第一次使用它,不知道密码是什么的人,他们可以遵循以下步骤(假设你是ubuntu):

3 .打开/etc/postgresql/9.x/main目录下的pg_hba.conf文件 Sudo vi pg_hba.conf .conf 2.编辑下面的行 本地所有postgres peer 来 本地所有postgres信任 重新启动服务器 Sudo服务postgresql重启 最后,您可以登录,无需密码,如图所示

更多信息请参考这里

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

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

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

遵循以下步骤:

Sudo -u postgres -i psql postgres \密码

之后,输入两次密码。

然后在pgAdmin4中使用该密码。

如果我没记错的话,默认情况下,用户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提供一个有效的数据库超级用户密码,它也会很高兴。: -)

工作人员的反应是正确的,但如果你想进一步自动化可以做:

$ sudo -u postgres psql -c “ALTER USER postgres PASSWORD 'postgres' ;”

完成了!您保存了User = postgres和password = postgres。

如果你没有postgres ubuntu用户的密码,请:

$ sudo passwd postgres