Postgresql:用户"postgres"的密码身份验证失败 [英] Postgresql: password authentication failed for user "postgres"

查看:1547
本文介绍了Postgresql:用户"postgres"的密码身份验证失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经安装了PostgreSQL 8.4,Postgres客户端和Pgadmin3.对于控制台客户端和Pgadmin的用户"postgres",身份验证失败.我已经输入user为"postgres"和密码为"postgres",因为以前可以使用.但是现在身份验证失败.我之前几次都没​​有出现此问题.我该怎么办?会发生什么?

I have installed PostgreSQL 8.4, Postgres client and Pgadmin 3. Authentication failed for user "postgres" for both console client and Pgadmin. I have typed user as "postgres" and password "postgres", because it worked before. But now authentication is failed. I did it before a couple of times without this problem. What should I do? And what happens?

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"

推荐答案

如果我没有记错的话,默认情况下,用户postgres在Ubuntu上没有设置 DB 密码.这意味着,您只能使用postgres OS用户帐户登录该帐户.

If I remember correctly the user postgres has no DB password set on Ubuntu by default. That means, that you can login to that account only by using the postgres OS user account.

假设您可以在框中执行root访问权限,

Assuming, that you have root access on the box you can do:

sudo -u postgres psql

如果失败并显示database "postgres" does not exists错误,则您很可能不在Ubuntu或Debian服务器上:-)在这种情况下,只需在命令中添加template1:

If that fails with a database "postgres" does not exists error, then you are most likely not on a Ubuntu or Debian server :-) In this case simply add template1 to the command:

sudo -u postgres psql template1

如果这些命令中的任何一个因错误psql: FATAL: password authentication failed for user "postgres"而失败,则检查文件/etc/postgresql/8.4/main/pg_hba.conf:必须有这样的行作为第一行非注释行:

If any of those commands fail with an error psql: FATAL: password authentication failed for user "postgres" then check the file /etc/postgresql/8.4/main/pg_hba.conf: There must be a line like this as the first non-comment line:

local   all         postgres                          ident

对于PostgreSQL的较新版本,ident实际上可能是peer.没关系.

For newer versions of PostgreSQL ident actually might be peer. That's OK also.

psql外壳程序内,您可以为 DB用户 postgres设置密码:

Inside the psql shell you can give the DB user postgres a password:

ALTER USER postgres PASSWORD 'newPassword';

您可以通过键入 Ctrl D 或使用命令\q离开psql外壳.

You can leave the psql shell by typing CtrlD or with the command \q.

现在,您应该能够为pgAdmin提供数据库超级用户的有效密码,这也将很高兴. :-)

Now you should be able to give pgAdmin a valid password for the DB superuser and it will be happy too. :-)

这篇关于Postgresql:用户"postgres"的密码身份验证失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆