# Delete all posts and topics

**URL:** https://meta.discourse.org/t/delete-all-posts-and-topics/38187
**Category:** Support
**Created:** [January 19, 2016, 4:04pm UTC](https://meta.discourse.org/t/delete-all-posts-and-topics/38187 "2016-01-19T16:04:30Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![Aryeh\_Armon](https://avatars.discourse-cdn.com/v4/letter/a/f05b48/32.png) [@Aryeh\_Armon](https://meta.discourse.org/u/Aryeh_Armon)
#### Post date: [January 19, 2016, 4:04pm UTC](https://meta.discourse.org/t/delete-all-posts-and-topics/38187/1 "2016-01-19T16:04:30Z")

</div>

I have imported about 500,000 posts to my discourse instance.  
i would like to delete all posts and topics to re-import all my posts.

does anyone have any idea how to do this?

---

<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 19, 2016, 4:09pm UTC](https://meta.discourse.org/t/delete-all-posts-and-topics/38187/2 "2016-01-19T16:09:54Z")

</div>

If you want to start from scratch, I would use the rails console to re-create a new database

```shell
rails db:drop db:create db:migrate

```

⚠ **THIS WILL DELETE EVERYTHING (users, site settings, etc..)**⚠

---

<div class="post-metadata">

### Author: ![Aryeh\_Armon](https://avatars.discourse-cdn.com/v4/letter/a/f05b48/32.png) [@Aryeh\_Armon](https://meta.discourse.org/u/Aryeh_Armon)
#### Post date: [January 19, 2016, 4:13pm UTC](https://meta.discourse.org/t/delete-all-posts-and-topics/38187/3 "2016-01-19T16:13:31Z")

</div>

the thing is i want to keep all the other settings i have.

---

<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 19, 2016, 4:16pm UTC](https://meta.discourse.org/t/delete-all-posts-and-topics/38187/4 "2016-01-19T16:16:07Z")

</div>

What other settings?

---

<div class="post-metadata">

### Author: ![Aryeh\_Armon](https://avatars.discourse-cdn.com/v4/letter/a/f05b48/32.png) [@Aryeh\_Armon](https://meta.discourse.org/u/Aryeh_Armon)
#### Post date: [January 19, 2016, 4:28pm UTC](https://meta.discourse.org/t/delete-all-posts-and-topics/38187/5 "2016-01-19T16:28:42Z")

</div>

design, site name… and other settings my client may have changed.  
i don’t see why i would have to reset everything.  
there gotta be another way.

---

<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 19, 2016, 4:37pm UTC](https://meta.discourse.org/t/delete-all-posts-and-topics/38187/6 "2016-01-19T16:37:43Z")

</div>

In that case, you could do this in the rails console

```rails
Post.order(id: :desc).each do |post| 
   PostDestroyer.new(Discourse.system_user, post).destroy
end

```

---

<div class="post-metadata">

### Author: ![Aryeh\_Armon](https://avatars.discourse-cdn.com/v4/letter/a/f05b48/32.png) [@Aryeh\_Armon](https://meta.discourse.org/u/Aryeh_Armon)
#### Post date: [January 19, 2016, 6:05pm UTC](https://meta.discourse.org/t/delete-all-posts-and-topics/38187/7 "2016-01-19T18:05:00Z")

</div>

this is working wayy to slow. it deleted about 10000 posts in about 1 hour.  
is there anyway to do this faster?

---

<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 19, 2016, 6:06pm UTC](https://meta.discourse.org/t/delete-all-posts-and-topics/38187/8 "2016-01-19T18:06:06Z")

</div>

Only the first method I mentioned will. If you use anything else, you will end up with an inconsistent database.

---

<div class="post-metadata">

### Author: ![Aryeh\_Armon](https://avatars.discourse-cdn.com/v4/letter/a/f05b48/32.png) [@Aryeh\_Armon](https://meta.discourse.org/u/Aryeh_Armon)
#### Post date: [January 19, 2016, 6:12pm UTC](https://meta.discourse.org/t/delete-all-posts-and-topics/38187/9 "2016-01-19T18:12:44Z")

</div>

is there a way to backup only the settings?

---

<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 19, 2016, 6:16pm UTC](https://meta.discourse.org/t/delete-all-posts-and-topics/38187/10 "2016-01-19T18:16:30Z")

</div>

I’m afraid not yet. But you can do it manually. All the settings (ie. `/admin/site_settings`) are stored in the `site_settings` table. Just dump that table and restore it once you’ve re-created the database.

---

<div class="post-metadata">

### Author: ![Aryeh\_Armon](https://avatars.discourse-cdn.com/v4/letter/a/f05b48/32.png) [@Aryeh\_Armon](https://meta.discourse.org/u/Aryeh_Armon)
#### Post date: [January 19, 2016, 6:20pm UTC](https://meta.discourse.org/t/delete-all-posts-and-topics/38187/11 "2016-01-19T18:20:43Z")

</div>

i do not come from the rails world,  
is it to much to ask how i can do that?

---

<div class="post-metadata">

### Author: ![Aryeh\_Armon](https://avatars.discourse-cdn.com/v4/letter/a/f05b48/32.png) [@Aryeh\_Armon](https://meta.discourse.org/u/Aryeh_Armon)
#### Post date: [January 19, 2016, 6:21pm UTC](https://meta.discourse.org/t/delete-all-posts-and-topics/38187/12 "2016-01-19T18:21:24Z")

</div>

something like this ?  
`rake db:site_settings:dump`

---

<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 19, 2016, 6:23pm UTC](https://meta.discourse.org/t/delete-all-posts-and-topics/38187/13 "2016-01-19T18:23:04Z")

</div>

It’s actually a postgresql thing 😉 Here’s how to dump the `site_settings` table

```shell
pg_dump -a -t site_settings -f site_settings.sql discourse_development

```

---

<div class="post-metadata">

### Author: ![Aryeh\_Armon](https://avatars.discourse-cdn.com/v4/letter/a/f05b48/32.png) [@Aryeh\_Armon](https://meta.discourse.org/u/Aryeh_Armon)
#### Post date: [January 19, 2016, 6:24pm UTC](https://meta.discourse.org/t/delete-all-posts-and-topics/38187/14 "2016-01-19T18:24:22Z")

</div>

/usr/lib/postgresql/9.3/bin/pg\_dump: invalid option – ‘D’  
Try “pg\_dump --help” for more information.

---

<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 19, 2016, 6:25pm UTC](https://meta.discourse.org/t/delete-all-posts-and-topics/38187/15 "2016-01-19T18:25:46Z")

</div>

You can remove that `-D` parameter. Sorry.

---

<div class="post-metadata">

### Author: ![Aryeh\_Armon](https://avatars.discourse-cdn.com/v4/letter/a/f05b48/32.png) [@Aryeh\_Armon](https://meta.discourse.org/u/Aryeh_Armon)
#### Post date: [January 19, 2016, 6:27pm UTC](https://meta.discourse.org/t/delete-all-posts-and-topics/38187/16 "2016-01-19T18:27:27Z")

</div>

just remembered i have 200,000 users i would like to keep as well 🙂 anyway to easily export those?

---

<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 19, 2016, 6:28pm UTC](https://meta.discourse.org/t/delete-all-posts-and-topics/38187/17 "2016-01-19T18:28:21Z")

</div>

I’m afraid there is none…

---

<div class="post-metadata">

### Author: ![Aryeh\_Armon](https://avatars.discourse-cdn.com/v4/letter/a/f05b48/32.png) [@Aryeh\_Armon](https://meta.discourse.org/u/Aryeh_Armon)
#### Post date: [January 19, 2016, 6:30pm UTC](https://meta.discourse.org/t/delete-all-posts-and-topics/38187/18 "2016-01-19T18:30:20Z")

</div>

OK, thank you so much. you helped me a lot.

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [December 9, 2018, 9:52pm UTC](https://meta.discourse.org/t/delete-all-posts-and-topics/38187/19 "2018-12-09T21:52:02Z")

</div>



---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [December 9, 2018, 10:06pm UTC](https://meta.discourse.org/t/delete-all-posts-and-topics/38187/20 "2018-12-09T22:06:55Z")

</div>

> [@Aryeh\_Armon](#):
>
> the thing is i want to keep all the other settings i have.

There is now a rake task for this:

> [@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. …

[Next page](https://meta.discourse.org/t/delete-all-posts-and-topics/38187.md?page=2)
