# Permanent deletion: Is there a database command?

**URL:** https://meta.discourse.org/t/permanent-deletion-is-there-a-database-command/271554
**Category:** Support
**Created:** [July 13, 2023, 3:47pm UTC](https://meta.discourse.org/t/permanent-deletion-is-there-a-database-command/271554 "2023-07-13T15:47:21Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![OrkoGrayskull](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/orkograyskull/32/275883_2.png) [@OrkoGrayskull](https://meta.discourse.org/u/OrkoGrayskull)
#### Post date: [July 13, 2023, 3:47pm UTC](https://meta.discourse.org/t/permanent-deletion-is-there-a-database-command/271554/1 "2023-07-13T15:47:21Z")

</div>

With [this function](https://meta.discourse.org/t/introducing-permanently-delete-post-functionality/207109), postings/threads can be permanently removed from the database. Depending on the number of deleted postings/threads, however, this can be very time-consuming. Is there a command/script for the database or rails to automate the process?

---

<div class="post-metadata">

### Author: ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)
#### Post date: [July 13, 2023, 4:10pm UTC](https://meta.discourse.org/t/permanent-deletion-is-there-a-database-command/271554/2 "2023-07-13T16:10:15Z")

</div>

If your wish is to hard-delete all the soft-deleted posts, then you could loop through them with a rails script and use the destroy method.

That might give some info:

> [@How to delete thousands of Personal Messages?](https://meta.discourse.org/t/how-to-delete-thousands-of-private-messages/162747/7):
>
> Revisiting this old topic, since none of the answers are 100% correct. The rake task rake destroy:private\_messages does not hard delete all private messages, it soft deletes them. They can still be seen by an admin and they can be recovered. The Rails code Topic.where(archetype: 'private\_message').where("user\_id \> 0").destroy\_all destroys the topics, but not the actual messages. They are still in the database and can be viewed using for instance the [data explorer](https://meta.discourse.org/t/32566?silent=true) plugin. This code will perma…

---

<div class="post-metadata">

### Author: ![OrkoGrayskull](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/orkograyskull/32/275883_2.png) [@OrkoGrayskull](https://meta.discourse.org/u/OrkoGrayskull)
#### Post date: [July 14, 2023, 5:47am UTC](https://meta.discourse.org/t/permanent-deletion-is-there-a-database-command/271554/3 "2023-07-14T05:47:04Z")

</div>

I was hoping for a ready-made command that has already been tested. I would not like to start experimenting on a productive platform. 😉

---

<div class="post-metadata">

### Author: ![Stephen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/stephen/32/95011_2.png) [@Stephen](https://meta.discourse.org/u/Stephen)
#### Post date: [July 14, 2023, 10:52am UTC](https://meta.discourse.org/t/permanent-deletion-is-there-a-database-command/271554/4 "2023-07-14T10:52:38Z")

</div>

It’s always prudent to have a testing or staging site rather than experiment on production 😉

---

<div class="post-metadata">

### Author: ![Lhc\_fl](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lhc_fl/32/268115_2.png) [@Lhc\_fl](https://meta.discourse.org/u/Lhc_fl)
#### Post date: [July 15, 2023, 11:10am UTC](https://meta.discourse.org/t/permanent-deletion-is-there-a-database-command/271554/5 "2023-07-15T11:10:36Z")

</div>

Any irreversible operation involving batches is extremely dangerous. I highly recommend that you back it up first, and then write code in a test environment. 😉

I don’t think anyone should dare to guarantee that “my code will permanently delete thousands of posts at a time, and it will never go wrong!”
