Can not write database session

Can not write database session

by T K -
Number of replies: 14
We are using Moodle 3.4, and last 6 mths my moodle login has been super slow. 

Today we were facing Can not write database session error and no one could login:

[Thu Jun 20 08:48:13.931815 2019] [:error] [pid 126630] [client 1.9.61.130:2914] Cannot obtain session lock for sid: xx, referer: xx
[Thu Jun 20 08:54:54.317362 2019] [:error] [pid 128045] [client 202.162.18.130:57559] Can not write database session - please verify max_allowed_packet is at least 4M!, referer: xx
[Thu Jun 20 08:54:55.183066 2019] [:error] [pid 128148] [client 203.115.247.114:9585] Can not write database session - please verify max_allowed_packet is at least 4M!, referer: xx
[Thu Jun 20 08:54:55.200976 2019] [:error] [pid 128059] [client 14.192.212.57:17783] Unknown exception when writing database session data : xx- Error writing to database, referer: xx

I even tried to increase the max_packet_allowed to 32M but still, login not successful.

I had read about the DB sessions and its problems, but always skeptical to make the change. And today after finding some previous discussions over this, I decided to add the following onto my config.php:

$CFG->dbsessions = false;


Immediately the login problem has resolved. But now, reading pros and cons of the file method, I am wondering what performance issues I should be monitoring?

Please advice.


Average of ratings: -
In reply to T K

Re: Can not write database session

by T K -
Also where is the session handling directory for file? i see no sessions in dataroot
In reply to T K

Re: Can not write database session

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
"please verify max_allowed_packet is at least 4M"

Did you?
In reply to Howard Miller

Re: Can not write database session

by T K -
as i mentioned, i did increase the max_allowed_packet, restarted the sql services and still faced the same problem. At the time of the problem, my max_allowed_packet was already set to 16M
In reply to T K

Re: Can not write database session

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Sorry - you did. Have you run out of disk space? Have you checked the logs for your database?
In reply to Howard Miller

Re: Can not write database session

by T K -
Diskspace is fine, and there are no logs of this incidence in the mysql logs, just the ssl_error.log as i shared above.
In reply to Howard Miller

Re: Can not write database session

by T K -
Howard, do you know where is the session handling directory for file? i see no sessions in dataroot
In reply to T K

Re: Can not write database session

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Well... have you enabled DB sessions or are there any other session-related settings in your config.php?
In reply to T K

Re: Can not write database session

by Ken Task -
Picture of Particularly helpful Moodlers

When switching to files for sessions, moodle should create a 'sessions' directory in moodledata.  If it is not there, manually create one and grant liberal permissions to it.

Also, the config.php line for sessions ... I've always used a '0' (zero) rather than a word.

Check via CLI ... in admin/cli/

php cfg.php |grep sessions

should return

dbsessions    0

'SoS', Ken

Average of ratings: Useful (1)
In reply to Ken Task

Re: Can not write database session

by T K -

Hi Ken,

It is really funny but i see no sessions directory in my moodledata directory, but my site is running fine on the file sessions mode

In reply to T K

Re: Can not write database session

by Sandy Bane -
What about support?
In reply to Sandy Bane

Re: Can not write database session

by T K -
What support?
In reply to T K

Re: Can not write database session

by Ken Task -
Picture of Particularly helpful Moodlers

'Support' in these forums are voluntaryNo one is paid to answer questions or make suggestions for issue resolutions.

Support is a two way street ... you are asked questions and suggestions might ask one to perform a command or a database query.

Earlier you posted that you have the following in your config.php file:

$CFG->dbsessions = false;

Shouldn't there be 'ticks' surrounding the value one is setting?   As I said before, I have always used '0' rather than a word.

You say you cannot find a 'sessions' directory in moodledata.

Have you checked your php.ini file for anything related to sessions?  php.ini files are usually fairly well commented.

How about ... as root user:

cd /

find / -name sessions [ENTER]

Although you say problem is resolved after adding the line to config.php.

'what performance issues I should be monitoring' ...

Since it involves logging in ... would say just observation if all accounts are manual and DB is localhost.

If authentications are not all manual and DB localhost then monitoring would have to be related to those.

Am sure there are several persons in this forums that would be happy to arrange with you a support contract.

Care to donate to my PayPal? smile

'SoS', Ken




Average of ratings: Useful (1)
In reply to Ken Task

Re: Can not write database session

by T K -
Correction, based on your previous replies on other discussions, i used this:

$CFG->dbsessions=0;

so i need '0' instead?

Pls let me know if there's a support contract, I can bring this forth to my company for our future use.

Thanks!
In reply to T K

Re: Can not write database session

by Ken Task -
Picture of Particularly helpful Moodlers

If you look at other config.php file lines, you should notice they all have ticks enclosing the values.

Contract ...

Could advertise you need help:

https://moodle.org/mod/data/view.php?d=54

or seek a Moodle Partner that provides remote support;

https://moodle.com/partners/

or ... if remotely hosted with provider, find providers FAQ's/Docs and in conjunction with other related Google searches, etc., learn.

A good resource: https://www.digitalocean.com/community/tutorials

'SoS', Ken