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

当前回答

以下是我尝试登录的一些组合:

# login via user foo
psql -Ufoo -h localhost

sudo -u postgres psql postgres

# user foo login to postgres db
psql -Ufoo -h localhost -d postgres

其他回答

遵循以下步骤:

Sudo -u postgres -i psql postgres \密码

之后,输入两次密码。

然后在pgAdmin4中使用该密码。

在登录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;

作为一个经验法则:你永远不应该为POSTGRES用户设置密码。

如果需要从pgAdmin获得超级用户权限,请创建另一个超级用户。这样,如果超级用户的凭据被泄露,您总是可以ssh到实际的数据库主机并使用手动删除超级用户

sudo -u postgres -c "DROP ROLE superuser;"

当你安装postgresql时,没有为postgres用户设置密码,你必须在Unix上使用命令显式地设置它:

sudo passwd postgres

它会询问您的sudo密码,然后提示您输入新的postgres用户密码。 源

我只是想补充一句,你也应该检查一下你的密码是否过期了。

详细信息请参见Postgres密码验证失败。