Migrate(backup and restore) data from the default IAM database (H2) while upgrading keycloak with latest non-vulnerable H2 Db
search cancel

Migrate(backup and restore) data from the default IAM database (H2) while upgrading keycloak with latest non-vulnerable H2 Db

book

Article ID: 230862

calendar_today

Updated On: 03-12-2025

Products

Service Virtualization

Issue/Introduction

In-place Upgrade DevTest 10.5 to 10.7.

10.5 IAM was running fine before the upgrade. After the upgrade, service is not starting and showing these errors ith following log.

Caused by: org.h2.jdbc.JdbcSQLNonTransientException: General error: "java.lang.IllegalStateException: Unable to read the page at position 77126892457453009 [1.4.200/6]" [50000-200]
                at org.h2.message.DbException.getJdbcSQLException(DbException.java:505)
                at org.h2.message.DbException.getJdbcSQLException(DbException.java:429)
                at org.h2.message.DbException.get(DbException.java:194)
         
2021-12-10 14:23:39,452 FATAL [org.keycloak.services] (ServerService Thread Pool -- 65) Error during startup: java.lang.RuntimeException: Failed to connect to database
                at org.keycloak.connections.jpa.DefaultJpaConnectionProviderFactory.getConnection(DefaultJpaConnectionProviderFactory.java:391)
                at org.keycloak.connections.jpa.updater.liquibase.lock.LiquibaseDBLockProvider.lazyInit(LiquibaseDBLockProvider.java:65)
              
                at org.jboss.jca.core.connectionmanager.pool.AbstractPool.getSimpleConnection(AbstractPool.java:632)
                at org.jboss.jca.core.connectionmanager.pool.AbstractPool.getConnection(AbstractPool.java:604)
                at org.jboss.jca.core.connectionmanager.AbstractConnectionManager.getManagedConnection(AbstractConnectionManager.java:624)
                ... 50 more
          
Caused by: java.lang.IllegalStateException: Unsupported type 17 [1.4.200/3]
                at org.h2.mvstore.DataUtils.newIllegalStateException(DataUtils.java:950)
                at org.h2.mvstore.type.ObjectDataType.newType(ObjectDataType.java:165)
                at org.h2.mvstore.type.ObjectDataType.read(ObjectDataType.java:229)
                at org.h2.mvstore.type.ObjectDataType.read(ObjectDataType.java:114)
                at org.h2.mvstore.Page.read(Page.java:605)
                at org.h2.mvstore.Page.read(Page.java:239)
                at org.h2.mvstore.MVStore.readPage(MVStore.java:2211)
                ... 78 more
 

2021-12-10 14:23:39,452 INFO  [org.jboss.resteasy.resteasy_jaxrs.i18n] (ServerService Thread Pool -- 65) RESTEASY002225: Deploying javax.ws.rs.core.Application: class org.keycloak.services.resources.KeycloakApplication

2021-12-10 14:23:39,452 INFO  [org.jboss.as.server] (Thread-2) WFLYSRV0220: Server shutdown has been requested via an OS signal

2021-12-10 14:23:39,452 INFO  [org.jboss.resteasy.resteasy_jaxrs.i18n] (ServerService Thread Pool -- 65) RESTEASY002200: Adding class resource org.keycloak.services.resources.JsResource from Application class org.keycloak.services.resources.KeycloakApplication

2021-12-10 14:23:39,468 INFO  [org.jboss.resteasy.resteasy_jaxrs.i18n] (ServerService Thread Pool -- 65) RESTEASY002205: Adding provider class org.keycloak.services.filters.KeycloakSecurityHeadersFilter from Application class org.keycloak.services.resources.KeycloakApplication

2021-12-10 14:23:39,968 ERROR [org.jboss.as.server] (ServerService Thread Pool -- 43) WFLYSRV0022: Deploy of deployment "keycloak-server.war" was rolled back with no failure message

2021-12-10 14:23:40,015 INFO  [org.jboss.as] (MSC service thread 1-5) WFLYSRV0050: Keycloak 15.0.0 (WildFly Core 15.0.1.Final) stopped in 554ms

 

Environment

All supported DevTest releases.

Cause

H2 database was corrupted during the migration

Resolution

Please see attached files for migration.

For Windows:

1: Default database H2 of IdentityAccessManager has to be upgraded. If we don’t have any data to take the backup, just go to the location <LISA_HOME>/IdentityAccessManager/standalone/data and delete keycloak.mv database file from this folder. Which will further be created while starting the server after the upgrade.

2: Before upgrading, module folder, to keep a backup of default database H2 of IdentityAccessManager follows these steps:

  • Copy h2db_backup windows command script file from the “h2dbupgrade-windows.zip” to the location <LISA_HOME>/IdentityAccessManager/standalone/data and run it by double click, it will create keycloak.sql file having a backup of the current database.
  • Take backup and delete keycloak.mv database file from this folder. Which will further be created while restoring the database after upgrade. 

3: After upgrading, module folder, to restore the backup of default database H2 of IdentityAccessManager follow these steps:

  • Copy h2db_restore windows command script file from the “h2dbupgrade-windows.zip” to the location <LISA_HOME>/IdentityAccessManager/standalone/data and run it by double click, it will create keycloak,mv database file and restore existing data backup from keycloak.sql file.
  • Take backup and delete h2db_backup, h2db_restore, and keycloak.sql files from this folder.

For Non-Windows:

1: Default database H2 of IdentityAccessManager has to be upgraded. If we don’t have any data to take the backup, just go to the location <LISA_HOME>/IdentityAccessManager/standalone/data and delete keycloak.mv database file from this folder. Which will further be created while starting the server after the upgrade.

2: Before upgrading, module folder, to keep a backup of default database H2 of IdentityAccessManager follows these steps:

  • Copy h2db_backup shell script file from the “h2dbupgrade-nonwindows.zip” to the location <LISA_HOME>/IdentityAccessManager/standalone/data and run it from the terminal at this location(Execution permission must be granted), it will create a keycloak.sql file having a backup of the current database. User can now delete keycloak.mv database file from this folder.

3: After upgrading, module folder, to restore the backup of default database H2 of IdentityAccessManager follow these steps:

  • Copy h2db_restore shell script file from the “h2dbupgrade-nonwindows.zip” to the location <LISA_HOME>/IdentityAccessManager/standalone/data and run it from the terminal at this location(Execution permission must be granted), it will create keycloak.mv database file and restore existing data backup from keycloak.sql file.
  • Take backup and delete h2db_backup, h2db_restore, and keycloak.sql files from this folder.

 

Attachments

h2dbupgrade-nonwindows_1639759915001.zip get_app
h2dbupgrade-windows_1639759898249.zip get_app