Manual idle offline sessions clean

Hello there!

There is a Keycloak 15 instance with PostgreSQL.
When the amount of offline sessions reached 7million, auto idle session cleaning started working comparingly slow which caused slow updates on last_refresh_token column and it ended up with some periodic deadlocks.

It was decided to change Offline Session Idle from 3month to 2month, but before updating the realm settings, offline sessions older than 2month where delete manually.

The problem is that it was done without deletion of corresponding rows in offline_client_session. Now there is a bunch of rows in the table offline_client_session with user_session_id which doesn’t exist in offline_user_session.

Result of a left join select shows more rows than were deleted and I’m not sure what are they.

Please, help to understand what’s the difference between PersistentUserSessionEntity vs PersistentClientSessionEntity in this context and what’s the best solution?

Thanks!