https://rt-wiki.bestpractical.com/index.php?title=CleanupSessions&feed=atom&action=historyCleanupSessions - Revision history2024-03-29T09:43:36ZRevision history for this page on the wikiMediaWiki 1.37.2https://rt-wiki.bestpractical.com/index.php?title=CleanupSessions&diff=513&oldid=prevAdmin: 2 revisions imported2016-04-06T20:03:25Z<p>2 revisions imported</p>
<p><b>New page</b></p><div>= rt-clean-sessions =<br />
<br />
Starting from RT 3.8, to cleanup sessions, it has been provided the tool :<br />
<br />
sbin/rt-clean-sessions<br />
<br />
<br />
dedicate to this task. This make obsolete all the other solutions down there, and avoid the duplication of the the db credentials.<br />
<br />
= Perl =<br />
<br />
Here's a simple perl script that you can run from cron nightly to clean up your sessions table. It will blow away any user sessions that haven't been touched in the last 24 hours.<br />
<br />
<nowiki>#!/usr/bin/perl<br />
use lib qw(/opt/rt3/lib);<br />
use RT;<br />
RT::LoadConfig();<br />
RT::Init();<br />
$RT::Handle-&gt;SimpleQuery("delete from sessions where LastUpdated &lt; (now() - interval 24 hour)");<br />
<br />
</nowiki><br />
<br />
With postgresql 7.4.6 and 7.4.5 this worked where the above did not.<br />
<br />
$RT::Handle-&gt;SimpleQuery("delete from sessions where LastUpdated &lt; (now() - '24 hour'::interval)");<br />
<br />
<br />
To avoid full table scan on that table could be nice to add an index on the [[LastUpdate]] field.<br />
<br />
create index LastUpdated on sessions (LastUpdated);<br />
<br />
= SQL =<br />
<br />
Just a little info from the irc channel, in case you want to clean up session regularly, as you should:<br />
<br />
&lt;ward&gt; this also seemed a bit odd:<br />
&lt;ward&gt; mysql&gt; select count(id) from sessions;<br />
&lt;ward&gt; +-----------+<br />
&lt;ward&gt; | count(id) |<br />
&lt;ward&gt; +-----------+<br />
&lt;ward&gt; | 133683 |<br />
&lt;ward&gt; +-----------+<br />
&lt;ward&gt; 1 row in set (5.24 sec)<br />
&lt;rrindels&gt; ouch<br />
&lt;oliof&gt; huh?<br />
&lt;rrindels&gt; must not prune your sessions regularly<br />
&lt;rrindels&gt; delete from sessions;<br />
&lt;rrindels&gt; in cron every night<br />
&lt;rrindels&gt; done<br />
&lt;ward&gt; ok, wiping session table entries now...<br />
&lt;rrindels&gt; I do mine nightly to force my users to relogin the next day anyway<br />
&lt;rrindels&gt; In fact I'm not sure if any part of RT's module base deals with<br />
session pruning<br />
&lt;ward&gt; ok; wiped session table content<br />
&lt;ward&gt; query builder is now _instant_<br />
&lt;ward&gt; adding nightly cron job now :)</div>Admin