简体   繁体   中英

Rails postgresql DB connection fails

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

我可以在路径中找到我的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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM