Delete all posts and topicts


(Aryeh Armon) #1

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?


(Régis Hanol) #2

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:


(Aryeh Armon) #3

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


(Régis Hanol) #4

What other settings?


(Aryeh Armon) #5

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.


(Régis Hanol) #6

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

(Aryeh Armon) #7

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


(Régis Hanol) #8

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


(Aryeh Armon) #9

is there a way to backup only the settings?


(Régis Hanol) #10

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.


(Aryeh Armon) #11

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


(Aryeh Armon) #12

something like this ?
rake db:site_settings:dump


(Régis Hanol) #13

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

(Aryeh Armon) #14

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


(Régis Hanol) #15

You can remove that -D parameter. Sorry.


(Aryeh Armon) #16

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


(Régis Hanol) #17

I’m afraid there is none…


(Aryeh Armon) #18

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