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.

  • Can you log into using psql as app_name/password? I'm guessing you can't – DVG May 26 '15 at 19:47
  • nope, the hole thing screwed up (I am new to rails and especially postgresql). any way out? – John Karver May 26 '15 at 19:53
  • How did you set up your postgres database? Did you create this user already? – DVG May 26 '15 at 19:55
  • I logged into the database (sudo -u postgres psql); then I've created the user (CREATE USER app_name WITH PASSWORD 'password';). Then I've created the database (CREATE DATABASE app_development OWNER app_name;); – John Karver May 26 '15 at 20:02

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,392
  • 7
  • 61
  • 88
  • 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
  • 26,283
  • 5
  • 48
  • 68