title: How to make keycloak sessions survive server restarts or upgrades?
body: <p>Keycloak configuration and data is stored in a relational database, which is usally persisted to the hard disk. This includes data like realm settings, users, group- and role-memberships, auth flows and so on. But the user sessions will only be stored in an ephemeral in-memory infinispan cache. Therefore the session data in this cache is lost, when the keycloak server restarts.</p>
  <p>There are many reasons why a restart of the Keycloak server is required. Major OS upgrades, Keycloak server upgrades to new versions, applying changes to keycloak e-mail templates or re-scheduling keycloak pods to other worker nodes in kubernetes or other cloud-based environments.</p>
  <p><strong>How to persist the session data to survive restarts. Ideally without having to maintain a custom infinspan server or using keycloak &quot;offline sessions&quot;.</strong></p>
  <hr />
  <p>One solution could be to simply use so-called keycloak <em>&quot;offline sessions&quot;</em>, but these sessions also have huge disadvantages:</p>
  <ul>
  <li>they remain valid, even if the user logs out</li>
  <li>logging out users with the keycloak admin console is no longer possible</li>
  </ul>
  <p>See: <a href="https://www.keycloak.org/docs/latest/server_admin/#_offline-access" rel="noreferrer">https://www.keycloak.org/docs/latest/server_admin/#_offline-access</a></p>
  <hr />
  <p><em>Will this problem still be present when keycloak &gt; 17 is out and uses the all new quarkus distribution?</em> Because in the following articles claim goals like <em>Container-First Approach</em>, <em>Zero-Downtime Upgrade</em> and <em>Storage re-architecture</em>.</p>
  <ul>
  <li><a href="https://www.keycloak.org/2021/10/keycloak-x-update" rel="noreferrer">https://www.keycloak.org/2021/10/keycloak-x-update</a></li>
  <li><a href="https://www.keycloak.org/2020/12/first-keycloak-x-release.adoc" rel="noreferrer">https://www.keycloak.org/2020/12/first-keycloak-x-release.adoc</a></li>
  </ul>