Misc Matt | 16 Apr 2009
Manually Purge ColdFusion Client Sessions in Database
ColdFusion will purge your client sessions for you on a schedule. This schedule is dependent on when the CF engine starts. If your purge schedule is OK now, a CF reboot will set a new schedule and cause problems. if you use a database and your client variables table has hundred of thousands or millions of records, this can really kill performance.
I have disabled purge of client sessions in the CF Admin and do my purge during low load hours using a separate schedule.
I run 4 queries in a bash script. You can write a CF script to run these in windows or any other scripting language that let’s you connect to your client variable database.
Here’s the MySQL versions of the queries:
delete from CDATA where CFID in (select CFID from CGLOBAL where CGLOBAL.lvisit < date_sub(now(), interval 60 day));
delete from CGLOBAL where lvisit < date_sub(now(), interval 60 day);
optimize table CDATA;
optimize table CGLOBAL;
Optimizing your tables after the purge will clean up the empty space in your db file left now that those records are gone. This is helpful if you delete thousands of records at a time.