bigpotato
bigpotato

Reputation: 27507

Rails + Postgres fe_sendauth: no password supplied

Hi I'm trying to hook up postgresql to my rails project. I'm learning testing but my tests aren't running because of a postgresql error about having an incorrect password:

Edmunds-MacBook-Pro:langexchange edmundmai$ rake test:units
rake aborted!
fe_sendauth: no password supplied

I've already read around and my pg_hba.conf file was originally already like this:

# TYPE  DATABASE        USER            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
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local   replication     edmundmai  

here's my database.yml file in my rails project

default: &default
  adapter: postgresql
  encoding: utf8
  pool: 5
  username: edmundmai
  password: 

development:
  <<: *default
  database: project_development

test:
  <<: *default
  database: project_test

production:
  <<: *default
  database: project_production

Does anyone know how I could fix this? We can chat if it's easier.

Upvotes: 29

Views: 61778

Answers (4)

Kras
Kras

Reputation: 1

You need only to create the user/passw and schema(db) in postgres with pgadmin and put user/passw in database.yml. When I tryed to create database with rake db:create in current rails project folder, it failed, and trowed to me error could't create for postgreSQL adapter. After that I created the schema for rails project with pgadmin, everyrthing is fine without any changes in pg_hba.conf.

Upvotes: 0

danielricecodes
danielricecodes

Reputation: 3586

Be sure that you have defined both RAILS_ENV and RACK_ENV on your production hosting server. I had a similar issue crop up where everything worked except rake and the solution was to add RACK_ENV=production to my environment. RAILS_ENV was already set to production.

export RACK_ENV=production

bundle exec rake db:version

You should see some output such as:

Current version: 20121126151935

Solution: make sure your Rails app has access to the RAILS_ENV and RACK_ENV environmental variables. Also, ensure they're both the same value.

Upvotes: 22

andreofthecape
andreofthecape

Reputation: 1196

On your local machine under the test and development sections of the database.yml file you should change the username to your logged in username. The rails generator makes it the same as your appname and that will not work. The production section will depend on your production setup. If you use heroku you do not need to change anything there.

Upvotes: 4

Thanh
Thanh

Reputation: 8604

First you should change:

local   all             all                                     trust

to:

local   all             all                                     md5

Then, You should create a super_user in PostgreSQL with username and password,after that adding username and password of new user to your database.yml file.

To create new super_user, open Pg Admin III and right click at the bottom Login Roles to create new super user.

Upvotes: 11

Related Questions