Rails Postgresql数据库连接失败 [英] Rails postgresql DB connection fails

查看:77
本文介绍了Rails Postgresql数据库连接失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Ruby和postgres的新手。

I'm very new to Ruby and postgres.

下面是我的数据库。yml

Below is my database.yml

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

用户存在,我可以使用phpPgadmin中的相同凭据登录。但是,当我启动Rails服务器并转到应用程序的主页时,我得到了 FATAL:用户 postgresql的身份验证失败

The user exists and I'm, able to login using same credentials in phpPgadmin. But when I start rails server and go to home page of app, I get FATAL: Ident authentication failed for user "postgresql".

编辑:万一pghba.conf很重要,

In case pghba.conf matters,

# 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

有人可以帮忙吗?

推荐答案

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

open PostgreSQL client authentication configuration file

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

此文件管理以下内容


  1. 允许使用哪些主机连接

  2. 如何验证客户端

  3. 哪个Postgr他们可以使用的eSQL用户名

  4. 可以访问的数据库

  1. Which hosts are allowed to connect
  2. How clients are authenticated
  3. Which PostgreSQL user names they can use
  4. Which databases they can access

默认情况下,PostgreSQL使用IDENT基于身份的身份验证。您要做的就是允许您的网络或Web服务器基于用户名和密码的身份验证。 IDENT绝对不允许您通过-U和-W选项登录。追加以下内容以仅允许通过本地主机登录:

By default Postgresql uses IDENT-based authentication. All you have to do is allow username and password based authentication for your network or webserver. IDENT will never allow you to login via -U and -W options. Append following to allow login via localhost only:

local   all all         trust
host    all 127.0.0.1/32    trust

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

Save and close the file. Restart Postgresql server:

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

应该可以工作

这篇关于Rails Postgresql数据库连接失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆