database 用户“postgres”的密码认证失败

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7038342/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 08:18:31  来源:igfitidea点击:

password authentication failed for user "postgres"

databasepostgresql

提问by Chan Pye

I have installed PostgreSQL server 8.4 on my CentOS server sucessfully. After that, I login to CentOS server by using 'postgres' user, but I can not run any command, the error occur:

我已经在我的 CentOS 服务器上成功安装了 PostgreSQL 服务器 8.4。之后,我使用'postgres'用户登录CentOS服务器,但我无法运行任何命令,出现错误:

password authentication failed for user "postgres"

用户“postgres”的密码认证失败

Here is some configurations in pg_hba.conf and postgresql.conf:

下面是 pg_hba.conf 和 postgresql.conf 中的一些配置:

--------------------configuration in postgresql.conf-----------
listen_addresses = '*'

--------------------configuration in pg_hba.conf---------------
local   all         all                               md5  
local   all         postgres                          md5 
host    all         all         127.0.0.1/32          md5  
host    all         all         ::1/128               md5

回答by Berry Langerak

I tend to use the following in pg_hba.conf:

我倾向于在 pg_hba.conf 中使用以下内容:

# Database administrative login by UNIX sockets
local   all         postgres                          ident

# TYPE  DATABASE    USER        CIDR-ADDRESS          METHOD
local   all         all                               md5
host    all         all         127.0.0.1/32          md5
host    all         all         ::1/128               md5

That means that once you're "postgres", you don't need a password, but you need sudo rights to become postgres, so that's pretty darn secure. Any other user can login using simple md5 authentication, which means you don't have to sudo all over the place. This works well for me.

这意味着一旦你成为“postgres”,你就不需要密码,但你需要 sudo 权限才能成为 postgres,所以这是非常安全的。任何其他用户都可以使用简单的 md5 身份验证登录,这意味着您不必到处 sudo。这对我很有效。

回答by Daniel

Ensure you use the password of the postgres PostgreSQL account, not the postgres system account. Try "trust" instead of "md5" in the pg_hba.conf to connect to the db an change your pass.

确保您使用的是 postgres PostgreSQL 帐户的密码,而不是 postgres 系统帐户的密码。在 pg_hba.conf 中尝试“信任”而不是“md5”以连接到数据库并更改您的通行证。

回答by Hoàng Long

I met a similar problem (the same error message). Like Daniel answer, it's because that I confuse between :

我遇到了类似的问题(相同的错误消息)。就像丹尼尔的回答一样,这是因为我混淆了:

"postgres PostgreSQL account, not the postgres system account."

“postgres PostgreSQL 帐户,而不是 postgres 系统帐户。”

To be sure about the postgres password, just change it to '123456' (or any other password)

要确定 postgres 密码,只需将其更改为“123456”(或任何其他密码)

# su postgres
# psql -d template1
template1=# ALTER USER postgres WITH PASSWORD '123456';