# Database Size 4.4GB - with campaign\_lead\_event\_log and lead\_event\_log accounting for 3.7GB

**URL:** <https://forum.mautic.org/t/database-size-4-4gb-with-campaign-lead-event-log-and-lead-event-log-accounting-for-3-7gb/17891>\
**Category:** Product Support\
**Tags:** development\
**Created:** [January 22, 2021, 5:20pm UTC](https://forum.mautic.org/t/database-size-4-4gb-with-campaign-lead-event-log-and-lead-event-log-accounting-for-3-7gb/17891 "2021-01-22T17:20:25Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![dirk\_s](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/dirk_s/32/748_2.png) [@dirk\_s](https://forum.mautic.org/u/dirk_s)\
**Post date:** [January 22, 2021, 5:20pm UTC](https://forum.mautic.org/t/database-size-4-4gb-with-campaign-lead-event-log-and-lead-event-log-accounting-for-3-7gb/17891/1 "2021-01-22T17:20:25Z")

</div>

**Your software**  
My Mautic version is: 2.6.15  
My PHP version is: 7.3

**Your problem**  
Database over time grew quite large. Almost all of the data is in tables:

- campaign\_lead\_event\_log and
- lead\_event\_log

Is there a safe way to get rid of them? The number of contacts is already trimmed to 365 days with the mautic:maintenance:cleanup

However - this seems not to cleanup the events logs?  
How can we save remove records?

---

<div class="post-metadata">

**Author:** ![joeyk](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/joeyk/32/11164_2.png) [@joeyk](https://forum.mautic.org/u/joeyk)\
**Post date:** [January 23, 2021, 11:05am UTC](https://forum.mautic.org/t/database-size-4-4gb-with-campaign-lead-event-log-and-lead-event-log-accounting-for-3-7gb/17891/2 "2021-01-23T11:05:31Z")

</div>

How old is your oldest event?  
Joey

---

<div class="post-metadata">

**Author:** ![dirk\_s](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/dirk_s/32/748_2.png) [@dirk\_s](https://forum.mautic.org/u/dirk_s)\
**Post date:** [January 24, 2021, 8:09pm UTC](https://forum.mautic.org/t/database-size-4-4gb-with-campaign-lead-event-log-and-lead-event-log-accounting-for-3-7gb/17891/3 "2021-01-24T20:09:39Z")

</div>

Earliest event is from 05/2018…

---

<div class="post-metadata">

**Author:** ![joeyk](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/joeyk/32/11164_2.png) [@joeyk](https://forum.mautic.org/u/joeyk)\
**Post date:** [January 24, 2021, 8:18pm UTC](https://forum.mautic.org/t/database-size-4-4gb-with-campaign-lead-event-log-and-lead-event-log-accounting-for-3-7gb/17891/4 "2021-01-24T20:18:44Z")

</div>

Maybe you should delete everything, that is really old:

> **[Housekeeping: Help the Mautic Datenbank Stay Lean](https://www.leuchtfeuer.com/en/mautic-know-how/mautic/mautic-database-housekeeping/)**
>
> The Mautic database tends to grow huge very quickly, especially when integrated on higher-traffic web sites. A large percentage is basically junk, though. Here are some simple tricks to reduce that drastically.
> Note that at the same time this...

---

<div class="post-metadata">

**Author:** ![dirk\_s](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/dirk_s/32/748_2.png) [@dirk\_s](https://forum.mautic.org/u/dirk_s)\
**Post date:** [January 26, 2021, 10:54am UTC](https://forum.mautic.org/t/database-size-4-4gb-with-campaign-lead-event-log-and-lead-event-log-accounting-for-3-7gb/17891/5 "2021-01-26T10:54:51Z")

</div>

> [@joeyk](#):
>
> Housekeeping: Help the Mautic Datenbank Stay Lean

Unfortunately those tipps seem always to be contact related… I would rather cleanup old events, than contacts 😉

---

<div class="post-metadata">

**Author:** ![EJL](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/ejl/32/12155_2.png) [@EJL](https://forum.mautic.org/u/EJL)\
**Post date:** [January 26, 2021, 4:02pm UTC](https://forum.mautic.org/t/database-size-4-4gb-with-campaign-lead-event-log-and-lead-event-log-accounting-for-3-7gb/17891/6 "2021-01-26T16:02:42Z")

</div>

I don’t recommend it to everyone, but I use Dbeaver and SQLyog to tidy up.  
Add your DB credentials  
connect  
select the table  
use the filters to identify events you want to delete  
Select all and delete.

Make a backup before you start of course

---

<div class="post-metadata">

**Author:** ![joeyk](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/joeyk/32/11164_2.png) [@joeyk](https://forum.mautic.org/u/joeyk)\
**Post date:** [January 26, 2021, 5:34pm UTC](https://forum.mautic.org/t/database-size-4-4gb-with-campaign-lead-event-log-and-lead-event-log-accounting-for-3-7gb/17891/7 "2021-01-26T17:34:44Z")

</div>

I do the same.  
And I also don’t recommend it 🙂

---

<div class="post-metadata">

**Author:** ![joeyk](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/joeyk/32/11164_2.png) [@joeyk](https://forum.mautic.org/u/joeyk)\
**Post date:** [January 26, 2021, 5:37pm UTC](https://forum.mautic.org/t/database-size-4-4gb-with-campaign-lead-event-log-and-lead-event-log-accounting-for-3-7gb/17891/8 "2021-01-26T17:37:05Z")

</div>

php /path/to/mautic/app/console mautic:maintenance:cleanup --days-old=365 --dry-run

This only deletes:

![image](https://us1.discourse-cdn.com/flex020/uploads/mautic/original/2X/0/0c673676dfc655b6bcc24075f4833102dd29b4c3.png)

The above entries (apprx 900 entries) happened in 4-5 days on a site where I only have around 50 visitors / day. You should try the dry run and see what happens, it won’t delete anything just give you heads up.

---

<div class="post-metadata">

**Author:** ![dirk\_s](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/dirk_s/32/748_2.png) [@dirk\_s](https://forum.mautic.org/u/dirk_s)\
**Post date:** [January 26, 2021, 10:47pm UTC](https://forum.mautic.org/t/database-size-4-4gb-with-campaign-lead-event-log-and-lead-event-log-accounting-for-3-7gb/17891/9 "2021-01-26T22:47:35Z")

</div>

thanks, thats what I did first 😉  
will investigate into what you both don’t recommend.  
probably I will not recommend it either and do it too.

---

<div class="post-metadata">

**Author:** ![sfahrenkrog1](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/sfahrenkrog1/32/4583_2.png) [@sfahrenkrog1](https://forum.mautic.org/u/sfahrenkrog1)\
**Post date:** [January 28, 2021, 4:48pm UTC](https://forum.mautic.org/t/database-size-4-4gb-with-campaign-lead-event-log-and-lead-event-log-accounting-for-3-7gb/17891/10 "2021-01-28T16:48:51Z")

</div>

Hi Dirk

We did the following to cleanup our mautic database:

DELETE FROM campaign\_lead\_event\_log WHERE date\_triggered \< (NOW() - INTERVAL 60 DAY);  
UPDATE campaign\_lead\_event\_log SET metadata = ‘’;

DELETE from lead\_event\_log where bundle=“lead” and object=“import” WHERE date\_added \< (NOW() - INTERVAL 30 DAY);

But very important:  
Dont forget to do the folowing

OPTIMIZE LOCAL TABLE campaign\_lead\_event\_log;  
OPTIMIZE LOCAL TABLE lead\_event\_log;

Only after this command you free up the space.

We got this from this ticket here:

> <https://github.com/mautic/mautic/issues/7763>
>
> Bug Description
> This issue persisted in Mautic for quite a long time, but seems like recent update made it worse.
> Given: quite big...

Greetings  
Sebastian

---

<div class="post-metadata">

**Author:** ![sfahrenkrog1](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/sfahrenkrog1/32/4583_2.png) [@sfahrenkrog1](https://forum.mautic.org/u/sfahrenkrog1)\
**Post date:** [January 28, 2021, 4:50pm UTC](https://forum.mautic.org/t/database-size-4-4gb-with-campaign-lead-event-log-and-lead-event-log-accounting-for-3-7gb/17891/11 "2021-01-28T16:50:14Z")

</div>

Sorry one thing:  
Maybe you want to increase the INTERVAL xx DAY to fit your needs

---

<div class="post-metadata">

**Author:** ![dirk\_s](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/dirk_s/32/748_2.png) [@dirk\_s](https://forum.mautic.org/u/dirk_s)\
**Post date:** [January 28, 2021, 5:06pm UTC](https://forum.mautic.org/t/database-size-4-4gb-with-campaign-lead-event-log-and-lead-event-log-accounting-for-3-7gb/17891/12 "2021-01-28T17:06:25Z")

</div>

So there are no vital dependencies, that expect the event logs to exist completely?

---

<div class="post-metadata">

**Author:** ![sfahrenkrog1](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/sfahrenkrog1/32/4583_2.png) [@sfahrenkrog1](https://forum.mautic.org/u/sfahrenkrog1)\
**Post date:** [January 28, 2021, 5:21pm UTC](https://forum.mautic.org/t/database-size-4-4gb-with-campaign-lead-event-log-and-lead-event-log-accounting-for-3-7gb/17891/13 "2021-01-28T17:21:31Z")

</div>

I used the statements several times and did not recognized any issue with that.

But in the issue one user wrotes:

> Be careful with it! 🙂
> 
> If you have some campaign waiting for “page visits” you can break it.
> 
> I tested these queries, and I have caused many messages in my GDPR workflow to be sent again.
> 
> My campaign looks like “for new contacts in segment A, send an email, and wait for visits to confirmation-page to move them to another segment.”
> 
> I hope you find this message useful.

You could also adapt the sql query and use it only for campaigns which are no longer are active.

---

<div class="post-metadata">

**Author:** ![sfahrenkrog1](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/sfahrenkrog1/32/4583_2.png) [@sfahrenkrog1](https://forum.mautic.org/u/sfahrenkrog1)\
**Post date:** [January 28, 2021, 5:26pm UTC](https://forum.mautic.org/t/database-size-4-4gb-with-campaign-lead-event-log-and-lead-event-log-accounting-for-3-7gb/17891/14 "2021-01-28T17:26:42Z")

</div>

I would suggest:  
Copy your installation to a staging installation and stop the mail cronjobs for this installation.

Clean the database on the staging installation like you would on the live enviroment and check the mail spool folder for emails to appear.

If there are emails in the spool, chances are high that you trigger some campaigns again. But in my experience this happens rarely if you use an day interval big enough in the query.

---

<div class="post-metadata">

**Author:** ![EJL](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/ejl/32/12155_2.png) [@EJL](https://forum.mautic.org/u/EJL)\
**Post date:** [January 29, 2021, 4:38pm UTC](https://forum.mautic.org/t/database-size-4-4gb-with-campaign-lead-event-log-and-lead-event-log-accounting-for-3-7gb/17891/15 "2021-01-29T16:38:06Z")

</div>

You can run **mautic:campaigns:validate** to see if there are inactive contacts hung up in your campaign as well

---

<div class="post-metadata">

**Author:** ![alexhammer](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/alexhammer/32/14525_2.png) [@alexhammer](https://forum.mautic.org/u/alexhammer)\
**Post date:** [June 21, 2022, 8:12am UTC](https://forum.mautic.org/t/database-size-4-4gb-with-campaign-lead-event-log-and-lead-event-log-accounting-for-3-7gb/17891/16 "2022-06-21T08:12:11Z")

</div>

Hi Sebastian,  
why did you use this line

```auto
DELETE from lead_event_log where bundle=“lead” and object=“import” WHERE date_added < (NOW() - INTERVAL 30 DAY);

```

?  
Is it only to get rid of the import event in the logs? I mean from imported contacts?

Cheers,  
Alex

---

<div class="post-metadata">

**Author:** ![sfahrenkrog1](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/sfahrenkrog1/32/4583_2.png) [@sfahrenkrog1](https://forum.mautic.org/u/sfahrenkrog1)\
**Post date:** [June 30, 2022, 9:59am UTC](https://forum.mautic.org/t/database-size-4-4gb-with-campaign-lead-event-log-and-lead-event-log-accounting-for-3-7gb/17891/17 "2022-06-30T09:59:08Z")

</div>

HI Alex

> Is it only to get rid of the import event in the logs? I mean from imported contacts?

Yes, exactly. If your clients use a lot of imports (or if you have something like a hotfolder import ) this gets really huge. But you don’t need to delete this.

greetings  
Sebastian

---

<div class="post-metadata">

**Author:** ![alexhammer](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/alexhammer/32/14525_2.png) [@alexhammer](https://forum.mautic.org/u/alexhammer)\
**Post date:** [July 5, 2022, 8:08am UTC](https://forum.mautic.org/t/database-size-4-4gb-with-campaign-lead-event-log-and-lead-event-log-accounting-for-3-7gb/17891/18 "2022-07-05T08:08:34Z")

</div>

Yes I thought so. Thank you Sebastian 🙂

---

<div class="post-metadata">

**Author:** ![sfahrenkrog1](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/sfahrenkrog1/32/4583_2.png) [@sfahrenkrog1](https://forum.mautic.org/u/sfahrenkrog1)\
**Post date:** [July 5, 2022, 11:28am UTC](https://forum.mautic.org/t/database-size-4-4gb-with-campaign-lead-event-log-and-lead-event-log-accounting-for-3-7gb/17891/19 "2022-07-05T11:28:25Z")

</div>

Hey Alex

I would like to recommend you this thread regarding the db cleanup:

> [@Mautic database is huge, can I manually delete old records?](https://forum.mautic.org/t/mautic-database-is-huge-can-i-manually-delete-old-records/22646/6):
>
> Hey Instamaker You could do this commands on the shell (backup + on your own risk!) We do them regularly but I could give you no garanty. There is a new plugin which does some campaign\_lead\_event\_log cleanups: [https://github.com/Leuchtfeuer/mautic-housekeeping-bundle](https://github.com/Leuchtfeuer/mautic-housekeeping-bundle) \*\*Update: \*\* Sorry made a mistake in the audit log statement. Fixed it in the gist. Greetings Sebastian

I also published our intern db cleanup script there.

Direct link to my gist in the thread:

> <https://gist.github.com/sebastian-fahrenkrog/0d53ced6a50ed680383f4680c6398635>

Greetings  
Sebastian
