How can I delete or undelete topics?

There is no documentation for this unfortunately, as it is quite an advanced repair technique. I’m not sure how you’ve installed discourse but if you access the database you’ll want to issue a DELETE FROM topic_embeds - of course be warned that will remove all existing links between posts and embeddings. So if you have any in a good state they will be removed too.


I have three posts that were somehow undeleted, while all the rest are deleted (and refuse to be undeleted). I’m perfectly happy to deleted the three and unlinking them.

This would allow me to link me to create new topics based on the same blog posts, right?

If so, I’d like to try this.

My Discourse uses the vanilla Docker install in a Digital Ocean droplet. I have a local Vagrant version, which I’ve used to run experiments. For obvious reasons, I would liked to try this in the Vagrant version before doing it in production :slight_smile:

I need a bit more help though. If I ssh into vagrant and open the console with rails c. What then?

That’s a c for Console
It will let you run Ruby from the command line.

Similarly you can rails db and run DataBase queries from the command line.

*Hint, please do yourself a favor and save backups or be prepared and willing to start from scratch if things turn sour.


In other words: Footgun, batteries not included


I’ll be working in my local Vagrant instance using a backup from the production docker. Starting from scratch is not an option at this point. We have migrated our Ning forum to Discourse and it’s now live and being used. There was, unfortunately, no indication in the embedding documentation available about any of these issues.

I’m still not sure what I’m doing. I tried this:

[vagrant@precise32:/vagrant (master)]$ rails db
psql (9.4.1)
Type "help" for help.

discourse_development=> DELETE FROM topic_embeds
discourse_development-> \q

But it doesn’t seem to be working. Or I don’t understand how to test this.

I visited the local version of the website but the “Continue the Discussion” link there tries to take me to old (deleted) topic at http://localhost:4000/t/profiles-events/18.

FWIW, I have as an allowed host.


I think you need to end your statement with ;, otherwise it thinks you are trying to write a multi-line query.


DELETE FROM topic_embeds;

Just landed here after I deleted a topic I’d created under Discourse 2 and low and behold this sage advice still works to restore deleted topics. That’s awesome! :smile:

1 Like

How can we restore topic discourse?
I deleted content of first topic, so it’s lost, now i wanna restore them. How do i?
Do Discourse have recycle bin topic?
Thank you!

Search, find the deleted topic and click the Un-delete button



Thanks-you very much! Works perfectly :kissing_heart:


How can i search or list all topic Make unlisted?

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.