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

当前回答

编辑pg_hba.conf文件,Debian在/etc/postgresql/9.3/main/pg_hba.conf, Red Hat/IBM在/var/lib/pgsql/9.4/data/pg_hba.conf

将所有身份验证方法更改为信任。 修改Linux postgres用户密码。 重新启动服务器。 使用psql -h localhost -U postgres登录,并使用刚才设置的Unix密码。 如果它工作,你应该重新设置pg_hba.conf文件的值md5或ident方法,并重新启动。

其他回答

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

sudo passwd postgres

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

遵循以下步骤:

Sudo -u postgres -i psql postgres \密码

之后,输入两次密码。

然后在pgAdmin4中使用该密码。

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

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

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

# 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 psql -c “ALTER USER postgres PASSWORD 'postgres' ;”

完成了!您保存了User = postgres和password = postgres。

如果你没有postgres ubuntu用户的密码,请:

$ sudo passwd postgres