Search code examples
ruby-on-railsherokuheroku-postgres

Heroku destroy_all 1/2 million rows seems to hang


On Heroku with Postgres

In the Heroku console when I do SiteInfo.destroy_all it just seems to hang. There are 1/2 million rows. What would be the best way to destroy these rows? Should I just do a migration to drop the table and then recreate it?

As per the comments be careful of you have callbacks. I do not. I just need to get rid of all these rows in the table fast and easy.


Solution

  • You could do something like

    ActiveRecord::Base.connection.execute("TRUNCATE site_infos")
    

    This will occur extremely quick in comparison to destroy_all as destroy_all loops through each record.