12

I'm working on an application in Rails for my college. The application was started by the students from previous year and now it's me and my colleagues turn to continue work on it. I took the application from github, I run bundle install, but when to run rake db:migrate I got this PG::ConnectionBad: FATAL: password authentication failed for user "alphauser". In database.yml I have these

 development:
  adapter: postgresql
  encoding: unicode
  database: alpha_database
  host: localhost
  pool: 5
  username: alphauser
  password: alphapassword

I don't know what to do in this case.

Madalina
  • 457
  • 1
  • 5
  • 14

4 Answers4

18

You have to create corresponding user and database manually like this:

in shell: psql

then:

  create user alphauser with password 'alphapassword';
  create database alpha_database owner alphauser;
  alter user alphauser superuser createrole createdb replication;
  \q

don't forget semicolons.

Mikhail Chuprynski
  • 2,404
  • 2
  • 29
  • 42
  • 2
    I couldn't even create a new user. Something about not having the permissions to do so. So I first did `$ sudo su - postgres`, entered my password (I'm on Ubuntu) before calling `psql` and then I continued with your answers. – blue_chip Feb 10 '17 at 22:15
  • How can you log into `psql` when enter `psql` on the terminal also unsuccessful? – Huy Vo Jan 13 '18 at 12:03
5

Try to use:

sudo -u postgres createuser --interactive --pwprompt

to add the role and the password

Salma Gomaa
  • 952
  • 1
  • 13
  • 18
3

So the problem is with your rails application using the database.yml file to try and connect to your local database and failing to find the user alphauser (since I assume you're using different computers/environments as the previous students).

Databases have users similar to applications, the postgres documentation is pretty dense on this, but I would guess if you can create a user alphauser, and make it's password alphapassword then you will have a new clean database for your app that you can run rake db:migrate on.

Postgres docs: http://www.postgresql.org/docs/9.2/static/app-createuser.html

Try running this command from the command line createuser -P -s -e alphauser

This will prompt for a password, which is alphauserpassword

george
  • 153
  • 7
1
 create user alphauser with password 'alphapassword';

Then

rake db:setup
vidur punj
  • 5,019
  • 4
  • 46
  • 65