Forums / General Questions / Sessions Table HUGE, bringing down site 1.5.1

Sessions Table HUGE, bringing down site 1.5.1

Views: 1,071

Results 1 to 5 of 5
25 Apr 2016, 4:28 PM
#1
sbbemn avatar

sbbemn

Zen Follower

Join Date:
Jan 2010
Posts:
182
Plugin Contributions:
0

Sessions Table HUGE, bringing down site 1.5.1

After getting disk cache going via file, our session table is growing to the point I have to truncate it every hour... with active carts going.

Not sure why it's growing, I thought 1.5+ already takes care of old sessions.

I tried a script to alleviate the strain on the server by running

mysql> DELETE FROM sessions WHERE expiry < (UNIX_TIMESTAMP() - 30 * 60);
Query OK, 0 rows affected (36.59 sec)

Although it did not clean the table up. Any suggestions?

25 Apr 2016, 7:55 PM
#2
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Sessions Table HUGE, bringing down site 1.5.1

Well, there is a function in ZC that takes an unused parameter that deletes sessions based on the current time. It appears that it uses the current time compared to the expiry time rather than a time offset like used above. In fact the 0 results provided there almost seem to indicate that the sessions ARE being deleted like they should be, but the rate of database access is out running the ability to maintain...

The function to which I refer is: _sess_gc($maxlifetime)

Pass any value as the $maxlifetime as it is not used inside the function. Not sure if upgrading would also solve your problem(s). Could also use the files instead of database.

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

25 Apr 2016, 7:58 PM
#3
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Sessions Table HUGE, bringing down site 1.5.1

Another question would be what kind of traffic is this database seeing? Is it shared among multiple stores? Might want to provide other server specs to try to help identify potential solutions.

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

25 Apr 2016, 9:12 PM
#4
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,515
Plugin Contributions:
176

Re: Sessions Table HUGE, bringing down site 1.5.1

You say the table is "HUGE".

Can you give some more context ... like how big is "HUGE" in your mind?
And, why do you believe you need to "truncate it every hour"? Why exactly are you doing that? What business "problem" is that attempting to solve?

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

21 Dec 2025, 12:03 PM
#5
torvista avatar

torvista

Totally Zenned

Join Date:
Aug 2007
Location:
Gijón, Asturias, Spain
Posts:
2,876
Plugin Contributions:
7

Re: Sessions Table HUGE, bringing down site 1.5.1

ZC2.2.0alpha in production...I see that my sessions table is 660MB with 200,500+ rows!
When restored locally it's 1GB.

I've truncated that today...see what happens.

Steve
github.com/torvista: BackupMySQL, Structured Data, Multiple Copy-Move-Delete, Google reCaptcha, Image Checker, Spanish Language Pack and more...