8

I'm able to type rails s without any issues inside of an app using postgres.app on Mac using postgres.app, however, when I go to localhost:3000 it gives me this error:

PG::ConnectionBad
FATAL: role "myapp" does not exist

I thought at first the problem was the database.yml file but heroku docs even say to have it the way it is: https://devcenter.heroku.com/articles/getting-started-with-rails4

development:
adapter: postgresql
encoding: unicode
database: myapp_development
pool: 5
username: myapp
password:

Here is my full log. I've seen similar issues but they only vaguely relate to this.

snippet:

Started GET "/" for 127.0.0.1 at 2014-03-25 16:48:31 -0600

PG::ConnectionBad (FATAL:  role "myapp" does not exist
):
  activerecord (4.0.2) lib/active_record/connection_adapters/postgresql_adapter.rb:831:in `initialize'
  activerecord (4.0.2) lib/active_record/connection_adapters/postgresql_adapter.rb:831:in `new'
  activerecord (4.0.2) lib/active_record/connection_adapters/postgresql_adapter.rb:831:in `connect'
  activerecord (4.0.2) lib/active_record/connection_adapters/postgresql_adapter.rb:548:in `initialize'
  activerecord (4.0.2) lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `new'
  activerecord (4.0.2) lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `postgresql_connection'
  activerecord (4.0.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:440:in `new_connection'
  activerecord (4.0.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:450:in `checkout_new_connection'
  activerecord (4.0.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:421:in `acquire_connection'
  activerecord (4.0.2)  lib/active_record/connection_adapters/abstract/connection_pool.rb:356:in `block in checkout'
  /Users/johncurry/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
  activerecord (4.0.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:355:in `checkout'
  activerecord (4.0.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:265:in `block in connection'
  /Users/johncurry/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
  activerecord (4.0.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:264:in `connection'
  activerecord (4.0.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:546:in 

any suggestions?

user3138341
  • 219
  • 2
  • 3
  • 12
  • 1
    Possible duplicate of [PG::ConnectionBad FATAL: role "Myname" does not exist](http://stackoverflow.com/questions/23338356/pgconnectionbad-fatal-role-myname-does-not-exist) – Meekohi Apr 12 '16 at 15:41

3 Answers3

13

It would appear that you have not created a user account for the application. In psql:

CREATE USER myapp WITH PASSWORD 'thepassword';

You'll also need to create a DB if you haven't:

CREATE DATABASE myapp_development OWNER myapp;
Craig Ringer
  • 307,061
  • 76
  • 688
  • 778
1

That's the best solution.

sudo -u postgres createuser -s myapp
0

You need to create the Postgres user on your local machine. The role is your username.

CWitty
  • 4,488
  • 3
  • 23
  • 40