Delete all posts and topics

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?

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

rails db:drop db:create db:migrate

:warning: THIS WILL DELETE EVERYTHING (users, site settings, etc
) :warning:

3 Likes

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

What other settings?

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.

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

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

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

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

is there a way to backup only the settings?

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.

1 Like

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

something like this ?
rake db:site_settings:dump

It’s actually a postgresql thing :wink: Here’s how to dump the site_settings table

pg_dump -a -t site_settings -f site_settings.sql discourse_development
1 Like

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

You can remove that -D parameter. Sorry.

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

I’m afraid there is none


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

1 Like

There is now a rake task for this:

4 Likes