# How to mass remove PMs?

**URL:** https://meta.discourse.org/t/how-to-mass-remove-pms/303158
**Category:** Support
**Tags:** automation, sql-query
**Created:** [April 10, 2024, 12:08am UTC](https://meta.discourse.org/t/how-to-mass-remove-pms/303158 "2024-04-10T00:08:24Z")
**Posts on this page:** 1
**Showing post:** 11

<div class="post-metadata">

### Author: ![satonotdead](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/satonotdead/32/447830_2.png) [@satonotdead](https://meta.discourse.org/u/satonotdead)
#### Post date: [April 27, 2025, 2:38am UTC](https://meta.discourse.org/t/how-to-mass-remove-pms/303158/11 "2025-04-27T02:38:11Z")

</div>

Is that OK for you folks? Could it be improved?

```plaintext
 Topic.where("archetype = 'private_message' AND title ILIKE ?", "%something%").find_each do |t|
   PostDestroyer.new(Discourse.system_user, t.ordered_posts.first).destroy
   puts "Destroyed PM: #{t.id} - #{t.title}"
 end

```

---

_[View the full topic](https://meta.discourse.org/t/how-to-mass-remove-pms/303158)._
