Keycloak user session persistence

Viewed 1102

When I'm logged in, I dont see any active session in the database in the tables USER_SESSION and CLIENT_SESSION.

But at the same time, the active session is displayed in the Sessions tab in the Keycloak Admin Panel.

Where is this session stored: in memory? And if it is stored in memory, then how to make it stored in the database table?

1 Answers

https://www.keycloak.org/docs/latest/server_installation/#cache

In Keycloak we have the concept of authentication sessions. There is a separate Infinispan cache called authenticationSessions.

So correct. DB is not used for the sessions, also "in memory" is not used. Infinispan cache is used.

Of course nobody is stopping you to rewrite whole Keycloak caching to store sessions in the DB. But this will be quite big task. I would say there is a reason why devs have choosed Infinispan and not DB, so I wouldn't change it at all.

It is not clear, why you need to store sessions in the DB. If it is for the persistance, then Infinispan offers configuration for persistent store - e.g. you can use JDBC driver and save data into relational DB.

Related