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

当前回答

时间过得真快啊!

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

local   all             postgres                                password

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

其他回答

这是由于缓存造成的。

当你运行php artisan config:cache时,它会缓存配置文件。当事情发生变化时,您需要继续运行它来更新缓存文件。但是,如果你不运行这个命令,它就不会缓存。

这对于生产来说是可以的,因为配置不会经常更改。但是在登台或开发期间,您可以通过清除缓存来禁用缓存,而不运行缓存命令

因此,只需运行php artisan config:clear,之前不要运行该命令以避免缓存。

查看原文

运行laravel迁移时密码验证失败错误

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

古老的线程,但我在2020年浪费了半天时间来处理这个问题,所以这可能会帮助到一些人:再次检查你的postgres端口(在Ubuntu上,它在/etc/postgresql/9.5/main/postgresql.conf)。psql客户端默认使用端口5432,但在我的例子中,服务器运行在端口5433上。解决方案是在psql中指定-p选项(例如psql——host=localhost——username=user -p 5433 mydatabase)。

如果不使用——host参数,psql将通过套接字进行连接,这在我的例子中是可行的,但我的Golang应用程序(使用TCP/IP)却不行。不幸的是,错误消息是用户“user”的密码验证失败,这是误导性的。解决方法是使用url连接字符串连接端口(例如postgres://user:password@localhost:5433/mydatabase)。

我的设置是数字海洋上的Ubuntu 18.04,通过apt-get安装postgres 9.5,所以不知道为什么会发生这种情况。希望这能为您节省一些时间。

我在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