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

当前回答

给出的答案几乎是正确的,只是缺少一些指针,我会在我的解决方案中照顾

首先确保你的用户有sudo访问权限,如果没有,你可以使用下面的命令添加你的用户作为sudo用户

sudo adduser <username> sudo

更改将在用户下次登录时生效。

i)现在转到sudo vim /etc/postgresql/<your_postgres_version>/main/pg_hba.conf文件,寻找这样的行:

local   all             postgres                                md5 #peer

评论一下。就在这一行下面,必须有一个注释行,说:

local   all             postgres                                peer

或者对于旧版本,它将是:-

local   all         postgres                          ident

取消这一行的注释。

ii)现在重新启动postgres使用任何这些命令:-

sudo /etc/init.d/postgresql restart

OR

sudo service postgresql restart

iii)现在您可以使用以下命令简单地登录到postgres:

sudo -u postgres psql

Iv)一旦你在你可以创建任何你想要的操作,在我的情况下,我想创建一个新的数据库,你可以使用下面的命令做同样的事情:

CREATE DATABASE airflow_replica;

其他回答

在任何文本编辑器中打开pg_hba.conf(你可以在postgres安装文件夹中找到这个文件); 将所有的方法字段更改为trust(这意味着postgre不需要密码); 在你的控制台运行这个命令: “alter user postgres with password '[my password]';”| psql -U postgres (意思是用参数-U postgres来修改用户[my password]的密码) Et voilà(不要忘记将方法从trust改回最适合你的方法)

我希望有一天这能帮助到别人。

答案是@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

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

命令

sudo -u postgres psql

接下来您可以更新密码

命令

修改用户postgres密码为YOUR_NEW_PASSWORD

首先是密码箱

ALTER USER postgres with encrypted password 'postgres';

然后重启服务:

sudo systemctl restart postgresql.service

End.

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

切换到postgres用户

# su - postgres

登录PSQL

# psql

希望这能有所帮助