Help Wiping all Posts from a Forum

(R. Shaun Brodie) #1

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!

(Jeff Atwood) #2

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

(R. Shaun Brodie) #3

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.

(Jeff Atwood) #4

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?

(R. Shaun Brodie) #5

Thanks Jeff! We’ll figure out something.

(Panos Petropoulos) #6


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

Thank you in advance.

(Régis Hanol) #7

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

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

:warning: be sure to make a backup before running this destructive code.

(Panos Petropoulos) #8

Thanks a lot @zogstrip for the quick answer!

Can you suggest a quick/safe backup method?

(Régis Hanol) #9

Use the backup feature in Discourse :wink:

(Panos Petropoulos) #10

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

Thanks anyway! :wink:

(Stephen Chung) #11

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.

(Régis Hanol) #12

It only marks them as deleted in the database.

(Stephen Chung) #13

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…

(Geoff Forster) #14

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

(Arpit Jalan) #15

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

(Yaw Anokwa) #16

How do these destroyed posts manifest in the UI?