If you created the database with the web UI on postgres.heroku.com, you need to navigate to it from https://postgres.heroku.com/databases , then click on the gear icon on the right. There should be a destroy link.
All Heroku Postgres databases have a corresponding Heroku application. You can find the application name on the database page at data.heroku.com. Your database is attached to the Heroku app and is accessible via an app config var containing the database URL, even if you host no code in the application itself.
Heroku Postgres delivers the world's most advanced open source database as a trusted, secure, and scalable service that is optimized for developers.
To drop the database, if you are using SHARED_DATABASE_URL
:
$ heroku pg:reset DATABASE_URL
Now to recreate the database with nothing in it:
$ heroku run rake db:migrate
To populate the database with your seed data:
$ heroku run rake db:seed
---OR---
You can combine the last two (migrate & seed) into one action by executing this:
$ heroku run rake db:setup
Edit 2014-04-18: rake db:setup
doesn't work with Rails 4, it fails with a Couldn't create database error
.
Edit 2014-10-09: You can use rake db:setup
with Rails 4. It does give you a Couldn't create database
error (because the database was already created using the heroku pg:reset
command). But it also loads your database schema and your seeds after the error message.
You can do this with pretty much any rake command, but there are exceptions. For example, db:reset
doesn't work via heroku run rake
. You have to use pg:reset
instead.
More information can be found in Heroku's documentation:
Running Rake Commands
Reset Postgres DB
Heroku has deprecated the --db
option now, so now use:
heroku pg:reset DATABASE_URL --confirm {the name of your app}
It's a little confusing because you use the literal text SHARED_DATABASE
but where I have written {the name of your app}
substitute the name of your app. For example, if your app is called my_great_app then you use:
heroku pg:reset DATABASE_URL --confirm my_great_app
To drop the database:
$ heroku pg:reset SHARED_DATABASE --confirm NAME_OF_THE_APP
To recreate the database:
$ heroku run rake db:migrate
To seed the database:
$ heroku run rake db:seed
**Final step
$ heroku restart
The current, ie. 2017 way to do this is:
heroku pg:reset DATABASE
https://devcenter.heroku.com/articles/heroku-postgresql#pg-reset
Now the command is
heroku pg:reset DATABASE_URL --confirm your_app_name
this way you can specify which app's db you want to reset. Then you can run
heroku run rake db:migrate
heroku run rake db:seed
or direct for both above commands
heroku run rake db:setup
And now final step to restart your app
heroku restart
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With