Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails can't login to postgresql - PG::Error - password - Correct info

This is how my database.yml file looks (obviously there are relevant entries for testing and production as well)

development:
  adapter: postgresql
  encoding: unicode
  database: dbname_dev
  pool: 5
  username: username
  password: tehpass

In terminal I can successfully run the following and log in to the database:

psql -U username dbname_dev

However after creating this new rails project and running

rails g controller ComingSoon index

I get the following message when I go to localhost:3000/coming_soon (despite double and triple checking the login credentials)

fe_sendauth: no password supplied

Any ideas why I can log in to these databases via "psql" but Rails cannot?

like image 255
Tyler Willingham Avatar asked Mar 09 '12 07:03

Tyler Willingham


1 Answers

Database.yml:

connection: &connection
  adapter: postgresql
  encoding: unicode
  pool: 5
  username: username
  password: tehpass

development:
  <<: *connection
  database: dbname_development

test:
  <<: *connection
  database: dbname_test

production:
  <<: *connection
  database: dbname_production

If this is not working for you then, there might be something wrong during installation.

Visit this blog, hope this might help you out.


EDIT


ERROR CASE:

e_sendauth: no password supplied 

fe_sendauth: no password supplied

This happens under a stock Ubuntu install, and is due to the permissions in pg_hba.conf being too restrictive by default. To allow rails to connect, simply change the bottom of pg_hba.conf to look like this.

# TYPE  DATABASE    USER        CIDR-ADDRESS          METHOD

# "local" is for Unix domain socket connections only
local   all         all                               trust
# IPv4 local connections:
host    all         all         127.0.0.1/32          trust
# IPv6 local connections:
host    all         all         ::1/128               trust

Let me know if this helps or not?

like image 117
Manish Das Avatar answered Oct 23 '22 09:10

Manish Das