# Delete deleted-posts permanently in bulk?

**URL:** <https://meta.discourse.org/t/delete-deleted-posts-permanently-in-bulk/203289>\
**Category:** Support\
**Created:** [September 12, 2021, 4:15am UTC](https://meta.discourse.org/t/delete-deleted-posts-permanently-in-bulk/203289 "2021-09-12T04:15:12Z")\
**Posts on this page:** 1\
**Showing post:** 38

<div class="post-metadata">

**Author:** ![nathank](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nathank/32/290039_2.png) [@nathank](https://meta.discourse.org/u/nathank)\
**Post date:** [October 30, 2021, 12:27am UTC](https://meta.discourse.org/t/delete-deleted-posts-permanently-in-bulk/203289/38 "2021-10-30T00:27:37Z")

</div>

In order to delete the old posts on our forum, I used this. It is the result of combining [The proper way to completely delete hundred of topics via rails?](https://meta.discourse.org/t/the-proper-way-to-completely-delete-hundred-of-topics-via-rails/90323) and @RGJ’s suggestions.

I chose to do this in the end, as I really wanted to remove the data from the database to protect the privacy of users. Rewriting the text to “This post has been deleted” still leaves the edit history intact and relatively easily accessible, so not good enough.

As we had 20,000 topics to destroy, it took a while!

```plaintext
Topic.with_deleted.where("deleted_at < '2021-08-28'").limit(1000).destroy_all

```

As this left a lot of orphaned posts, I had to follow it up with:

```plaintext
Post.where('topic_id not in (select id from topics)').limit(1000).destroy_all

```

---

_[View the full topic](https://meta.discourse.org/t/delete-deleted-posts-permanently-in-bulk/203289)._
