# Help Wiping all Posts from a Forum

**URL:** https://meta.discourse.org/t/help-wiping-all-posts-from-a-forum/46367
**Category:** Support
**Created:** [June 23, 2016, 6:56pm UTC](https://meta.discourse.org/t/help-wiping-all-posts-from-a-forum/46367 "2016-06-23T18:56:59Z")
**Posts on this page:** 19
**Page:** 1

<div class="post-metadata">

### Author: ![SBrodie](https://avatars.discourse-cdn.com/v4/letter/s/bbce88/32.png) [@SBrodie](https://meta.discourse.org/u/SBrodie)
#### Post date: [June 23, 2016, 6:56pm UTC](https://meta.discourse.org/t/help-wiping-all-posts-from-a-forum/46367/1 "2016-06-23T18:56:59Z")

</div>

Hi folks,

One of the Discourse sites that I operate is preparing to undergo a re-launch, and due to the large amount of inactivity on the forum, and the type of posts that have been made in the last year or so, I’d like to remove/delete all topics and start over fresh on the forums.

Is there an easy way to do this?

Thanks in advance!

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [June 23, 2016, 7:06pm UTC](https://meta.discourse.org/t/help-wiping-all-posts-from-a-forum/46367/2 "2016-06-23T19:06:25Z")

</div>

Do you want to delete _everything_ and start from scratch, or just the topics, categories, users?

---

<div class="post-metadata">

### Author: ![SBrodie](https://avatars.discourse-cdn.com/v4/letter/s/bbce88/32.png) [@SBrodie](https://meta.discourse.org/u/SBrodie)
#### Post date: [June 23, 2016, 7:09pm UTC](https://meta.discourse.org/t/help-wiping-all-posts-from-a-forum/46367/3 "2016-06-23T19:09:22Z")

</div>

Hi Jeff,

We really just want to delete the topics and categories. We’d like to keep users and all of the css work that has been done on the instance.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [June 23, 2016, 7:21pm UTC](https://meta.discourse.org/t/help-wiping-all-posts-from-a-forum/46367/4 "2016-06-23T19:21:30Z")

</div>

I don’t know that we have a simple way to do that at the moment, but it does come up a fair bit.

Can we create a rake task that would remove all categories and topics @techapj? Perhaps add this to your list as low priority?

---

<div class="post-metadata">

### Author: ![SBrodie](https://avatars.discourse-cdn.com/v4/letter/s/bbce88/32.png) [@SBrodie](https://meta.discourse.org/u/SBrodie)
#### Post date: [June 24, 2016, 12:56am UTC](https://meta.discourse.org/t/help-wiping-all-posts-from-a-forum/46367/5 "2016-06-24T00:56:41Z")

</div>

Thanks Jeff! We’ll figure out something.

---

<div class="post-metadata">

### Author: ![panospet](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/panospet/32/120406_2.png) [@panospet](https://meta.discourse.org/u/panospet)
#### Post date: [January 7, 2018, 12:46pm UTC](https://meta.discourse.org/t/help-wiping-all-posts-from-a-forum/46367/6 "2018-01-07T12:46:06Z")

</div>

Hello,

Are there any updates considering an easy way of wiping out every thread-post-category in a discourse forum?

Thank you in advance.

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [January 7, 2018, 12:58pm UTC](https://meta.discourse.org/t/help-wiping-all-posts-from-a-forum/46367/7 "2018-01-07T12:58:46Z")

</div>

The easiest way is to use rails command line, ssh into your server and then

```plaintext
cd /var/discourse
./launcher enter app
rails c
Post.where("user_id > 0").where(post_number: 1).find_each do |post| 
  PostDestroyer.new(Discourse.system_user, post).destroy
  putc "."
end

```

**⚠ be sure to make a backup before running this destructive code.**

---

<div class="post-metadata">

### Author: ![panospet](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/panospet/32/120406_2.png) [@panospet](https://meta.discourse.org/u/panospet)
#### Post date: [January 7, 2018, 1:07pm UTC](https://meta.discourse.org/t/help-wiping-all-posts-from-a-forum/46367/8 "2018-01-07T13:07:01Z")

</div>

Thanks a lot @zogstrip for the quick answer!

Can you suggest a quick/safe backup method?

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [January 7, 2018, 1:08pm UTC](https://meta.discourse.org/t/help-wiping-all-posts-from-a-forum/46367/9 "2018-01-07T13:08:08Z")

</div>

Use the backup feature in Discourse 😉

---

<div class="post-metadata">

### Author: ![panospet](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/panospet/32/120406_2.png) [@panospet](https://meta.discourse.org/u/panospet)
#### Post date: [January 7, 2018, 1:08pm UTC](https://meta.discourse.org/t/help-wiping-all-posts-from-a-forum/46367/10 "2018-01-07T13:08:52Z")

</div>

Oh, my bad. Had to check first before asking.

Thanks anyway! 😉

---

<div class="post-metadata">

### Author: ![schungx](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/schungx/32/70989_2.png) [@schungx](https://meta.discourse.org/u/schungx)
#### Post date: [January 8, 2018, 11:05am UTC](https://meta.discourse.org/t/help-wiping-all-posts-from-a-forum/46367/11 "2018-01-08T11:05:18Z")

</div>

Does running `PostDestroyer.destroy` actually remove the record from the database or does it merely mark the post as deleted, keeping it in the database?

There will be a lot of uses for a script that actually DELETES all the topics and posts, leaving everything (like site settings and users) there. Categories are yes/no.

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [January 8, 2018, 11:07am UTC](https://meta.discourse.org/t/help-wiping-all-posts-from-a-forum/46367/12 "2018-01-08T11:07:01Z")

</div>

It only marks them as deleted in the database.

---

<div class="post-metadata">

### Author: ![schungx](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/schungx/32/70989_2.png) [@schungx](https://meta.discourse.org/u/schungx)
#### Post date: [January 8, 2018, 11:07am UTC](https://meta.discourse.org/t/help-wiping-all-posts-from-a-forum/46367/13 "2018-01-08T11:07:45Z")

</div>

That’s what I’m afraid of.

There must be some internal Discourse database guru who can whip up a bunch of SQL statements to just wipe the necessary tables clean…

---

<div class="post-metadata">

### Author: ![geoff777](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/geoff777/32/202388_2.png) [@geoff777](https://meta.discourse.org/u/geoff777)
#### Post date: [January 8, 2018, 1:19pm UTC](https://meta.discourse.org/t/help-wiping-all-posts-from-a-forum/46367/14 "2018-01-08T13:19:43Z")

</div>

What about being able to back up just users, and/or site settings, categories etc.  
Then uploading to a fresh install?

---

<div class="post-metadata">

### Author: ![techAPJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/techapj/32/342990_2.png) [@techAPJ](https://meta.discourse.org/u/techAPJ)
#### Post date: [April 23, 2018, 11:44am UTC](https://meta.discourse.org/t/help-wiping-all-posts-from-a-forum/46367/15 "2018-04-23T11:44:41Z")

</div>

Thanks to @blake we now have rake tasks for cleanup of various sorts .

> <https://github.com/discourse/discourse/blob/main/lib/tasks/destroy.rake>

---

<div class="post-metadata">

### Author: ![yanokwa](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/yanokwa/32/105083_2.png) [@yanokwa](https://meta.discourse.org/u/yanokwa)
#### Post date: [April 26, 2018, 5:01pm UTC](https://meta.discourse.org/t/help-wiping-all-posts-from-a-forum/46367/16 "2018-04-26T17:01:05Z")

</div>

How do these destroyed posts manifest in the UI?

---

<div class="post-metadata">

### Author: ![Cozdabuch](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cozdabuch/32/139120_2.png) [@Cozdabuch](https://meta.discourse.org/u/Cozdabuch)
#### Post date: [March 10, 2019, 4:53am UTC](https://meta.discourse.org/t/help-wiping-all-posts-from-a-forum/46367/17 "2019-03-10T04:53:55Z")

</div>

What I’m looking to do:

Keep all site structure, (categories, groups, users, and settings), but wipe all threads, and PMS, and logs, basically to take a demo site that served as a sandbox, and transition it to a live site, similar to the OP, without having to setup a new instance and re-register all my users. But everything content wise, as well as logged actions all starts fresh.

Does this rake task posted above do this, or can the added reset logs as well be done, so all post data, and all log data is wiped fresh?

---

<div class="post-metadata">

### Author: ![markcarey](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/markcarey/32/189049_2.png) [@markcarey](https://meta.discourse.org/u/markcarey)
#### Post date: [August 26, 2020, 6:04pm UTC](https://meta.discourse.org/t/help-wiping-all-posts-from-a-forum/46367/18 "2020-08-26T18:04:29Z")

</div>

This is really useful, many thanks. It seems that this doesn’t remove any Custom Fields for the posts. In my case, I am trying to import posts, so the “import\_id” custom fields remain, making the importer think the posts are still present, even though they are not. Any way to remove the custom field data as well? 😉

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [August 26, 2020, 7:58pm UTC](https://meta.discourse.org/t/help-wiping-all-posts-from-a-forum/46367/19 "2020-08-26T19:58:24Z")

</div>

> [@markcarey](#):
>
> Any way to remove the custom field data as well?

Sure, add these lines before the `PostDestroyer.new` line

```ruby
post.custom_fields = nil
post.save_custom_fields

```
