# 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:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![rahulMasal](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rahulmasal/32/213255_2.png) [@rahulMasal](https://meta.discourse.org/u/rahulMasal)
#### Post date: [September 12, 2021, 4:15am UTC](https://meta.discourse.org/t/delete-deleted-posts-permanently-in-bulk/203289/1 "2021-09-12T04:15:13Z")

</div>

Dear Team,

Please help me out to resolve this!

We have too many deleted-posts and we need to delete that permanently but in bulk!

 ![image](https://global.discourse-cdn.com/meta/original/3X/3/3/33ed15f271b374502ff1f8d56340599ff79ca448.png)

---

<div class="post-metadata">

### Author: ![itsbhanusharma](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/itsbhanusharma/32/180717_2.png) [@itsbhanusharma](https://meta.discourse.org/u/itsbhanusharma)
#### Post date: [September 12, 2021, 7:21am UTC](https://meta.discourse.org/t/delete-deleted-posts-permanently-in-bulk/203289/2 "2021-09-12T07:21:06Z")

</div>

A deleted topic is exactly what it is, a deleted topic. No further action is required and only admins can view such topics. You directly delete an already deleted topic.

---

<div class="post-metadata">

### Author: ![rahulMasal](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rahulmasal/32/213255_2.png) [@rahulMasal](https://meta.discourse.org/u/rahulMasal)
#### Post date: [September 12, 2021, 7:50am UTC](https://meta.discourse.org/t/delete-deleted-posts-permanently-in-bulk/203289/3 "2021-09-12T07:50:59Z")

</div>

i dont want in deleted topics list i want to clear them from DB.

so if any command or any way to delete those??

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [September 12, 2021, 8:22am UTC](https://meta.discourse.org/t/delete-deleted-posts-permanently-in-bulk/203289/4 "2021-09-12T08:22:22Z")

</div>

It’s not something I’ve done, but is this topic helpful:

> [@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):
>
> Hi. I would like to delete ALL topics from a single category (~5000 topics) in order to re-import these topics from phpbb. I could delete these topics, but since Discourse doesn’t really delete them but hide them, my phpbb import won’t re-import these messages. I can’t just re-import from scratch either because I did a lot of configuration since my import. Not only discourse admin config but also reorganized categories, moved hundreds of topics by keywords, filtered a lot of messages with reg…

---

<div class="post-metadata">

### Author: ![rahulMasal](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rahulmasal/32/213255_2.png) [@rahulMasal](https://meta.discourse.org/u/rahulMasal)
#### Post date: [September 12, 2021, 8:44am UTC](https://meta.discourse.org/t/delete-deleted-posts-permanently-in-bulk/203289/5 "2021-09-12T08:44:07Z")

</div>

Not Useful ☹ please help me if anything found?

---

<div class="post-metadata">

### Author: ![IAmGav](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/iamgav/32/235598_2.png) [@IAmGav](https://meta.discourse.org/u/IAmGav)
#### Post date: [September 12, 2021, 9:21am UTC](https://meta.discourse.org/t/delete-deleted-posts-permanently-in-bulk/203289/6 "2021-09-12T09:21:58Z")

</div>

maybe this can help you

> [@Bulk delete all topics in a category](https://meta.discourse.org/t/deleting-all-topics-in-a-category/97904):
>
> bookmark This guide provides instructions on how to bulk delete all topics within a category on a self-hosted Discourse instance. person_raising_hand Required user level: System Administrator warning SSH access to your server is required Removing all topics from a category can be necessary for various reasons, such as reorganizing content or clearing outdated discussions. This guide walks you through the steps to accomplish this task safely on a self-hosted Discourse server. …

---

<div class="post-metadata">

### Author: ![rahulMasal](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rahulmasal/32/213255_2.png) [@rahulMasal](https://meta.discourse.org/u/rahulMasal)
#### Post date: [September 12, 2021, 10:19am UTC](https://meta.discourse.org/t/delete-deleted-posts-permanently-in-bulk/203289/7 "2021-09-12T10:19:15Z")

</div>

![image](https://global.discourse-cdn.com/meta/original/3X/9/1/914b7d65bb9eeffd4419c6d87310d83f22238a50.png)

not showing deleted-posts category ??

---

<div class="post-metadata">

### Author: ![j127](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/j127/32/79093_2.png) [@j127](https://meta.discourse.org/u/j127)
#### Post date: [September 12, 2021, 11:34pm UTC](https://meta.discourse.org/t/delete-deleted-posts-permanently-in-bulk/203289/8 "2021-09-12T23:34:05Z")

</div>

> [@rahulMasal](#):
>
> deleted-posts

Do you have a category with the slug `deleted-posts`? The posts in your screenshot look like they are probably in categories that have different slugs.

![image](https://global.discourse-cdn.com/meta/original/3X/2/6/26cd96bbfa71be2d2f10160619f0b3b7070c5bab.png)

 ![image](https://global.discourse-cdn.com/meta/original/3X/3/1/31caae81e6d372eb6ca149fdecdfd30a5219e45e.png)

---

<div class="post-metadata">

### Author: ![rahulMasal](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rahulmasal/32/213255_2.png) [@rahulMasal](https://meta.discourse.org/u/rahulMasal)
#### Post date: [September 13, 2021, 9:29am UTC](https://meta.discourse.org/t/delete-deleted-posts-permanently-in-bulk/203289/9 "2021-09-13T09:29:12Z")

</div>

If I delete Category wise then all POSTS will delete which not in deleted-posts!

so can you help me to delete deleted-posts from DB.

---

<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: [September 13, 2021, 2:42pm UTC](https://meta.discourse.org/t/delete-deleted-posts-permanently-in-bulk/203289/10 "2021-09-13T14:42:25Z")

</div>

I’m trying to find a way to do this too. After much searching here on Meta, and a lot of trial and failure, I am now quite confused about it all.

Can we indeed permanently purge deleted posts from the database? How?

---

<div class="post-metadata">

### Author: ![IAmGav](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/iamgav/32/235598_2.png) [@IAmGav](https://meta.discourse.org/u/IAmGav)
#### Post date: [September 13, 2021, 2:57pm UTC](https://meta.discourse.org/t/delete-deleted-posts-permanently-in-bulk/203289/11 "2021-09-13T14:57:26Z")

</div>

if you can delete a category, then you can delete deleted posts.

rebuilding my test app now to install [data explorer](https://meta.discourse.org/t/32566?silent=true)

🙂

---

<div class="post-metadata">

### Author: ![j127](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/j127/32/79093_2.png) [@j127](https://meta.discourse.org/u/j127)
#### Post date: [September 13, 2021, 3:49pm UTC](https://meta.discourse.org/t/delete-deleted-posts-permanently-in-bulk/203289/12 "2021-09-13T15:49:49Z")

</div>

> [@rahulMasal](#):
>
> If I delete Category wise then all POSTS will delete which not in deleted-posts!

I’m not sure how to do it. I was just mentioning that the command you typed appears to be looking for a category with the slug `deleted-posts`.

---

<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: [September 17, 2021, 2:11am UTC](https://meta.discourse.org/t/delete-deleted-posts-permanently-in-bulk/203289/13 "2021-09-17T02:11:42Z")

</div>

> [@IAmGav](#):
>
> if you can delete a category, then you can delete deleted posts.

When you delete a category using the Rake task, all the posts (not just topics) within it are deleted. However, they are only soft deleted.

I remain unsure of how to actually remove posts from the database. I also remain unsure of how to get rid of the uploads associated with my deleted posts. Both are causing quite a headache at the mo.

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [September 17, 2021, 7:27am UTC](https://meta.discourse.org/t/delete-deleted-posts-permanently-in-bulk/203289/14 "2021-09-17T07:27:59Z")

</div>

> [@nathank](#):
>
> I also remain unsure of how to get rid of the uploads associated with my deleted posts. Both are causing quite a headache at the mo.

I _think_ the attachments will be cleaned up by one of the daily jobs, as long as they’re not part of the latest version of the post. So changing the deleted post to ‘(deleted by admin)’ or something would make its attachment part of the edit history and would then orphan it (thus scooping it up in the ‘clear orphan’ clean-up).

I am only theorising though, so this may be wrong. 🙂

Source:

> [@How to make an image orphaned so that it gets removed?](https://meta.discourse.org/t/how-to-make-an-image-orphaned-so-that-it-gets-removed/79231/3):
>
> All the details are available in this job
> 
> [https://github.com/discourse/discourse/blob/master/app/jobs/scheduled/clean\_up\_uploads.rb](https://github.com/discourse/discourse/blob/master/app/jobs/scheduled/clean_up_uploads.rb)
> 
> TL;DR: an image is orphaned if and only if it’s not referenced
> 
> - in the latest version of a post
> - in a draft
> - in a queued post
> - in a logo site setting
> - in a custom emoji
> - in a theme
> - in a user avatar/background/card image
> - in a category logo/background image

---

<div class="post-metadata">

### Author: ![IAmGav](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/iamgav/32/235598_2.png) [@IAmGav](https://meta.discourse.org/u/IAmGav)
#### Post date: [September 17, 2021, 7:31am UTC](https://meta.discourse.org/t/delete-deleted-posts-permanently-in-bulk/203289/15 "2021-09-17T07:31:30Z")

</div>

if you log into postgres, you can delete it out of the DB.

I am looking at the current rake destoy tasks and tying to understand how it works. Maybe the ppl that created the current destroy task can implement something for us to del deleted posts

---

<div class="post-metadata">

### Author: ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)
#### Post date: [September 17, 2021, 8:13am UTC](https://meta.discourse.org/t/delete-deleted-posts-permanently-in-bulk/203289/16 "2021-09-17T08:13:07Z")

</div>

> [@JammyDodger](#):
>
> I _think_ the attachments will be cleaned up by one of the daily jobs, as long as they’re not part of the latest version of the post.

Yes, that is correct.  
In order to get rid of an attachment, you need to remove the _contents_ of the post and then delete the post.

---

<div class="post-metadata">

### Author: ![rahulMasal](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rahulmasal/32/213255_2.png) [@rahulMasal](https://meta.discourse.org/u/rahulMasal)
#### Post date: [September 17, 2021, 8:34am UTC](https://meta.discourse.org/t/delete-deleted-posts-permanently-in-bulk/203289/17 "2021-09-17T08:34:17Z")

</div>

if you got command aur anything helpful and quick then please share with me!

---

<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: [September 17, 2021, 3:05pm UTC](https://meta.discourse.org/t/delete-deleted-posts-permanently-in-bulk/203289/18 "2021-09-17T15:05:47Z")

</div>

> [@RGJ](#):
>
> In order to get rid of an attachment, you need to remove the _contents_ of the post and then delete the post.

Thanks Richard and @JammyDodger!

My only issue is that I have 20,000 posts to do this to. Know any shortcuts?

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [September 17, 2021, 4:08pm UTC](https://meta.discourse.org/t/delete-deleted-posts-permanently-in-bulk/203289/19 "2021-09-17T16:08:56Z")

</div>

I’m afraid I’m at the start of my Discourse journey, so lack the necessary expertise for that. 🙂

Is it possible to amend this to target deleted posts rather than a user’s posts to achieve a similar thing?

> [@Deleting a users posts (with large post count+history)](https://meta.discourse.org/t/deleting-a-users-posts-with-large-post-count-history/82439/2):
>
> I think that what you’ll need to do is select all posts owned by the user and replace the post with Post deleted at request of user Something like Post.where("id = 123").update\_all(raw: "Post deleted...") That’s not tested. You’d want to test it. I’m not sure if you’d need to rebake those posts or not. Edit: I think that’d still leave the edit history, though. But, maybe only if there were an edit history.

---

<div class="post-metadata">

### Author: ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)
#### Post date: [September 17, 2021, 4:26pm UTC](https://meta.discourse.org/t/delete-deleted-posts-permanently-in-bulk/203289/20 "2021-09-17T16:26:22Z")

</div>

`Post.with_deleted.where('deleted_at is not null').update_all(raw: 'This post has been deleted', cooked: 'This post has been deleted')`

[Next page](https://meta.discourse.org/t/delete-deleted-posts-permanently-in-bulk/203289.md?page=2)
