CleanupSessions

From Request Tracker Wiki
Revision as of 16:03, 6 April 2016 by Admin (talk | contribs) (2 revisions imported)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

rt-clean-sessions

Starting from RT 3.8, to cleanup sessions, it has been provided the tool :

sbin/rt-clean-sessions

dedicate to this task. This make obsolete all the other solutions down there, and avoid the duplication of the the db credentials.

Perl

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.

#!/usr/bin/perl
 use lib qw(/opt/rt3/lib);
 use RT;
 RT::LoadConfig();
 RT::Init();
 $RT::Handle->SimpleQuery("delete from sessions where LastUpdated < (now() - interval 24 hour)");
 
 

With postgresql 7.4.6 and 7.4.5 this worked where the above did not.

$RT::Handle->SimpleQuery("delete from sessions where LastUpdated < (now() - '24 hour'::interval)");

To avoid full table scan on that table could be nice to add an index on the LastUpdate field.

create index LastUpdated on sessions (LastUpdated);

SQL

Just a little info from the irc channel, in case you want to clean up session regularly, as you should:

<ward> this also seemed a bit odd:
<ward> mysql> select count(id) from sessions;
<ward> +-----------+
<ward> | count(id) |
<ward> +-----------+
<ward> |    133683 |
<ward> +-----------+
<ward> 1 row in set (5.24 sec)
<rrindels> ouch
<oliof> huh?
<rrindels> must not prune your sessions regularly
<rrindels> delete from sessions;
<rrindels> in cron every night
<rrindels> done
<ward> ok, wiping session table entries now...
<rrindels> I do mine nightly to force my users to relogin the next day anyway
<rrindels> In fact I'm not sure if any part of RT's module base deals with
          session pruning
<ward> ok; wiped session table content
<ward> query builder is now _instant_
<ward> adding nightly cron job now :)