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

本文是小编为大家收集整理的关于Rails postgresql数据库连接失败的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我是Ruby和Postgres的新手.

下面是我的数据库.yml

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

用户存在,我可以在phppgadmin中使用相同的凭据登录.但是,当我启动Rails Server并转到App的主页时,我会得到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

任何人都可以帮忙吗?

推荐答案

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

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

此文件在下面管理

  1. 允许哪些主机连接
  2. 如何认证客户
  3. 他们可以使用哪个PostgreSQL用户名
  4. 他们可以访问哪些数据库

默认情况下,PostgreSQL使用基于标识的身份验证.您要做的就是允许您的网络或网络服务器基于用户名和密码的身份验证. 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

它应该工作

其他推荐答案

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

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

其他推荐答案

对于仍然找不到 pg_hba.conf 文件的任何人,我正在使用PostgreSQL v9.2,我在以下位置找到了我的:

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

本文地址:https://www.itbaoku.cn/post/1764110.html

问题描述

I'm very new to Ruby and postgres.

Below is my database.yml

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

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".

Edit: 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

Could anyone please help ?

推荐答案

open PostgreSQL client authentication configuration file

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

This file manage below stuffs

  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

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

Save and close the file. Restart Postgresql server:

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

It should work

其他推荐答案

I can find my pg_hba.conf file in the path:

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

其他推荐答案

For anyone who still can't find their pg_hba.conf file, I'm using PostgreSQL v9.2 and I found mine in:

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