Issue while Keycloak Version upgrade from V19.0.3 to V21.1.2

Hello Team,We are currently in the process of upgrading the version in one of our test environments from Keycloak V19.0.3 to V21.1.2. However, during the server startup, we are encountering the following error repeatedly, causing the pods to enter into an error crash mode. Could you please suggest a solution to resolve this issue?

024-01-29 14:50:04,471 INFO  [org.infinispan.CLUSTER] (keycloak-cache-init) ISPN000094: Received new cluster view for channel ISPN: [auth-provider-service-sandbox-keycloakx-0-123|0] (1) [auth-provider-service-sandbox-keycloakx-0-123]
2024-01-29 14:50:04,674 INFO  [org.infinispan.CLUSTER] (keycloak-cache-init) ISPN000079: Channel `ISPN` local address is `auth-provider-service-sandbox-keycloakx-0-123`, physical addresses are `[172.21.44.123:7800]`
2024-01-29 14:50:14,669 INFO  [org.keycloak.quarkus.runtime.storage.legacy.liquibase.QuarkusJpaUpdaterProvider] (main) Updating database. Using changelog META-INF/jpa-changelog-master.xml
2024-01-29 14:50:18,867 INFO  [org.infinispan.CLUSTER] (main) ISPN000080: Disconnecting JGroups channel `ISPN`
2024-01-29 14:50:19,275 ERROR [org.keycloak.quarkus.runtime.cli.ExecutionExceptionHandler] (main) ERROR: Failed to start server in (production) mode
2024-01-29 14:50:19,276 ERROR [org.keycloak.quarkus.runtime.cli.ExecutionExceptionHandler] (main) ERROR: Failed to update database
2024-01-29 14:50:19,277 ERROR [org.keycloak.quarkus.runtime.cli.ExecutionExceptionHandler] (main) ERROR: liquibase.exception.MigrationFailedException: Migration failed for changeset META-INF/jpa-changelog-21.1.0.xml::21.1.0-19404::keycloak:
     Reason: liquibase.exception.DatabaseException: ERROR: default for column "decision_strategy" cannot be cast automatically to type smallint [Failed SQL: (0) ALTER TABLE public.RESOURCE_SERVER_POLICY ALTER COLUMN DECISION_STRATEGY TYPE SMALLINT USING (DECISION_STRATEGY::SMALLINT)]
2024-01-29 14:50:19,278 ERROR [org.keycloak.quarkus.runtime.cli.ExecutionExceptionHandler] (main) ERROR: Migration failed for changeset META-INF/jpa-changelog-21.1.0.xml::21.1.0-19404::keycloak:
     Reason: liquibase.exception.DatabaseException: ERROR: default for column "decision_strategy" cannot be cast automatically to type smallint [Failed SQL: (0) ALTER TABLE public.RESOURCE_SERVER_POLICY ALTER COLUMN DECISION_STRATEGY TYPE SMALLINT USING (DECISION_STRATEGY::SMALLINT)]
2024-01-29 14:50:19,278 ERROR [org.keycloak.quarkus.runtime.cli.ExecutionExceptionHandler] (main) ERROR: ERROR: default for column "decision_strategy" cannot be cast automatically to type smallint [Failed SQL: (0) ALTER TABLE public.RESOURCE_SERVER_POLICY ALTER COLUMN DECISION_STRATEGY TYPE SMALLINT USING (DECISION_STRATEGY::SMALLINT)]
2024-01-29 14:50:19,279 ERROR [org.keycloak.quarkus.runtime.cli.ExecutionExceptionHandler] (main) ERROR: ERROR: default for column "decision_strategy" cannot be cast automatically to type smallint
2024-01-29 14:50:19,365 ERROR [org.keycloak.quarkus.runtime.cli.ExecutionExceptionHandler] (main) For more details run the same command passing the '--verbose' option. Also you can use '--help' to see the details about the usage of the particular command.

Can you check the values actually stored in that column? Maybe there’s a strange value there which prevents conversion to smallint ?

Hello @regilero ,
Thanks for getting back to me. We’re trying to upgrade Keycloak from version 19.0.3 to 21.1.2. We first went to version 20.0.5, which went smoothly. But when we try to go from 20.0.5 to 21.1.2, things break with an error related to a table. Even going directly from 19.0.5 to 21.1.2 gives the same error. It seems like it’s something to do with the database. Do you know if we’re missing a step or doing something wrong?

Any suggestion on this issue ?

Did you actually check if there was something too big for the conversion in that column in the database. The samlint conversion is failing because some values are too big. Did you check what values are problematic in this column?