<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[iRedMail — Amavis MySQL table cleanup/maintenence]]></title>
	<link rel="self" href="http://www.iredmail.org/forum/feed-atom-topic4350.xml" />
	<updated>2013-01-12T15:06:46Z</updated>
	<generator>PunBB</generator>
	<id>http://www.iredmail.org/forum/topic4350-amavis-mysql-table-cleanupmaintenence.html</id>
		<entry>
			<title type="html"><![CDATA[Re: Amavis MySQL table cleanup/maintenence]]></title>
			<link rel="alternate" href="http://www.iredmail.org/forum/post19836.html#p19836" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>broth wrote:</cite><blockquote><p>Maybe you should include a command line switch to select between deleting only quarantined messages or all messages older than x days.</p></blockquote></div><p>No plan yet, sorry.</p><p>== UPDATE ==<br />I removed &#039;content IN (&#039;S&#039;, &#039;s&#039;, &#039;V&#039;, &#039;Y&#039;) AND&#039; in SQL commands, so that it won&#039;t check msg type (banned, spammy, virus, etc).</p>]]></content>
			<author>
				<name><![CDATA[ZhangHuangbin]]></name>
				<uri>http://www.iredmail.org/forum/user2.html</uri>
			</author>
			<updated>2013-01-12T15:06:46Z</updated>
			<id>http://www.iredmail.org/forum/post19836.html#p19836</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Amavis MySQL table cleanup/maintenence]]></title>
			<link rel="alternate" href="http://www.iredmail.org/forum/post19834.html#p19834" />
			<content type="html"><![CDATA[<p>Hello Zhang,<br />the patch works, thank you!<br />Maybe you should include a command line switch to select between deleting only quarantined messages or all messages older than x days.<br />Best regards,<br />Bernhard</p>]]></content>
			<author>
				<name><![CDATA[broth]]></name>
				<uri>http://www.iredmail.org/forum/user31203.html</uri>
			</author>
			<updated>2013-01-12T13:15:50Z</updated>
			<id>http://www.iredmail.org/forum/post19834.html#p19834</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Amavis MySQL table cleanup/maintenence]]></title>
			<link rel="alternate" href="http://www.iredmail.org/forum/post19830.html#p19830" />
			<content type="html"><![CDATA[<p>Hi broth,</p><p>You can add this sql command in the file directly, or try below patch. Let me know whether it works for you or not.<br /></p><div class="codebox"><pre><code>diff -r 46eeed2e9cf8 tools/cleanup_amavisd_db.py
--- a/tools/cleanup_amavisd_db.py    Mon Jan 07 00:56:38 2013 +0800
+++ b/tools/cleanup_amavisd_db.py    Sat Jan 12 17:49:22 2013 +0800
@@ -98,6 +98,11 @@
         WHERE msgs.time_num &lt; UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL %d DAY))
         &#039;&#039;&#039; % settings.AMAVISD_REMOVE_MAILLOG_IN_DAYS
     )
+    conn.query(&#039;&#039;&#039;
+        DELETE FROM msgs
+        WHERE time_num &lt; UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL %d DAY))
+        &#039;&#039;&#039; % settings.AMAVISD_REMOVE_MAILLOG_IN_DAYS
+    )
 elif sql_dbn == &#039;postgres&#039;:
     conn.query(&#039;&#039;&#039;
         DELETE FROM msgrcpt
@@ -107,6 +112,11 @@
             AND msgs.time_iso &lt; CURRENT_TIMESTAMP - INTERVAL &#039;%d DAYS&#039;
         &#039;&#039;&#039; % settings.AMAVISD_REMOVE_MAILLOG_IN_DAYS
     )
+    conn.query(&#039;&#039;&#039;
+        DELETE FROM msgs
+        WHERE time_iso &lt; CURRENT_TIMESTAMP - INTERVAL &#039;%d DAYS&#039;
+        &#039;&#039;&#039; % settings.AMAVISD_REMOVE_MAILLOG_IN_DAYS
+    )
 
 # delete unreferenced records from tables msgrcpt, quarantine and maddr
 logger.info(&#039;Delete unreferenced records from table msgrcpt.&#039;)</code></pre></div>]]></content>
			<author>
				<name><![CDATA[ZhangHuangbin]]></name>
				<uri>http://www.iredmail.org/forum/user2.html</uri>
			</author>
			<updated>2013-01-12T09:49:46Z</updated>
			<id>http://www.iredmail.org/forum/post19830.html#p19830</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Amavis MySQL table cleanup/maintenence]]></title>
			<link rel="alternate" href="http://www.iredmail.org/forum/post19826.html#p19826" />
			<content type="html"><![CDATA[<p>From how I understand the script it does cleanup quarantined mails only.<br />This SQL query does remove them</p><p>&nbsp; &nbsp; &nbsp; &nbsp; DELETE FROM msgs<br />&nbsp; &nbsp; &nbsp; &nbsp; WHERE<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; content IN (&#039;S&#039;, &#039;s&#039;, &#039;V&#039;, &#039;Y&#039;)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AND quar_type = &#039;Q&#039;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AND time_num &lt; UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL %d DAY))</p><p>Following the next queries are removing unreferenced records. Thats fine.</p><p>I have many clean messages (content tag C) in my table.<br />Maybe you could include a command line parameter wether to delete only quarantined mails or anything older than X days:</p><p>DELETE FROM msgs<br />&nbsp; &nbsp; &nbsp; &nbsp; WHERE time_num &lt; UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 60 DAY))</p><p>I won&#039;t say there&#039;s a bug, it&#039;s only a missing feature <img src="http://www.iredmail.org/forum/img/smilies/smile.png" width="15" height="15" alt="smile" /><br />@Zhang: Can you implement the CLI switch and/or the modified query?</p>]]></content>
			<author>
				<name><![CDATA[broth]]></name>
				<uri>http://www.iredmail.org/forum/user31203.html</uri>
			</author>
			<updated>2013-01-12T05:56:51Z</updated>
			<id>http://www.iredmail.org/forum/post19826.html#p19826</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Amavis MySQL table cleanup/maintenence]]></title>
			<link rel="alternate" href="http://www.iredmail.org/forum/post19824.html#p19824" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>broth wrote:</cite><blockquote><p>BTW: Is it intended not to clean up the table amavisd.msgs?<br />That table has around 484000 rows and the login to iRedMail-Pro does take some time due to the statistics queries.</p></blockquote></div><p>It&#039;s supposed to be deleted with this script (cleanup_amavisd_db.py). There must be a bug if it doesn&#039;t do so.</p>]]></content>
			<author>
				<name><![CDATA[ZhangHuangbin]]></name>
				<uri>http://www.iredmail.org/forum/user2.html</uri>
			</author>
			<updated>2013-01-12T04:29:07Z</updated>
			<id>http://www.iredmail.org/forum/post19824.html#p19824</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Amavis MySQL table cleanup/maintenence]]></title>
			<link rel="alternate" href="http://www.iredmail.org/forum/post19823.html#p19823" />
			<content type="html"><![CDATA[<p>Sorry for hitchhike this thread but I was wondering it is safe to delete all the data in amavsid.msgs and amavsid.msgrcpt?</p><p>I am using below SQL script to delete the data in msgs and msgrcpt but it seem it only delete content IN (&#039;S&#039;, &#039;s&#039;, &#039;V&#039;, &#039;Y&#039;) AND quar_type = &#039;Q&#039; data. How about quar_type = &#039;C&#039;? I got around 4000+ rows of data in msgs table...do i need to clean it too?</p><p>DELETE FROM msgs WHERE content IN (&#039;S&#039;, &#039;s&#039;, &#039;V&#039;, &#039;Y&#039;) AND quar_type = &#039;Q&#039; AND time_num &lt; UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 7 DAY))</p><p><a href="http://www.iredmail.org/forum/post12114.html#p12114">http://www.iredmail.org/forum/post12114.html#p12114</a></p>]]></content>
			<author>
				<name><![CDATA[hata_ph]]></name>
				<uri>http://www.iredmail.org/forum/user1064.html</uri>
			</author>
			<updated>2013-01-12T02:55:56Z</updated>
			<id>http://www.iredmail.org/forum/post19823.html#p19823</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Amavis MySQL table cleanup/maintenence]]></title>
			<link rel="alternate" href="http://www.iredmail.org/forum/post19818.html#p19818" />
			<content type="html"><![CDATA[<p>BTW: Is it intended not to clean up the table amavisd.msgs?<br />That table has around 484000 rows and the login to iRedMail-Pro does take some time due to the statistics queries.</p>]]></content>
			<author>
				<name><![CDATA[broth]]></name>
				<uri>http://www.iredmail.org/forum/user31203.html</uri>
			</author>
			<updated>2013-01-11T15:57:44Z</updated>
			<id>http://www.iredmail.org/forum/post19818.html#p19818</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Amavis MySQL table cleanup/maintenence]]></title>
			<link rel="alternate" href="http://www.iredmail.org/forum/post19816.html#p19816" />
			<content type="html"><![CDATA[<p>Hello Zhang,<br />perfect, working like a charm! Thank you very much!<br />Great work!<br />Best regards,<br />Bernhard</p>]]></content>
			<author>
				<name><![CDATA[broth]]></name>
				<uri>http://www.iredmail.org/forum/user31203.html</uri>
			</author>
			<updated>2013-01-11T15:51:32Z</updated>
			<id>http://www.iredmail.org/forum/post19816.html#p19816</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Amavis MySQL table cleanup/maintenence]]></title>
			<link rel="alternate" href="http://www.iredmail.org/forum/post19812.html#p19812" />
			<content type="html"><![CDATA[<p>There&#039;s a cron job script shipped in iRedAdmin-Pro: tools/cleanup_amavisd_db.py, you can use it to delete older records. Please just open this file and read the top lines for basic usage.</p>]]></content>
			<author>
				<name><![CDATA[ZhangHuangbin]]></name>
				<uri>http://www.iredmail.org/forum/user2.html</uri>
			</author>
			<updated>2013-01-11T13:46:28Z</updated>
			<id>http://www.iredmail.org/forum/post19812.html#p19812</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Amavis MySQL table cleanup/maintenence]]></title>
			<link rel="alternate" href="http://www.iredmail.org/forum/post19810.html#p19810" />
			<content type="html"><![CDATA[<p>==== Required information ====<br />- iRedMail version: 0.8.3<br />- Store mail accounts in which backend (LDAP/MySQL/PGSQL): MySQL<br />- Linux/BSD distribution name and version: Debian 6.0<br />- Related log if you&#039;re reporting an issue: <br />==== </p><p>Hello!<br />My avamis MySQL tables are growing and getting slow, especially the msgs table.<br />What can be done to optimize these tables or cut them down?<br />Are there any special maintenance scripts to remove older messages from these table, e.g. all messages older than 30 days?<br />The iRedAdmin-Pro web interface is getting quite slow, too when logging in.</p><p>Maybe there is some regular maintenance job broken on that system?<br />Please help <img src="http://www.iredmail.org/forum/img/smilies/smile.png" width="15" height="15" alt="smile" /></p><p>Best regards,<br />Bernhard</p>]]></content>
			<author>
				<name><![CDATA[broth]]></name>
				<uri>http://www.iredmail.org/forum/user31203.html</uri>
			</author>
			<updated>2013-01-11T12:20:21Z</updated>
			<id>http://www.iredmail.org/forum/post19810.html#p19810</id>
		</entry>
</feed>
