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

当前回答

我希望这能在短时间内帮到你。 可以使用bellow命令修改postgres sql的密码。

命令

sudo -u postgres psql

接下来您可以更新密码

命令

修改用户postgres密码为YOUR_NEW_PASSWORD

其他回答

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

# 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

我在Windows 10上也遇到了同样的错误。在我的例子中,当我设置Postgres时,我的用户名默认是Postgres。 但是当我运行命令psql时,它显示我的用户名为jitender,这是我的机器名,我不知道为什么这个用户名已经设置。

为了解决这个问题,我做了以下步骤: 执行命令psql——help

在输出中,寻找Connection Option,在这里您将看到默认用户,在我的示例中为jitender。 您还将获得设置另一个用户名的命令,该命令应该是psql——username 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

这是令人沮丧的,上面的大多数答案是正确的,但他们没有提到你必须重新启动数据库服务在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的新用户提供信息

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

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