While figuring out the problems we’ve been having at the site we noticed how huge the sessions table was getting, averaging over 35,000 rows at any given time. The size of the sessions table is due to the Drupal default settings in SETTINGS.PHP, which looks (in part) something like this:
With these default settings, your sessions wont expire for many, many minutes (I tried to calculate it, but I only have 10 fingers). UNexpired sessions means two things:
- Your sessions table will get fat
- Users will remain logged-in for days after exiting from their browser
Having a fat sessions table isn’t necessarily a bad thing, but in my case we’ve been having troubles with DUPLICATE ENTRY INSERT INTO SESSIONS table errors that were crippling the site. It also can be a bit of a security issue for our users because it means they remain logged in after leaving the site. This can be especially troublesome if they are using a shared or public computer.
How we shrank our SESSIONS table:
It’s actually pretty easy. Find your SETTINGS.PHP file – probably located in your \sites\default directory and change those “2000000” (shown in our example above) to a smaller value (after you back it up!) This is how ours looked after we changed it:
Save the file back to your server, and the changes take effect immediately.
Now, users are logged out immediately when they close their browser and sessions are only saved for 45 minutes. After making this change, our sessions table went from having over 30,000 rows to only a few hundred.Shrink Your Drupal Sessions Table by Randy "Wilson" Brown