1

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

| improve this question | | | | |
1
  • 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.
| improve this answer | | | | |
  • 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 Dec 30 '18 at 18:30
  • Have you flushed cache? – Muhammad Ayaz Jan 1 '19 at 13:26
  • Yes, i have reset all. Cache, static file etc. – Alessandro Jan 2 '19 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 {} \;'
| improve this answer | | | | |
  • 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 Dec 27 '18 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 Dec 31 '18 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 Jan 2 '19 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.

| improve this answer | | | | |

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.