1

I have roughly 35,500 rows of session data in this table. Is that a lot? Would this cause problems? How much is generally too much? Should i truncate it?

It seems to be a problem so I was thinking of truncating it.

New Relic is giving me a list of most time consuming mysql queries.

enter image description here

Thoughts?

3 Answers 3

6

The only reason to truncate this table is if you change the session storage so that you don't need the table anymore. That is, after migrating sessions to redis, files or whatever.

It's the equivalent of deleting var/session with file based sessions, which I explained here: keeping customers logged in after deleting var/session in magento

This will log out all your customers and delete the carts of guest customers. If you have visitors that might want to buy something, this is really bad for your business!

Instead, you can delete old sessions regulary, that is, rows with session_expires < NOW().

2
  • Thanks for the response. What is this MySQL core_session update that is taking so long? Any idea why it's slow? @Fabian
    – Head
    Commented Jul 8, 2017 at 18:25
  • The number of sessions are a factor, but also the numbers of concurrent users, if the update query is locking the table (should not be the case, but is possible, see stackoverflow.com/questions/23772793/…). Otherwise there is row locking, so multiple queries from the same user will lock each other. These are typically AJAX requests. Commented Jul 10, 2017 at 6:36
1

Why not remove session records older than some time e.g. 1 week. This way you keep recent login/sessions/carts.

DELETE FROM `session` WHERE session_expires < UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 1 week));

See disclaimer from Fabian This will log out all your customers and delete the carts of guest customers. If you have visitors that might want to buy something, this is really bad for your business!

Had a site with a 5GB session table. Come on Magento.

0

you can do it with a stored procedure and an event

#store procedure
DELIMITER //
CREATE PROCEDURE CleanSession()
BEGIN

DELETE FROM core_session WHERE session_expires < UNIX_TIMESTAMP()

END; //
DELIMITER ;


# event
CREATE EVENT CallCleanSession
    ON SCHEDULE EVERY 3 DAY
    DO
      CALL CleanSession();
1
  • Mixing application specific logic with logic in the DB sounds like a very bad idea. I would only use this if I were running a hosting company for a large number of ill-managed Magento's to help protect against server overload.
    – Wouter
    Commented Nov 21, 2018 at 9:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.