Rails postgresql数据库连接失败

时间:2012-02-28 23:41:04

标签: ruby-on-rails ruby postgresql

我是Ruby和postgres的新手。

以下是我的database.yml

development:
  adapter: postgresql
  database: test_database
  username: postgresql
  password: mypassword
  host: localhost
  encoding: utf8

用户存在,我可以使用phpPgadmin中的相同凭据登录。但是,当我启动rails服务器并转到应用程序的主页时,我得到FATAL: Ident authentication failed for user "postgresql"

编辑:如果pghba.conf很重要,

# TYPE  DATABASE          USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
#local    all             all                                     peer
local     all             postgres                                md5
local     all             postgresql                              md5

有人可以帮忙吗?

3 个答案:

答案 0 :(得分:2)

打开PostgreSQL客户端身份验证配置文件

vi /var/lib/pgsql/data/pg_hba.conf

此文件管理以下内容

  1. 允许哪些主机连接
  2. 客户端的身份验证方式
  3. 他们可以使用哪些PostgreSQL用户名
  4. 他们可以访问哪些数据库
  5. 默认情况下,Postgresql使用基于IDENT的身份验证。您所要做的就是为您的网络或网络服务器提供基于用户名和密码的身份验证。 IDENT永远不会允许您通过-U和-W选项登录。附加以下内容仅允许通过localhost登录:

    local   all all         trust
    host    all 127.0.0.1/32    trust
    

    保存并关闭文件。 重新启动Postgresql服务器:

    service postgresql restart   OR
    sudo /etc/init.d/postgresql restart
    

    应该有效

答案 1 :(得分:1)

我可以在路径中找到 pg_hba.conf 文件:

/etc/postgresql/8.4/main/pg_hba.conf

答案 2 :(得分:1)

对于仍然无法找到 pg_hba.conf 文件的人,我正在使用PostgreSQL v9.2,我发现了我的:

/var/lib/pgsql/9.2/data/pg_hba.conf
相关问题