1

Good afternoon,

I browsed the other questions on this topic, and it appears nobody has asked about this issue. I was expecting otherwise!

In any case - I have a PostgreSQL database server running on my local machine with a MYAPP_DEVELOPMENT database. I've tried to do a

heroku db:push

But keep getting the following error:

Failed to connect to database:
Sequel::DatabaseConnectionError -> PGError: FATAL:  role "brandon" does not exist

This obviously has something to do with the permissions & users on the local/heroku shared database, but I'm honestly not that good with this kind of stuff. Any help would be appreciated. I'm currently including the "database.yml" file in my slug to Heroku, which has all of the login/password info for my local database... hence why I was not expecting this kind of error.

Thanks!

** EDIT ** Here is the contents of my database.yml file (edited for clarity):

common: &common
  adapter: postgresql
  encoding: unicode
  username: user
  password: secret

test:
  <<: *common
  database: myapp_test

development:
  <<: *common
  database: myapp_development

production:
  <<: *common
  database: myapp_production

I figure it must be something on the Heroku setup side. Note that nowhere in my database.yaml file does "brandon" show up. I'm not quite sure where it is pulling that from. My database user name is not that (although that is my name haha)

Brandon
  • 3,091
  • 2
  • 34
  • 64

3 Answers3

1

This error generally means a username has not been specified under the appropriate environment in your database.yml file.

Your database.yml file should resemble the following (I use MySQL locally, hence the adapter and socket parameters):

common: &common
  adapter: mysql2
  encoding: utf8
  reconnect: false
  pool: 5
  username: <your_username>
  password: <your_password>
  socket: /tmp/mysql.sock

development:
  <<: *common
  database: appname_dev

test:
  ...

staging:
  ...

production:
  <<: *common
  database: appname_prod

If that doesn't solve your problem, check to ensure Heroku is running in the correct environment:

  • heroku config --app <appname>
  • Ensure RACK_ENV is set to production
  • If not: heroku config:add RACK_ENV=production --app <appname>

(It would have been helpful if you pasted the contents of your database.yml file.)

Graham Swan
  • 4,818
  • 2
  • 30
  • 39
  • Included the contents of my databse.yml file above. Heroku is running in the production environment. Thanks for answering though! – Brandon Jan 31 '12 at 03:28
0

You will have to use the Heroku specific ENV var to use the DB which is usually ENV['DATABASE_URL']

Edit: If you have a db mapper like datamapper you'd write it like this:

DataMapper.setup(:default, ENV['DATABASE_URL'] || LOCAL_DB_URL)

which then either uses the Heroku DB if it exists or defaults to your local DB which is stored in the LOCAL_DB_URL var.

three
  • 8,262
  • 3
  • 35
  • 39
  • My heroku ENV['DATABASE_URL'] is set to the postres://blahhhhh.amazonws.com/blah value... (i.e. I'm not using an external database). Should the db:push not just work under those conditions? – Brandon Jan 31 '12 at 03:30
  • heroku sets that ENV var for you. You just have to use it. But that's in the Heroku docs. – three Jan 31 '12 at 07:39
  • Thanks for getting back to me. How do I set this up then in my Heroku config and/or database.yml file? I am using ActiveRecord and a Postgres database. I could swear I've pushed my local dev database to Heroku before without any fiddling – Brandon Jan 31 '12 at 09:10
-1

Thanks for everyone's input to this one. I ended up fixing my issue by explicitly providing my login details to Heroku during the db:push... e.g.:

heroku db:push postgres://postgres:PASSWORD@127.0.0.1:5432/DATABASE

Not sure why it isn't using the (same) information in my database.yml file, but oh well.

Brandon
  • 3,091
  • 2
  • 34
  • 64