# Mautic DB Hygiene

**URL:** <https://forum.mautic.org/t/mautic-db-hygiene/23027>\
**Category:** General Discussion\
**Created:** [March 13, 2022, 9:59am UTC](https://forum.mautic.org/t/mautic-db-hygiene/23027 "2022-03-13T09:59:12Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![mikew](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/mikew/32/5156_2.png) [@mikew](https://forum.mautic.org/u/mikew)\
**Post date:** [March 13, 2022, 9:59am UTC](https://forum.mautic.org/t/mautic-db-hygiene/23027/1 "2022-03-13T09:59:12Z")

</div>

Hi,

I am sure for many of us that have been running Mautic for a few years are starting to see that the database grows exponentially and some of the candidates for this are the  
audit\_logs  
email\_stats  
campaign\_lead\_event\_log  
lead\_event\_log  
page\_hits

There is already a console command that will clean up the audit\_logs on a specific date range, what can we do in the most affective way to do the same for rest ?

I have already researched this issue and it is something that repeats itself however there is no definite elegant way to take care of this. (example: [email\_stats table bloat · Issue #7763 · mautic/mautic · GitHub](https://github.com/mautic/mautic/issues/7763))

No one wants to loose historic data however there is a price to keeping it, speed, space, memory.  
Maybe there is a way to export these big tables into a separate database so that this is still accessible, maybe not ?

And when trying to follow some of the suggestions on the net it can be quite dangerous as you do not really know what will break along the way…

So this is an open discussion for those of us that have similar problems to try and find a solution that is long lasting, safe and doable for non-technical people

---

<div class="post-metadata">

**Author:** ![pierre\_a](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/pierre_a/32/7031_2.png) [@pierre\_a](https://forum.mautic.org/u/pierre_a)\
**Post date:** [March 14, 2022, 6:43am UTC](https://forum.mautic.org/t/mautic-db-hygiene/23027/2 "2022-03-14T06:43:23Z")

</div>

Hello @mikew,

What is your version of Mautic?

Pierre

---

<div class="post-metadata">

**Author:** ![mikew](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/mikew/32/5156_2.png) [@mikew](https://forum.mautic.org/u/mikew)\
**Post date:** [March 14, 2022, 7:34am UTC](https://forum.mautic.org/t/mautic-db-hygiene/23027/3 "2022-03-14T07:34:06Z")

</div>

Most of my servers are on Digital ocean, running ubuntu, nginx and mariabd

---

<div class="post-metadata">

**Author:** ![jester](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/jester/32/7067_2.png) [@jester](https://forum.mautic.org/u/jester)\
**Post date:** [March 14, 2022, 8:26am UTC](https://forum.mautic.org/t/mautic-db-hygiene/23027/4 "2022-03-14T08:26:33Z")

</div>

Hi @mikew,

I’m the one who posted the “solution” in github thread you’ve mentioned. Using mautics up to latest version and can confirm the issue is still there.

The DB cleanup procedure is proven to be safe for years already, although you need to make sure you dont need the data cleaned.

There is no other way to deal with it to my knowledge. Would be happy to deal with it other than deleting data.

---

<div class="post-metadata">

**Author:** ![mikew](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/mikew/32/5156_2.png) [@mikew](https://forum.mautic.org/u/mikew)\
**Post date:** [March 14, 2022, 10:02am UTC](https://forum.mautic.org/t/mautic-db-hygiene/23027/5 "2022-03-14T10:02:18Z")

</div>

Hi @jester . Thanks for the solution on GitHub and replying here as well.

I am hoping this post catches the attention of enough people that we can look at putting some kind of console command in the take care of this without people having to go into the mysql themselves. I am pretty comfortable doing this, however I am sure that many others are not.

---

<div class="post-metadata">

**Author:** ![jester](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/jester/32/7067_2.png) [@jester](https://forum.mautic.org/u/jester)\
**Post date:** [March 15, 2022, 7:45am UTC](https://forum.mautic.org/t/mautic-db-hygiene/23027/6 "2022-03-15T07:45:02Z")

</div>

Hi @mikew , hope so too although after many years of dealing with it without any response from mautic team I doubt this may be the case.

To fix it permanently they have to change how data is stored in database. This will require substantial efforts from programming and database management side, hence chances team will look into it are quite small.

It is not critical on small to mid size instances. I have few instances scheduling around 4m emails on daily basis and my db size is over 3Tb by now. Without procedures in place I’m terrified to predict the DB size.

---

<div class="post-metadata">

**Author:** ![jvilarnau](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/jvilarnau/32/636_2.png) [@jvilarnau](https://forum.mautic.org/u/jvilarnau)\
**Post date:** [March 17, 2022, 11:15am UTC](https://forum.mautic.org/t/mautic-db-hygiene/23027/7 "2022-03-17T11:15:57Z")

</div>

I would be a good feature to be able to delete old emails, so that Mautic would remove this data from database. In my case, the biggest table is “email\_stats” (not “audit\_log”). You can remove leads and emails, but data from this table is never deleted.

---

<div class="post-metadata">

**Author:** ![pierre\_a](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/pierre_a/32/7031_2.png) [@pierre\_a](https://forum.mautic.org/u/pierre_a)\
**Post date:** [March 22, 2022, 12:55pm UTC](https://forum.mautic.org/t/mautic-db-hygiene/23027/8 "2022-03-22T12:55:16Z")

</div>

Hello @mikew @jvilarnau,

You can check this : [Mautic Cleanup Commands · GitHub](https://gist.github.com/sebastian-fahrenkrog/0d53ced6a50ed680383f4680c6398635)

It’s work for me.

Pierre
