# Manual idle offline sessions clean

**URL:** <https://forum.keycloak.org/t/manual-idle-offline-sessions-clean/20134>\
**Category:** Getting advice\
**Created:** [February 8, 2023, 11:30pm UTC](https://forum.keycloak.org/t/manual-idle-offline-sessions-clean/20134 "2023-02-08T23:30:28Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![terengb](https://avatars.discourse-cdn.com/v4/letter/t/d2c977/32.png) [@terengb](https://forum.keycloak.org/u/terengb)\
**Post date:** [February 8, 2023, 11:30pm UTC](https://forum.keycloak.org/t/manual-idle-offline-sessions-clean/20134/1 "2023-02-08T23:30:28Z")

</div>

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!
