0

I am running the command "rails server", but when it launches, it gives out the following error:

PG::ConnectionBad
FATAL: password authentication failed for user "app_name" FATAL: password authentication failed for user "app_name" 

I cant figure out, what might be the problem, here is my GemFile:

development:
  adapter: postgresql
  encoding: unicode
  database: app_development
  host: localhost
  pool: 5
  username: app_name
  password: password

I am running Rails on Ubuntu with posgresql db.

2 Answers2

1

I'm going to assume you don't have a postgres user account set up.

Run this command:

sudo -u postgres psql postgres

This will log you into postgres as the postgres super user. You are then going to want to create a user

CREATE ROLE my_app PASSWORD 'password' SUPERUSER CREATEDB CREATEROLE INHERIT LOGIN;

Create DB is the important permission. The rest shouldn't really matter, see documentation for more information.

Then in your database.yml

development:
  adapter: postgresql
  encoding: unicode
  database: my_app_development
  pool: 5
  username: my_app
  password: password    
  host: localhost
  port: 5432

Then you should be able to run rake db:create to create the my_app_development database via the my_app user.

DVG
  • 17,144
  • 7
  • 58
  • 82
  • Well, I try to run rake db:create and it gives me out this error="Couldn't create database for {"adapter"=>"postgresql", "encoding"=>"unicode", "database"=>"app_development", "host"=>"localhost", "pool"=>5, "username"=>"app_name", "password"=>"password"}"; do you know what that means? – John Karver May 26 '15 at 20:08
  • That's the generic response when creation fails. There may be more information in the stack trace that points to what exactly went wrong. The only thing from the final error that it might be is the port is missing. – DVG May 26 '15 at 20:09
0

First, I hope that's not really your "GemFile", I hope it's your config/database.yml file.

Second, I feel a bit silly doing this, because the error you've shown seems really clear to me, but maybe you just need the error rephrased. You have configured your app to login to your postgresql database using a username of app_name and a password of password. Those credentials are not valid for your database.

smathy
  • 23,746
  • 5
  • 45
  • 66