# Is it possible to delete posts from the database?

**URL:** https://meta.discourse.org/t/is-it-possible-to-delete-posts-from-the-database/139792
**Category:** Development
**Created:** [January 26, 2020, 8:53pm UTC](https://meta.discourse.org/t/is-it-possible-to-delete-posts-from-the-database/139792 "2020-01-26T20:53:27Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Arimov](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/arimov/32/167747_2.png) [@Arimov](https://meta.discourse.org/u/Arimov)
#### Post date: [January 26, 2020, 8:53pm UTC](https://meta.discourse.org/t/is-it-possible-to-delete-posts-from-the-database/139792/1 "2020-01-26T20:53:27Z")

</div>

I apologize in advance if the question is too dummies.  
I have access to the Discourse database (through the plugin).  
Can I delete some of the posts (which I myself created in large quantities during testing) using the query?

```
delete from posts where id in (123, 567, ... etc)

```

Is it safe to perform such operations?

---

<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: [January 27, 2020, 7:08pm UTC](https://meta.discourse.org/t/is-it-possible-to-delete-posts-from-the-database/139792/2 "2020-01-27T19:08:39Z")

</div>

> [@Arimov](#):
>
> I have access to the Discourse database (through the plugin).

If you are accessing the database through the [Data Explorer](https://meta.discourse.org/t/32566?silent=true) plugin, that plugin only allows read-only queries. It is not possible to use it to write to the database.

It is possible to fully delete posts from the Rails console, but we don’t recommend doing that. Your best approach would be to use the [Data Explorer](https://meta.discourse.org/t/32566?silent=true) plugin to find the posts you want to delete, and then use the tools availale on the Discourse user interface to remove the posts.

If for some reason this approach won’t work for you, let us know and we can give you details about deleting posts from the Rails console.

---

<div class="post-metadata">

### Author: ![Nikolay](https://avatars.discourse-cdn.com/v4/letter/n/a698b9/32.png) [@Nikolay](https://meta.discourse.org/u/Nikolay)
#### Post date: [January 28, 2020, 4:18pm UTC](https://meta.discourse.org/t/is-it-possible-to-delete-posts-from-the-database/139792/3 "2020-01-28T16:18:02Z")

</div>

I am not expert in this engine, but i suppose that it is not safe, because like that you will only delete entry from posts table, and one post can have linked entries in other tables, and alot of meta information, linked to that post\_id. And later on something might break. So you should use integrated tools for post deletion.

---

<div class="post-metadata">

### Author: ![Arimov](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/arimov/32/167747_2.png) [@Arimov](https://meta.discourse.org/u/Arimov)
#### Post date: [January 28, 2020, 6:49pm UTC](https://meta.discourse.org/t/is-it-possible-to-delete-posts-from-the-database/139792/4 "2020-01-28T18:49:05Z")

</div>

Thanks Nikolay.  
I also think .. But suddenly real experts on this application will come, and they will say - feel free to delete! )))

---

<div class="post-metadata">

### Author: ![Remah](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/remah/32/70590_2.png) [@Remah](https://meta.discourse.org/u/Remah)
#### Post date: [January 28, 2020, 7:25pm UTC](https://meta.discourse.org/t/is-it-possible-to-delete-posts-from-the-database/139792/5 "2020-01-28T19:25:59Z")

</div>

Except that no experts say it is OK:

- It is not recommended.
- It is not on the Discourse roadmap and there are no plans to add it.
- It is not being developed because a permanent delete cannot be undone.
- Nobody has paid to have this feature developed.

Nobody who has asked for it has developed this feature because it is either too difficult or is not worth the cost of developing it.

See this topic for examples of these points:

> [@How to remove post completely?](https://meta.discourse.org/t/how-to-remove-post-completely/50514):
>
> Hey there! I want to remove a post completely. For example can I delete post shown below? I don’t want to see this deleted post shown in red, even if they’re only visible to staff. (If you wondered why I want to remove it, because I have obsession.) I think discourse is a very pleasant forum software. But sometimes it makes me laugh. I can do a lot of thing as an admin, but I can’t delete post completely… What a contradiction! blush

---

<div class="post-metadata">

### Author: ![Mittineague](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mittineague/32/114259_2.png) [@Mittineague](https://meta.discourse.org/u/Mittineague)
#### Post date: [January 28, 2020, 8:06pm UTC](https://meta.discourse.org/t/is-it-possible-to-delete-posts-from-the-database/139792/6 "2020-01-28T20:06:44Z")

</div>

I would not call myself an expert, but I have looked at, analyzed, and played with files and code a fair bit over the years.

I have seen enough to convince myself that on my own I am not knowledgeable enough to do more than experiment in localhost. What I have seen, and not seen, cause pause.

I have _not_ ever seen a single “`ON DELETE CASCADE`”. I _have_ seen a lot of “`has_many`”, “`dependent:`”, “Indexes” and “`ensure_consistency`” in a lot of model files. There is a job file [discourse/app/jobs/scheduled/ensure\_db\_consistency.rb at main · discourse/discourse · GitHub](https://github.com/discourse/discourse/blob/master/app/jobs/scheduled/ensure_db_consistency.rb)

Personally, as much as I like Discourse, I would not expect them to deal with the consequences of actions that go outside of core safeguards. i.e. I often break my own code, but I take full responsibility when it happens. But that’s me. And there certainly can be some core code somewhere I’m not yet aware of.

---

<div class="post-metadata">

### Author: ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)
#### Post date: [January 28, 2020, 8:47pm UTC](https://meta.discourse.org/t/is-it-possible-to-delete-posts-from-the-database/139792/7 "2020-01-28T20:47:59Z")

</div>

Also,

> [@If I want to completely delete a post, I should just hide them?](https://meta.discourse.org/t/if-i-want-to-completely-delete-a-post-i-should-just-hide-them/56720/13):
>
> Hard deleting a post using .destroy is the recommended way. I will not break stuff in Discourse, there are jobs that ensure consistency. There may be some inconsistency in counts for 1 to 7 days depending. (Sam made 9997 posts but REALLY he only made 9996 posts)

But that would be pointless in op’s case.
