# How to remove admin logs

**URL:** https://meta.discourse.org/t/how-to-remove-admin-logs/80185
**Category:** Support
**Created:** [February 9, 2018, 4:31pm UTC](https://meta.discourse.org/t/how-to-remove-admin-logs/80185 "2018-02-09T16:31:13Z")
**Posts on this page:** 16
**Page:** 1

<div class="post-metadata">

### Author: ![dangtrungluong](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dangtrungluong/32/120310_2.png) [@dangtrungluong](https://meta.discourse.org/u/dangtrungluong)
#### Post date: [February 9, 2018, 4:31pm UTC](https://meta.discourse.org/t/how-to-remove-admin-logs/80185/1 "2018-02-09T16:31:13Z")

</div>

I want to remove admin logs (admin/logs/staff\_action\_logs) or disable staff logs?  
How to?

---

<div class="post-metadata">

### Author: ![vinothkannans](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vinothkannans/32/86465_2.png) [@vinothkannans](https://meta.discourse.org/u/vinothkannans)
#### Post date: [February 9, 2018, 4:36pm UTC](https://meta.discourse.org/t/how-to-remove-admin-logs/80185/2 "2018-02-09T16:36:30Z")

</div>

> [@How to clean staff action logs?](https://meta.discourse.org/t/how-to-clean-staff-action-logs/51305):
>
> Hey! Is it possible to clean staff action logs? Immh, or is there any option like “delete staff actions whichs older than 30 days” ? love_letter

No. You can’t disable it.

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [February 9, 2018, 4:37pm UTC](https://meta.discourse.org/t/how-to-remove-admin-logs/80185/3 "2018-02-09T16:37:41Z")

</div>

Why would you want to do this?

---

<div class="post-metadata">

### Author: ![dangtrungluong](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dangtrungluong/32/120310_2.png) [@dangtrungluong](https://meta.discourse.org/u/dangtrungluong)
#### Post date: [February 9, 2018, 5:15pm UTC](https://meta.discourse.org/t/how-to-remove-admin-logs/80185/4 "2018-02-09T17:15:15Z")

</div>

I think database larger

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [February 9, 2018, 5:33pm UTC](https://meta.discourse.org/t/how-to-remove-admin-logs/80185/5 "2018-02-09T17:33:35Z")

</div>

Could you safely delete using postgres Sql?

---

<div class="post-metadata">

### Author: ![dangtrungluong](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dangtrungluong/32/120310_2.png) [@dangtrungluong](https://meta.discourse.org/u/dangtrungluong)
#### Post date: [February 9, 2018, 5:57pm UTC](https://meta.discourse.org/t/how-to-remove-admin-logs/80185/6 "2018-02-09T17:57:26Z")

</div>

thanks yoú

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [February 9, 2018, 6:01pm UTC](https://meta.discourse.org/t/how-to-remove-admin-logs/80185/7 "2018-02-09T18:01:39Z")

</div>

Take a back-up before you start firing off commands though!

---

<div class="post-metadata">

### Author: ![robbyoconnor](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/robbyoconnor/32/120330_2.png) [@robbyoconnor](https://meta.discourse.org/u/robbyoconnor)
#### Post date: [February 9, 2018, 6:14pm UTC](https://meta.discourse.org/t/how-to-remove-admin-logs/80185/8 "2018-02-09T18:14:01Z")

</div>

There are very few legitimate reasons to do this…what is the reason?

---

<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: [February 9, 2018, 6:19pm UTC](https://meta.discourse.org/t/how-to-remove-admin-logs/80185/9 "2018-02-09T18:19:27Z")

</div>

First, @dangtrungluong , congratulations on having a forum that’s so successful that you actually need to worry about the database size.

However, perhaps you should consider sharding / partitioning?  
Generating more granular backups?

Simply deleting data is usually a poor idea likely to lead to unforeseen problems. What exactly is the problem you’re having that you’re wanting to solve?

---

<div class="post-metadata">

### Author: ![dangtrungluong](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dangtrungluong/32/120310_2.png) [@dangtrungluong](https://meta.discourse.org/u/dangtrungluong)
#### Post date: [February 9, 2018, 6:33pm UTC](https://meta.discourse.org/t/how-to-remove-admin-logs/80185/10 "2018-02-09T18:33:56Z")

</div>

@Mittineague i’m newbie joining to “discourse”

---

<div class="post-metadata">

### Author: ![mikechristopher](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mikechristopher/32/89135_2.png) [@mikechristopher](https://meta.discourse.org/u/mikechristopher)
#### Post date: [February 9, 2018, 6:43pm UTC](https://meta.discourse.org/t/how-to-remove-admin-logs/80185/11 "2018-02-09T18:43:39Z")

</div>

If you are new to using discourse then I do not see what the issue is at the moment and why you feel it will make a massive impact on your database. We have logs going back to 2014 with no impact and I do not believe it takes up a massive amount of space.

---

<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: [February 9, 2018, 7:58pm UTC](https://meta.discourse.org/t/how-to-remove-admin-logs/80185/12 "2018-02-09T19:58:34Z")

</div>

It’s not a bad thing to think about things before they become a problem. If anything, I don’t think the database will be a problem as much as heavy weight media files could be. i.e. should you set up a CDN so the requests are served from closest to a visitors location? Do members reallly need to fill up a topic with mega weight files that could slow down page load and consume bandwidth?

---

<div class="post-metadata">

### Author: ![dangtrungluong](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dangtrungluong/32/120310_2.png) [@dangtrungluong](https://meta.discourse.org/u/dangtrungluong)
#### Post date: [February 12, 2018, 10:14am UTC](https://meta.discourse.org/t/how-to-remove-admin-logs/80185/13 "2018-02-12T10:14:17Z")

</div>

hi. thank for all  
🙂

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [May 19, 2020, 4:46am UTC](https://meta.discourse.org/t/how-to-remove-admin-logs/80185/14 "2020-05-19T04:46:48Z")

</div>



---

<div class="post-metadata">

### Author: ![yoda\_mtfbwu](https://avatars.discourse-cdn.com/v4/letter/y/46a35a/32.png) [@yoda\_mtfbwu](https://meta.discourse.org/u/yoda_mtfbwu)
#### Post date: [November 14, 2023, 6:36pm UTC](https://meta.discourse.org/t/how-to-remove-admin-logs/80185/15 "2023-11-14T18:36:42Z")

</div>

You could do it using the rails console but it’s also dangerous. So if I’m correct it would like

> cd /var/discourse  
> sudo ./launcher enter app  
> rails c

Now you’re in the console, one option to delete the entire staff action / admin logs is to use this:

> [@How to clean staff action logs?](https://meta.discourse.org/t/how-to-clean-staff-action-logs/51305/7):
>
> OK. This is solved via UserHistory.destroy\_all.

However this removes everything which may not be what you wanted. You may want to limit the time period or investigate certain actions.

For example:  
`UserHistory.where(action: 17, acting_user_id: 5)`

This would return all posts deleted by the user who’s id is 5

or

`UserHistory.where(action: 17, post_id: 15643)`

This would return information about who deleted the post with id 15643

For a list of table fields and actions id’s see [this file](https://github.com/discourse/discourse/blob/main/app/models/user_history.rb):

```plaintext
# == Schema Information
#
# Table name: user_histories
#
# id :integer not null, primary key
# action :integer not null
# acting_user_id :integer
# target_user_id :integer
# details :text
# created_at :datetime not null
# updated_at :datetime not null
# context :string
# ip_address :string
# email :string
# subject :text
# previous_value :text
# new_value :text
# topic_id :integer
# admin_only :boolean default(FALSE)
# post_id :integer
# custom_type :string
# category_id :integer
#
# Indexes
#
# index_user_histories_on_acting_user_id_and_action_and_id (acting_user_id,action,id)
# index_user_histories_on_action_and_id (action,id)
# index_user_histories_on_category_id (category_id)
# index_user_histories_on_subject_and_id (subject,id)
# index_user_histories_on_target_user_id_and_id (target_user_id,id)
# index_user_histories_on_topic_id_and_target_user_id_and_action (topic_id,target_user_id,action)
#

```

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [November 15, 2023, 7:34am UTC](https://meta.discourse.org/t/how-to-remove-admin-logs/80185/16 "2023-11-15T07:34:39Z")

</div>


