2

Today I saw my Magento database and in a few months, it went from a weight of 300MB to 2GB. I saw which of the tables was heavier and I saw that there is a 2GB SESSION table.

Why do the sessions are saved in the Database and not in a folder? Is it possible to clean the table without breaking the website? Is there any setting I can add to change the save into the DB?

Below an image. enter image description here

4 Answers 4

2
  • backup your database and files
  • open app/etc/env.php (changing session save from db to file)

    find

'session' => array ( 'save' => 'db', )

replace with

'session' => array ( 'save' => 'files', )

  • Just truncate the session table.
3
  • Hi, I've done since you wrote me the change to the env.php file but it continues to save the session in the DB. How does this happen? Why do not you create sessions like files?
    – Alessandro
    Commented Dec 30, 2018 at 18:30
  • Have you flushed cache? Commented Jan 1, 2019 at 13:26
  • Yes, i have reset all. Cache, static file etc.
    – Alessandro
    Commented Jan 2, 2019 at 18:50
1

The configuration can be found in:

app/etc/env.php

and can be changed by updating the session configuration to:

'session' =>
  array (
    'save' => 'files',
  ),

When you save it in sessions you can clear the session tables.

Normally the session files will be cleaned up through the cron but if you want to make sure old session files are removed add a crontask to the crontab like this example:

0 2 * * * flock -n ~/.cleanup-sessions.lock -c 'find /folder/to/your/magento/root/var/session -name '"'"'sess_*'"'"' -type f -mtime +1 -exec rm {} \;'
3
  • Hi, I've done since you wrote me the change to the env.php file but it continues to save the session in the DB. How does this happen? Why do not you create sessions like files?
    – Alessandro
    Commented Dec 27, 2018 at 9:54
  • @Alessandro Did you change the config and then flush the cache manually (rm -rf var/cache/*) and then truncated the table and now the files should be saved to the session folder. Depending on your server settings the session folder could be localt in a different location then the var/session folder in the magento root.
    – Mr. Lewis
    Commented Dec 31, 2018 at 11:26
  • I ran the rm command for the cache. But nothing the sessions continue to save in the DB that now has exceeded 2.8 gb. If I empty the Session table can something happen to the website?
    – Alessandro
    Commented Jan 2, 2019 at 18:57
0

Its possible that your php.ini or user.ini file has the session.save_handler directive set to db.

If you see a line that says: session.save_handler = db

Change it to: session.save_handler = files

Remember to restart PHP after making changes to *.ini files.

0

I would advise activating Memcache through these changes in your Magento root folder > app > etc > env.php.

From: 'session' => array ( 'save' => 'db', )

In: 'session' => array ('save' => 'memcached', 'save_path' => '127.0.0.1:11211'),

Then remove these files: rm -rf var/cache/* var/page_cache/* var/session/*

This will improve your website speed.

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.