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

当前回答

对于那些第一次使用它,不知道密码是什么的人,他们可以遵循以下步骤(假设你是ubuntu):

3 .打开/etc/postgresql/9.x/main目录下的pg_hba.conf文件 Sudo vi pg_hba.conf .conf 2.编辑下面的行 本地所有postgres peer 来 本地所有postgres信任 重新启动服务器 Sudo服务postgresql重启 最后,您可以登录,无需密码,如图所示

更多信息请参考这里

其他回答

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

进入postgres shell后,输入以下命令

postgres=# \password postgres

输入此命令后,将提示您设置密码,只需设置密码,然后尝试。

工作人员的反应是正确的,但如果你想进一步自动化可以做:

$ sudo -u postgres psql -c “ALTER USER postgres PASSWORD 'postgres' ;”

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

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

$ sudo passwd postgres

对于那些第一次使用它,不知道密码是什么的人,他们可以遵循以下步骤(假设你是ubuntu):

3 .打开/etc/postgresql/9.x/main目录下的pg_hba.conf文件 Sudo vi pg_hba.conf .conf 2.编辑下面的行 本地所有postgres peer 来 本地所有postgres信任 重新启动服务器 Sudo服务postgresql重启 最后,您可以登录,无需密码,如图所示

更多信息请参考这里

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

# 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