Search code examples
ruby-on-railspostgresqlherokurails-postgresql

Problems with heroku rake db:reset


I have a problem, I pushed my app to github and I made the deploy with heroku, everything was ok, but when I run heroku run --app myapp rake db:reset (to populate the database on heroku) I found the following messages filled with errors (I show only the part that I think is important because the message was too long)

FATAL:  permission denied for database "postgres"
DETAIL:  User does not have CONNECT privilege.
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `initialize'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `new'
.
.
.
/app/vendor/bundle/ruby/2.0.0/bin/rake:23:in `load'
/app/vendor/bundle/ruby/2.0.0/bin/rake:23:in `<main>'
Couldn't drop d5q6ajst4p4d97
FATAL:  permission denied for database "postgres"
DETAIL:  User does not have CONNECT privilege.
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `initialize'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `new'
.
.
.
/app/vendor/bundle/ruby/2.0.0/bin/rake:23:in `load'
/app/vendor/bundle/ruby/2.0.0/bin/rake:23:in `<main>'
Couldn't create database for {"adapter"=>"postgresql", "encoding"=>"utf8", "database"=> [DATABASE], "pool"=>5, "username"=> [USERNAME], "password"=> [PASSWORD], "port"=>5432, "host"=> [HOST]}
-- enable_extension("plpgsql")
   -> 0.0370s
-- create_table("heros", {:force=>:cascade})
   -> 0.0307s
-- initialize_schema_migrations_table()
   -> 0.0579s

Note: I'm hiding the username, password, etc...

Everything works fine in the deployed app, but I find ugly to see so many mistakes when making a rake db: reset in heroku, so after seeing this I searched how to solve this problem and found some posts that preach the same solution, so I followed the recommendations and run the command heroku pg:reset DATABASE_URL --app myapp, it ended succesfully, but the same error message appears when I tried again to run rake db:reset, What could be happening?

This is my database.yml

development:
  adapter: postgresql
  encoding: utf8
  database: project_development
  pool: 5
  username:
  password:

test:
  adapter: postgresql
  encoding: utf8
  database: project_test
  pool: 5
  username:
  password:

production:
  adapter: postgresql
  encoding: utf8
  database: project_production
  pool: 5
  username:
  password:

Solution

  • Heroku, being a shared service is not allowing users the permissions to drop nor create databases - hence the error when running rake db:reset

    Hence heroku pg:reset is present as a command to perform the reset of your database.

    See https://devcenter.heroku.com/articles/rake