【发布时间】:2017-07-25 12:35:48
【问题描述】:
我正在尝试使用我不熟悉的 Postgres 数据库设置我的 rails 应用程序。
我正在使用
- centos 6
- postgresql 9.6.2
- pg_hba.conf 路径 =>
/var/lib/pgsql/data/pg_hba.conf
我使用sudo -u postgres psql 登录并使用密码“password”创建了用户“X”。以下是详细内容
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
--------------+--------------+----------+-------------+-------------+-------------------------------
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
trip_staging | X | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =Tc/X +
| | | | | X=CTc/X
(4 rows)
postgres=# \du
List of roles
Role name | Attributes | Member of
--------------+------------------------------------------------------------+-----------
X | | {}
postgres | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
当我运行命令时:
RAILS_ENV=staging bundle exec rake db:create
我收到以下错误:
FATAL: Ident authentication failed for user "X"
Couldn't create database for {"database"=>"trip_staging", "adapter"=>"postgresql", "username"=>"X", "password"=>"password", "host"=>"localhost", "port"=>5432, "pool"=>5, "timeout"=>5000}
在此之后,我查找了每个可能的解决方法。我尝试使用以下配置更改 pg_hba.conf:
TYPE DATABASE USER ADDRESS METHOD
local all all md5
host all all 0.0.0.0 md5
host all all ::1/128 md5
也试过了,用trust更改METHOD,然后用命令重新启动postgresql服务器:sudo service postgresql-9.6 restart但同样的错误。
还尝试将路径/var/lib/pgsql/data/pg_hba.conf 的读取权限从600 更改为755。为此,我必须使用 sudo su - postgres 以 postgres 超级用户身份登录,这很奇怪。然后重启了postgresql服务器
也尝试过,将路径 /var/lib/pgsql/9.6/data/pg_hba.conf 的方法从 ident 更改为 trust,因为显然也存在版本明智的 pg_hba.conf。然后我重新启动了 PostgreSQL 服务器。
到目前为止似乎没有任何效果。请帮助找出缺少的内容。
【问题讨论】:
标签: ruby-on-rails ruby linux postgresql centos