<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/xsl" href="RSS_xslt_style.asp" version="1.0" ?>
<rss version="2.0" xmlns:WebWizForums="http://syndication.webwiz.co.uk/rss_namespace/">
 <channel>
  <title>Spam Filter ISP Forums : MySQL commands for cleanup</title>
  <link>https://www.logsat.com/spamfilter/forums/</link>
  <description><![CDATA[This is an XML content feed of; Spam Filter ISP Forums : Spam Filter ISP Support : MySQL commands for cleanup]]></description>
  <pubDate>Sat, 06 Jun 2026 09:18:47 +0000</pubDate>
  <lastBuildDate>Tue, 28 Dec 2010 07:13:58 +0000</lastBuildDate>
  <docs>http://blogs.law.harvard.edu/tech/rss</docs>
  <generator>Web Wiz Forums 11.04</generator>
  <ttl>360</ttl>
  <WebWizForums:feedURL>https://www.logsat.com/spamfilter/forums/RSS_post_feed.asp?TID=6845</WebWizForums:feedURL>
  <image>
   <title><![CDATA[Spam Filter ISP Forums]]></title>
   <url>https://www.logsat.com/spamfilter/forums/forum_images/web_wiz_forums.png</url>
   <link>https://www.logsat.com/spamfilter/forums/</link>
  </image>
  <item>
   <title><![CDATA[MySQL commands for cleanup : Thanks for the detailed feedback...]]></title>
   <link>https://www.logsat.com/spamfilter/forums/forum_posts.asp?TID=6845&amp;PID=13950&amp;title=mysql-commands-for-cleanup#13950</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="https://www.logsat.com/spamfilter/forums/member_profile.asp?PF=104">yapadu</a><br /><strong>Subject:</strong> 6845<br /><strong>Posted:</strong> 28 December 2010 at 7:13am<br /><br />Thanks for the detailed feedback Roberto, we do have an index on that field.&nbsp; I am just surprised how long it takes even with an index.<br><br>On my server with 512,000 records in tblquarantine and 360,000 records in tblmsgs the process takes between 2 - 4 minutes with an index.&nbsp; With no index, you can forget about it.&nbsp; I tried it, but aborted after 24 hours.<br><br>Nothing further can be placed in quarantine causing an immediate backlog for servers that might try and place items in quarantine when this housekeeping is going on.<br><br>If you have multiple spamfilter servers running, I don't see any need for both (you have a primary and secondary right?) of the servers to be executing the cleanup every hour.<br><br>We have made some changes to our system and can run two different routes to do our housekeeping.&nbsp; Our 'regular' housekeeping now takes less than 4 seconds.&nbsp; A few times a day we can do a 'deep' housekeeping and it takes about 30 - 40 seconds.<br><br>Will try it like this for a while and see how it goes, our spamfilter actually did not<br>have a problem, just trying to make it faster as we did notice the servers getting backlogged from time to time.&nbsp; The backlog lasted a couple of minutes each time, so I suspect it was the housekeeping that was locking the tblmsgs table.]]>
   </description>
   <pubDate>Tue, 28 Dec 2010 07:13:58 +0000</pubDate>
   <guid isPermaLink="true">https://www.logsat.com/spamfilter/forums/forum_posts.asp?TID=6845&amp;PID=13950&amp;title=mysql-commands-for-cleanup#13950</guid>
  </item> 
  <item>
   <title><![CDATA[MySQL commands for cleanup : The time would depend on the database...]]></title>
   <link>https://www.logsat.com/spamfilter/forums/forum_posts.asp?TID=6845&amp;PID=13949&amp;title=mysql-commands-for-cleanup#13949</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="https://www.logsat.com/spamfilter/forums/member_profile.asp?PF=8">LogSat</a><br /><strong>Subject:</strong> 6845<br /><strong>Posted:</strong> 27 December 2010 at 11:19pm<br /><br />The time would depend on the database server's speed and type of database (SQL Server 2005 and higher for example are <i>much</i>&nbsp;faster than MySQL). Guest-imating I'd say anywhere between 10 and 60 minutes. SpamFilter runs that query by default every 60 minutes, but that can be of course be customized and/or disabled (from the "Database Setup" tab).<div><br></div><div>Are you 100% certain that the MsgID field in the tblQuarantine does not have an index? There should indeed be one, along with several others for other fields as well.</div><div><br></div><div>Are you running MySQL or Microsoft SQL Server? If you're running Microsoft SQL Server, you could disable SpamFilter's cleanup procedure (see above) and follow the thread at:</div><div>http://www.logsat.com/SpamFilter/Forums/forum_posts.asp?TID=6745&amp;PID=13167</div><div>to schedule the cleanup with an optimized stored procedure.</div><div><br></div><div>If you're running MySQL, we sometimes suggest creating the extra indexes to improve performance during the cleanup.&nbsp;Both are made up of multiple fields:</div><div><br></div><div>Index for: emailto, msgid, msgdate, deliver, expire&nbsp;</div><div>and one for: MsgID, Deliver, Expire, ServerID&nbsp;</div><div><br></div><div>This may help increase performance while deleting records.</div><div><br></div><div>You can create the indexes easily using the MySQL Administrator, or if you wish, you can use execute the SQL statements below:&nbsp;</div><div><br></div><div>ALTER TABLE `SpamFilter`.`tblquarantine` ADD INDEX Optimize_1(`emailto`, `msgid`, `msgdate`, `deliver`, `expire`);</div><div>ALTER TABLE `SpamFilter`.`tblquarantine` ADD INDEX Optimize_2(`msgid`, `deliver`, `expire`, `serverid`);</div><div><br></div><div><br></div><div>In regards to your suggested query, I'd recommend against it. Deleting entries from the tblMsgs causes the database's built-in triggers we added as a safety-net to kick in to perform cascade deletes from the related records in the tblQuarantine, which should make the query run slowly. In addition, there isn't a parameter in it to specify how old the messages have to be before being deleted.</div>]]>
   </description>
   <pubDate>Mon, 27 Dec 2010 23:19:24 +0000</pubDate>
   <guid isPermaLink="true">https://www.logsat.com/spamfilter/forums/forum_posts.asp?TID=6845&amp;PID=13949&amp;title=mysql-commands-for-cleanup#13949</guid>
  </item> 
  <item>
   <title><![CDATA[MySQL commands for cleanup : How long do you estimate that...]]></title>
   <link>https://www.logsat.com/spamfilter/forums/forum_posts.asp?TID=6845&amp;PID=13946&amp;title=mysql-commands-for-cleanup#13946</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="https://www.logsat.com/spamfilter/forums/member_profile.asp?PF=104">yapadu</a><br /><strong>Subject:</strong> 6845<br /><strong>Posted:</strong> 27 December 2010 at 1:33am<br /><br />How long do you estimate that query (DELETE tblMsgs FROM tblMsgs) would take to execute on say 750k rows?&nbsp; And how often is spamfilter running that query?<br><br>From the looks of it, out of the box the tblMsgs has an index on msgid as it is the primary key for the table.<br><br>The msgid field in tblquarantine does not have an index (or is mine missing it?).<br><br>I made a copy of my spamfilter database and tried to run the command and it took so long I just gave up at about 45 minutes.<br><br>What is the INI entry to disable the housekeeping?<br><br>I'm thinking of putting an index on tblquarantine.msgid.&nbsp; The resulting join is faster but still quite slow on my server (about 3 mintutes).&nbsp; Something like following is much faster, but does it create some other issue I might be overlooking?<br><br>delete from tblmsgs<br>where msgid &lt; ( select min(msgid) from tblquarantine )]]>
   </description>
   <pubDate>Mon, 27 Dec 2010 01:33:52 +0000</pubDate>
   <guid isPermaLink="true">https://www.logsat.com/spamfilter/forums/forum_posts.asp?TID=6845&amp;PID=13946&amp;title=mysql-commands-for-cleanup#13946</guid>
  </item> 
  <item>
   <title><![CDATA[MySQL commands for cleanup : Good observationsThe foreign key...]]></title>
   <link>https://www.logsat.com/spamfilter/forums/forum_posts.asp?TID=6845&amp;PID=13945&amp;title=mysql-commands-for-cleanup#13945</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="https://www.logsat.com/spamfilter/forums/member_profile.asp?PF=8">LogSat</a><br /><strong>Subject:</strong> 6845<br /><strong>Posted:</strong> 26 December 2010 at 11:26pm<br /><br />Good observations&nbsp;<img src="https://www.logsat.com/spamfilter/forums/smileys/smiley1.gif" border="0" alt="Smile" title="Smile" /><div><br></div><div>The foreign key constraints is however not enforced on inserts, just on deletes. This means that if a record in the tblMsgs table is deleted, then all records in the tblQuarantine table that point to it are automatically deleted by the database as well. Do not forget that if a spam email is sent to multiple users, we only store one record with the actual email contents in the tblMsgs, while we save multiple "headers" for the individual recipients in the tblQuarantine. This allows us to save lots of disk space as we only save the actual email once.</div><div><br></div><div>In reality however, to optimize the routine cleanup process, we do not rely on the database's foreign key constraint as that is actually cause of slowdowns, since for each delete on the tblMsgs the database has to lookup and individually delete all records from the tblQuarantine. We find it more efficient to first delete in bulk all old records from the tblQuarantine. There are no cascading deletes here, so the process is very fast. Once this is done, we delete all orphaned records in the tblMsgs table. As here there are now more "linked" records (we just deleted them all before), this process is very fast as well.</div><div><br></div><div>We left the foreign key cascade delete constraint as it's always better to have a good cleanup in place in case the entries in the tblMsgs table are deleted by an external process and our routine scheduled cleanup has been disabled...</div>]]>
   </description>
   <pubDate>Sun, 26 Dec 2010 23:26:18 +0000</pubDate>
   <guid isPermaLink="true">https://www.logsat.com/spamfilter/forums/forum_posts.asp?TID=6845&amp;PID=13945&amp;title=mysql-commands-for-cleanup#13945</guid>
  </item> 
  <item>
   <title><![CDATA[MySQL commands for cleanup :   LogSat wrote:Then we issue...]]></title>
   <link>https://www.logsat.com/spamfilter/forums/forum_posts.asp?TID=6845&amp;PID=13944&amp;title=mysql-commands-for-cleanup#13944</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="https://www.logsat.com/spamfilter/forums/member_profile.asp?PF=104">yapadu</a><br /><strong>Subject:</strong> 6845<br /><strong>Posted:</strong> 26 December 2010 at 6:56am<br /><br /><table width="99%"><tr><td class="BBquote"><img src="forum_images/quote_box.png" title="Originally posted by LogSat" alt="Originally posted by LogSat" style="vertical-align: text-bottom;" /> <strong>LogSat wrote:</strong><br /><br />Then we issue the actual delete query:&nbsp;<div>&nbsp;&nbsp;</div><div>DELETE FROM tblQuarantine WHERE tblQuarantine.Expire &lt;&gt; 0&nbsp;</div><div>&nbsp;&nbsp;</div><div>That deletes most of rows from the tblQuarantine (and due to the database constraints, the related records in the tblMsgs), but may leave behind some "orphaned" rows in the tblMsgs. So we then issue the following as a backup to ensure all orphans are deleted as well:</div><div><br></div><div>DELETE tblMsgs FROM tblMsgs LEFT JOIN tblQuarantine&nbsp;</div><div>ON tblMsgs.MsgID = tblQuarantine.MsgID WHERE (tblQuarantine.MsgID IS NULL)</div></td></tr></table><br><br><br>I was just searching this forum to see what cleanup functions are being run as I found a bunch of old messages in the tblquarantine.<br><br>You mentioned a foreign key constraint, neither my tblquarantine or tblmsgs has any.&nbsp; I did some searching of the database scripts and found this one:<br><br><i>ALTER TABLE `tblQuarantine` ADD<br>&nbsp;&nbsp;&nbsp; CONSTRAINT `FK_tblQuarantine_tblMsgs` FOREIGN KEY `FK_tblQuarantine_tblMsgs`<br>&nbsp;&nbsp;&nbsp; (`MsgID`) REFERENCES `tblMsgs` (`MsgID`) ON DELETE CASCADE ;</i><br><br>This creates a constraint from tblQuarantine -&gt; tblMsgs, so I assume that spamfilter inserts the message into tblMsgs first to generate the msgID needed for tblQuarantine.<br><br>A message record could not exists in tblQuarantine if there was no matching record in tblMsgs, except you delete messages via the tblQuarantine as tblMsgs has no date information.&nbsp; So that constraint doesn't really do anything, it would actually need to be the other way around, no?<br>&nbsp;&nbsp;&nbsp; <br><br><br>]]>
   </description>
   <pubDate>Sun, 26 Dec 2010 06:56:38 +0000</pubDate>
   <guid isPermaLink="true">https://www.logsat.com/spamfilter/forums/forum_posts.asp?TID=6845&amp;PID=13944&amp;title=mysql-commands-for-cleanup#13944</guid>
  </item> 
  <item>
   <title><![CDATA[MySQL commands for cleanup : So if you keep the email for two...]]></title>
   <link>https://www.logsat.com/spamfilter/forums/forum_posts.asp?TID=6845&amp;PID=13726&amp;title=mysql-commands-for-cleanup#13726</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="https://www.logsat.com/spamfilter/forums/member_profile.asp?PF=104">yapadu</a><br /><strong>Subject:</strong> 6845<br /><strong>Posted:</strong> 27 July 2010 at 6:13pm<br /><br />So if you keep the email for two weeks, you end up with maybe a little over 2 million messages in that table.<br><br>It should not be a big issue for mysql to hold that many records in a database.&nbsp; What type of hardware is the database running on?<br>]]>
   </description>
   <pubDate>Tue, 27 Jul 2010 18:13:36 +0000</pubDate>
   <guid isPermaLink="true">https://www.logsat.com/spamfilter/forums/forum_posts.asp?TID=6845&amp;PID=13726&amp;title=mysql-commands-for-cleanup#13726</guid>
  </item> 
  <item>
   <title><![CDATA[MySQL commands for cleanup : Hi Thanks for reply We get about...]]></title>
   <link>https://www.logsat.com/spamfilter/forums/forum_posts.asp?TID=6845&amp;PID=13725&amp;title=mysql-commands-for-cleanup#13725</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="https://www.logsat.com/spamfilter/forums/member_profile.asp?PF=865">morten44</a><br /><strong>Subject:</strong> 6845<br /><strong>Posted:</strong> 27 July 2010 at 5:58pm<br /><br />Hi<DIV>Thanks for reply</DIV><DIV>We get about 120.000-150.000 incomming mails a day</DIV><DIV>About 90% is spam</DIV><DIV>I think our problem has to do with the size of the mysql database as when it gets big spamfilter freezes when mysql is running. When i stop mysql, spamfiler start to work ok again.</DIV><DIV>Our spamfilter program is working good as long as we dont the quarantene database. IT works well for 3 weeks after a new install and then the problems starts</DIV><DIV>&nbsp;</DIV><DIV>&nbsp;</DIV>]]>
   </description>
   <pubDate>Tue, 27 Jul 2010 17:58:11 +0000</pubDate>
   <guid isPermaLink="true">https://www.logsat.com/spamfilter/forums/forum_posts.asp?TID=6845&amp;PID=13725&amp;title=mysql-commands-for-cleanup#13725</guid>
  </item> 
  <item>
   <title><![CDATA[MySQL commands for cleanup : tblmsgs stores the actual email...]]></title>
   <link>https://www.logsat.com/spamfilter/forums/forum_posts.asp?TID=6845&amp;PID=13723&amp;title=mysql-commands-for-cleanup#13723</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="https://www.logsat.com/spamfilter/forums/member_profile.asp?PF=104">yapadu</a><br /><strong>Subject:</strong> 6845<br /><strong>Posted:</strong> 27 July 2010 at 7:22am<br /><br />tblmsgs stores the actual email that has been placed in quarantine.&nbsp; You can only make this table smaller by storing the messages for fewer days.&nbsp; If you currently store for 14 days, if you reduce it to 7 days the table size would reduce by about half.<br><br>I see from this thread you are doing your own cleanup, and not relying on spamfilter to do it so you might want to make sure it is working.<br><br>How many messages do you process a day that you have a 5gb tblmsgs table?<br>]]>
   </description>
   <pubDate>Tue, 27 Jul 2010 07:22:40 +0000</pubDate>
   <guid isPermaLink="true">https://www.logsat.com/spamfilter/forums/forum_posts.asp?TID=6845&amp;PID=13723&amp;title=mysql-commands-for-cleanup#13723</guid>
  </item> 
  <item>
   <title><![CDATA[MySQL commands for cleanup : Hi Thanks for your reply At...]]></title>
   <link>https://www.logsat.com/spamfilter/forums/forum_posts.asp?TID=6845&amp;PID=13719&amp;title=mysql-commands-for-cleanup#13719</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="https://www.logsat.com/spamfilter/forums/member_profile.asp?PF=865">morten44</a><br /><strong>Subject:</strong> 6845<br /><strong>Posted:</strong> 26 July 2010 at 12:57pm<br /><br />Hi<DIV>Thanks for your reply</DIV><DIV>At a closer look I can see that after Optemizing the database the tblquarantene is about 120MB and that is acceptable. I cant remember what it was before because my focus was on the tblmsgs table. That is about 5GB and that does not seem to get smaller.</DIV><DIV>&nbsp;</DIV><DIV>Do you know what the table is used for?</DIV><DIV>Is there a way to empty that one or make it smaller?</DIV><DIV>&nbsp;</DIV><DIV>I cant even open it as it freezes, probably because its to big.</DIV><DIV><BR>At the moment I have managed to get Spamfilter up and running again by disable the database, but its not optimal.</DIV><DIV>&nbsp;</DIV><DIV>I seem to have this issue every time i setup this system. I have tried to setup ISP spamfilter 3 times on 2 servers and it runs fine for 2-3 weeks, then it starts to behave strange and customers can not connect and send/receive. At the same time server starts to be very slow, to a point of freezing.</DIV><DIV>If i broswe using Windows Explorer inside the spamfilter homedir and click on quarantene Explorer freezes.</DIV><DIV>&nbsp;</DIV><DIV>Hope there are some with simular issues who has a solution to the freezing or how to make the tblmsgs smaller</DIV><DIV>&nbsp;</DIV><DIV>&nbsp;</DIV><DIV>Regards</DIV><DIV>Morten</DIV>]]>
   </description>
   <pubDate>Mon, 26 Jul 2010 12:57:03 +0000</pubDate>
   <guid isPermaLink="true">https://www.logsat.com/spamfilter/forums/forum_posts.asp?TID=6845&amp;PID=13719&amp;title=mysql-commands-for-cleanup#13719</guid>
  </item> 
  <item>
   <title><![CDATA[MySQL commands for cleanup : I too was not sure what was going...]]></title>
   <link>https://www.logsat.com/spamfilter/forums/forum_posts.asp?TID=6845&amp;PID=13717&amp;title=mysql-commands-for-cleanup#13717</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="https://www.logsat.com/spamfilter/forums/member_profile.asp?PF=811">leeH</a><br /><strong>Subject:</strong> 6845<br /><strong>Posted:</strong> 24 July 2010 at 6:46pm<br /><br />I too was not sure what was going on but it turned out that you need to optimize the databases&nbsp;too in order to shrink the physical size down.<DIV>&nbsp;</DIV><DIV>Lee</DIV>]]>
   </description>
   <pubDate>Sat, 24 Jul 2010 18:46:48 +0000</pubDate>
   <guid isPermaLink="true">https://www.logsat.com/spamfilter/forums/forum_posts.asp?TID=6845&amp;PID=13717&amp;title=mysql-commands-for-cleanup#13717</guid>
  </item> 
 </channel>
</rss>