The database size increased due to the attachments are stored in the Email Queue as base64. and @ManasSolanki and @netchampfaris has already fixed this issue.
Just wanted to revive this topic since I think its a pertinent question and hasn’t been answered well in the last time it was asked.
Let me put things in perspective I have been using erpnext since 2010 and I have a DB file zipped (.gz) file at a size of about 3 GB and unzipped it becomes around 9GB, out of which the total size of the tables in my DB is as below just to give an idea:
Now there are around 193301 records in my email queue table but I have hardly ever looked at them, what its basically showing whether an email is sent or not or there is error and out these 193301 records only 352 records which are not sent:
So does it make sense to have such a huge table sit on top of the DB which is basically of no use as of now.
The only use I could see in future for this table is whether an email is read or not and we might need to fetch the details from some service like Sparkpost about whether an email has been read or not, which I think still a dream.
Also would like to add here that having this table with such huge records is basically also delaying the process of migrations and patches since every time a table is renamed it checks the email queue and replaces the values in this table and almost takes forever to execute
I would myself want to know if its safe to remove the records atleast the ones which are sent and older than maybe like a week or we can give a field in settings page for users to define if they want to keep the email queue forever or the want to delete it by days and run a scheduler even every day for deleting the records.
Just wanted to add that email queue started to add up data somewhere in 2017-May and for a small users like me it has grown to 3GB or thereabouts in a matter of 1.25 years and what would be happening to DB load on erpnext cloud hosting servers god knows, no wonder the cost of hosting erpnext accounts is going to go up.
My solution would be add a field to state that whether users want email queue in settings page and run this command everyday:
DELETE FROM `tabEmail Queue` WHERE status = 'Sent' AND TIMESTAMPDIFF(DAY, creation, now()) > 90 LIMIT 10000;
WHERE 90 is the value which is defined by users in their settings page
Just a follow-up on the above said solution, I just ran it on my test environment and found out that after deleting entries older than 90 days the table size was reduced by 2.5GB which is clear from the below table: