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?

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().

  • Thanks for the response. What is this MySQL core_session update that is taking so long? Any idea why it's slow? @Fabian – Supplement Jul 8 '17 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. – Fabian Schmengler Jul 10 '17 at 6:36
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();
  • 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 Nov 21 '18 at 9:15
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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