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

当前回答

在我的例子中,它的密码超过100个字符。将其设置为较小的字符密码有效。

事实上,我想知道有没有什么地方提到过这个。

其他回答

这是令人沮丧的,上面的大多数答案是正确的,但他们没有提到你必须重新启动数据库服务在pg_hba.conf文件中的更改将生效。

所以如果你做出如上所述的改变:

local all postgres ident

然后以root身份重新启动(在centos上,它类似于service service postgresql-9.2 restart) 现在您应该能够以用户postgres的身份访问数据库了

$psql
psql (9.2.4)
Type "help" for help.

postgres=# 

希望这能为postgres的新用户提供信息

首先是密码箱

ALTER USER postgres with encrypted password 'postgres';

然后重启服务:

sudo systemctl restart postgresql.service

End.

时间过得真快啊!

在版本12中,我必须在这里使用“password”而不是“ident”:

local   all             postgres                                password

不使用-h选项进行连接。

如果您试图以postgres用户登录postgres shell,那么您可以使用以下命令。

切换到postgres用户

# su - postgres

登录PSQL

# psql

希望这能有所帮助

在登录postgres时,我也遇到了这个问题。我遵循以下步骤,并能够登录postgres和pgadmin。

步骤1:使用终端打开Postgres。

sudo su postgres

步骤2:打开psql。

psql

步骤3:重置用户密码

ALTER USER user_name WITH PASSWORD 'new_password';

Step4:赋予用户对数据库的权限。

GRANT ALL PRIVILEGES ON DATABASE my_database TO db_user;