FATAL: Ident authentication failed for user "postgres"

时间:2019-05-19 01:26:04  来源:igfitidea点击:

在用ROR和PostgreSQL配置一个新的主机设置时。
当应用程序试图连接postgres数据库服务器时,出现以下问题。

错误:

FATAL: Ident authentication failed for user "postgres"
致命:用户“postgres”的Ident认证失败

解决方案:-

首先,使用下面的命令在PostgreSQL中设置postgres用户的密码。

$ sudo -u postgres psql

现在使用下面的命令设置密码。

postgres=# password

使用以下命令为应用程序创建一个新的用户帐户。
同时创建一个该账户所有的数据库

postgres=# create user "myappusr" with password '_password_';
postgres=# create database "myapp_development" owner "myappusr";

现在编辑pg_hba postgresql配置文件并更新配置。
默认情况下,PostgreSQL使用基于身份验证。
我们需要允许基于用户名和密码的身份验证。
IDENT将永远不允许我们通过-U和-W选项登录。

# vim /var/lib/pgsql/9.4/data/pg_hba.conf

local   all             postgres                                trust
local   all             myapp_usr                               trust
# IPv4 local connections:
host    all             all             127.0.0.1/32            trust
# IPv6 local connections:
#host    all             all             ::1/128                 trust