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

当前回答

答案是@diego

我想补充一些关于我如何修复错误的解释,我希望它能帮助到其他人: postgres用户密码验证失败

在窗口


确保你下载Postgres软件,安装它,创建和确认密码 并确保它不复杂的一些符号和字符。 打开窗口,单击SQL Shell (PSQL),进入并创建数据库 创建连接字符串,如 postgres: / / postgres: your_password@localhost:港口/ your_database

在WSL


遵循微软文档

安装成功后

 // Open postgres
 su postgres
 
 // Type psql and hit enter
 psql

 // Create a user postgres if not exist or any other user you want 
 CREATE USER your_user_db WITH PASSWORD 'match_password_with_db_password';
 

 // Give user password same as the one you set up for postgres db
 ALTER USER your_user_db WITH PASSWORD 'match_password_with_db_password';

 // Restart the server
 sudo service postgresql restart

其他回答

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

如果你看到错误

FATAL:  password authentication failed for user "postgres"

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

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

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

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

请记住,如果你安装了两个版本的Postgres,你需要卸载其中一个,在我的情况下,在MacOS上,我通过。dmg安装了一个版本,另一个通过brew安装。

对我来说有用的是使用以下步骤卸载通过.dmg安装的程序

进入/Library/PostgreSQL/13。 uninstall-postgres.app开放。

那就试试

psql postgres

它应该会起作用。

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

切换到postgres用户

# su - postgres

登录PSQL

# psql

希望这能有所帮助