How to empty a Heroku database

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