Session table pruning

Hi there,

I have successfully configured to use mysql to save sessions data. I can see the data getting inserted in mysql. But I see the table keeps growing and it shows even those records whose expiry date is past. Wondering is there any configuration to prune the session table to remove records when the expiry date is past ?

Also I see it is growing super fast. I have deployed on our qa environment with ~7 users having access to the environment. In the last 7 days the records have reached around 850K, is this normal ?

Thanks,
K

Session lifetime should default to 24 hours. That sounds like a lot of data. Do you have a load balancer or something else that could be creating a lot of sessions?

Yes we have load balancer running behind grafana application. But I see the records staying in there forever, not getting deleted at all. Right now I can see records whose expiry date is June 2. I am looking for solution where the session info get deleted after certain time.

Just to check, have you changed the session_life_time or gc_interval_time config values?

What does the schema for the session table look like?

Any errors in the logs about garbage collecting sessions? (Should look something like session/mysql: error garbage collecting)

No I didnt change any configs.

mysql> describe session;
±-------±-----------------±-----±----±--------±------+
| Field | Type | Null | Key | Default | Extra |
±-------±-----------------±-----±----±--------±------+
| key | char(16) | NO | PRI | NULL | |
| data | blob | YES | | NULL | |
| expiry | int(11) unsigned | NO | | NULL | |
±-------±-----------------±-----±----±--------±------+

There are no errors in the logs.

The table schema looks right.

We use MySQL for session storage for Hosted Grafana so I’ve asked our team there to check if they have similar problems.

I will also try this out locally and see if I can recreate this. In the meantime, feel free to delete all expired sessions. This is the query that should be executed (86400 is 24 hours):

DELETE FROM session WHERE  expiry + 86400 <= UNIX_TIMESTAMP(NOW())

Thanks Daniellee. Please keep me updated.

HI Danielle… Did you get chance to check if your team are seeing issues on session table pruning on mysql ? Or did you try locally ?

I am still deleting the records manually

I tested locally with MySQL (I’ve been using it for the last two weeks). And it seems to work but it is not obvious when the cleanup occurs. It is part of the Macaron web framework that we use. I did ask our Hosted Grafana team but didn’t get a reply. I’ll check with them again later in the week (4th of July today so they are out of office).

@komal I got a reply and they said that their session table had only a handful of rows.

Can it be something to do with permissions for the mysql user?

Had a thought. Are you using HTTPS?

What setting do you have for the cookie_secure config setting?

Yes we are running grafana behind the loadbalancer which uses https. And cookie_secure is set to false. Ah… I see… it should be set to true, right ?

Yes, it might explain why so many sessions are being created.

@komal did that change fix the problem?