question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

migration with postgres DB failed from 11.0.3 -> 12.0.0 or higher

See original GitHub issue

Describe the bug

try to update keycloak from 11.0.3 with an existing postgres 14.1 database to a newer version. keycloak and postgres run as container, setup with docker-compose. This is the relevant log:

keycloak_1  | 	at org.wildfly.extension.undertow@26.0.1.Final//org.wildfly.extension.undertow.deployment.UndertowDeploymentService$1.run(UndertowDeploymentService.java:87)
keycloak_1  | 	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
keycloak_1  | 	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
keycloak_1  | 	at org.jboss.threads@2.4.0.Final//org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
keycloak_1  | 	at org.jboss.threads@2.4.0.Final//org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1990)
keycloak_1  | 	at org.jboss.threads@2.4.0.Final//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1486)
keycloak_1  | 	at org.jboss.threads@2.4.0.Final//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1377)
keycloak_1  | 	at java.base/java.lang.Thread.run(Thread.java:829)
keycloak_1  | 	at org.jboss.threads@2.4.0.Final//org.jboss.threads.JBossThread.run(JBossThread.java:513)
keycloak_1  | Caused by: liquibase.exception.MigrationFailedException: Migration failed for change set META-INF/jpa-changelog-12.0.0.xml::12.1.0-add-realm-localization-table::keycloak:
keycloak_1  |      Reason: liquibase.exception.DatabaseException: ERROR: relation "realm_localizations" already exists [Failed SQL: CREATE TABLE public.REALM_LOCALIZATIONS (REALM_ID VARCHAR(255) NOT NULL, LOCALE VARCHAR(255) NOT NULL, TEXTS TEXT NOT NULL)]
keycloak_1  | 	at org.liquibase//liquibase.changelog.ChangeSet.execute(ChangeSet.java:619)
keycloak_1  | 	at org.liquibase//liquibase.changelog.visitor.UpdateVisitor.visit(UpdateVisitor.java:51)
keycloak_1  | 	at org.liquibase//liquibase.changelog.ChangeLogIterator.run(ChangeLogIterator.java:79)
keycloak_1  | 	at org.liquibase//liquibase.Liquibase.update(Liquibase.java:214)
keycloak_1  | 	at org.liquibase//liquibase.Liquibase.update(Liquibase.java:192)
keycloak_1  | 	at org.liquibase//liquibase.Liquibase.update(Liquibase.java:188)
keycloak_1  | 	at org.keycloak.keycloak-model-jpa@16.1.1//org.keycloak.connections.jpa.updater.liquibase.LiquibaseJpaUpdaterProvider.updateChangeSet(LiquibaseJpaUpdaterProvider.java:184)
keycloak_1  | 	at org.keycloak.keycloak-model-jpa@16.1.1//org.keycloak.connections.jpa.updater.liquibase.LiquibaseJpaUpdaterProvider.update(LiquibaseJpaUpdaterProvider.java:103)
keycloak_1  | 	... 65 more
keycloak_1  | Caused by: liquibase.exception.DatabaseException: ERROR: relation "realm_localizations" already exists [Failed SQL: CREATE TABLE public.REALM_LOCALIZATIONS (REALM_ID VARCHAR(255) NOT NULL, LOCALE VARCHAR(255) NOT NULL, TEXTS TEXT NOT NULL)]
keycloak_1  | 	at org.liquibase//liquibase.executor.jvm.JdbcExecutor$ExecuteStatementCallback.doInStatement(JdbcExecutor.java:309)
keycloak_1  | 	at org.liquibase//liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:55)
keycloak_1  | 	at org.liquibase//liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:113)
keycloak_1  | 	at org.liquibase//liquibase.database.AbstractJdbcDatabase.execute(AbstractJdbcDatabase.java:1277)
keycloak_1  | 	at org.liquibase//liquibase.database.AbstractJdbcDatabase.executeStatements(AbstractJdbcDatabase.java:1259)
keycloak_1  | 	at org.liquibase//liquibase.changelog.ChangeSet.execute(ChangeSet.java:582)
keycloak_1  | 	... 72 more
keycloak_1  | Caused by: org.postgresql.util.PSQLException: ERROR: relation "realm_localizations" already exists
keycloak_1  | 	at org.postgresql.jdbc@42.2.5//org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2440)
keycloak_1  | 	at org.postgresql.jdbc@42.2.5//org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2183)
keycloak_1  | 	at org.postgresql.jdbc@42.2.5//org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:308)
keycloak_1  | 	at org.postgresql.jdbc@42.2.5//org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:441)
keycloak_1  | 	at org.postgresql.jdbc@42.2.5//org.postgresql.jdbc.PgStatement.execute(PgStatement.java:365)
keycloak_1  | 	at org.postgresql.jdbc@42.2.5//org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:307)
keycloak_1  | 	at org.postgresql.jdbc@42.2.5//org.postgresql.jdbc.PgStatement.executeCachedSql(PgStatement.java:293)
keycloak_1  | 	at org.postgresql.jdbc@42.2.5//org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:270)
keycloak_1  | 	at org.postgresql.jdbc@42.2.5//org.postgresql.jdbc.PgStatement.execute(PgStatement.java:266)
keycloak_1  | 	at org.jboss.ironjacamar.jdbcadapters@1.5.3.Final//org.jboss.jca.adapters.jdbc.WrappedStatement.execute(WrappedStatement.java:198)
keycloak_1  | 	at org.liquibase//liquibase.executor.jvm.JdbcExecutor$ExecuteStatementCallback.doInStatement(JdbcExecutor.java:307)
keycloak_1  | 	... 77 more
keycloak_1  |
keycloak_1  | 11:46:36,688 INFO  [org.jboss.as.server] (Thread-1) WFLYSRV0220: Server shutdown has been requested via an OS signal
keycloak_1  | 11:46:36,724 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-2) WFLYJCA0010: Unbound data source [java:jboss/datasources/KeycloakDS]

Version

11.0.3

Expected behavior

database migration don’t fail and keycloak is running after update the docker tag

Actual behavior

keycloak don’t start.

keycloak_1  | 11:46:37,106 INFO  [org.infinispan.CLUSTER] (ServerService Thread Pool -- 59) ISPN000080: Disconnecting JGroups channel ejb
keycloak_1  | 11:46:37,121 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("add") failed - address: ([("subsystem" => "metrics")]): java.lang.NullPointerException
keycloak_1  | 	at org.wildfly.extension.metrics@26.0.1.Final//org.wildfly.extension.metrics.MetricsSubsystemAdd$2.execute(MetricsSubsystemAdd.java:91)
keycloak_1  | 	at org.jboss.as.controller@18.0.4.Final//org.jboss.as.controller.AbstractOperationContext.executeStep(AbstractOperationContext.java:1045)
keycloak_1  | 	at org.jboss.as.controller@18.0.4.Final//org.jboss.as.controller.AbstractOperationContext.processStages(AbstractOperationContext.java:777)
keycloak_1  | 	at org.jboss.as.controller@18.0.4.Final//org.jboss.as.controller.AbstractOperationContext.executeOperation(AbstractOperationContext.java:466)
keycloak_1  | 	at org.jboss.as.controller@18.0.4.Final//org.jboss.as.controller.OperationContextImpl.executeOperation(OperationContextImpl.java:1427)
keycloak_1  | 	at org.jboss.as.controller@18.0.4.Final//org.jboss.as.controller.ModelControllerImpl.boot(ModelControllerImpl.java:550)
keycloak_1  | 	at org.jboss.as.controller@18.0.4.Final//org.jboss.as.controller.AbstractControllerService.boot(AbstractControllerService.java:554)
keycloak_1  | 	at org.jboss.as.controller@18.0.4.Final//org.jboss.as.controller.AbstractControllerService.boot(AbstractControllerService.java:516)
keycloak_1  | 	at org.jboss.as.server@18.0.4.Final//org.jboss.as.server.ServerService.boot(ServerService.java:461)
keycloak_1  | 	at org.jboss.as.server@18.0.4.Final//org.jboss.as.server.ServerService.boot(ServerService.java:414)
keycloak_1  | 	at org.jboss.as.controller@18.0.4.Final//org.jboss.as.controller.AbstractControllerService$1.run(AbstractControllerService.java:455)
keycloak_1  | 	at java.base/java.lang.Thread.run(Thread.java:829)
keycloak_1  |
keycloak_1  | 11:46:37,126 ERROR [org.jboss.as.server] (ServerService Thread Pool -- 45) WFLYSRV0022: Deploy of deployment "keycloak-server.war" was rolled back with no failure message
keycloak_1  | 11:46:37,143 INFO  [org.jboss.as] (MSC service thread 1-2) WFLYSRV0050: Keycloak 16.1.1 (WildFly Core 18.0.4.Final) stopped in 452ms
keycloak_1  | kc_keycloak_1 exited with code 1

How to Reproduce?

this is the compose config file

version: '3'

volumes:
  postgres_data:
      driver: local

services:
  postgres:
    image: docker.io/postgres:14.1-alpine
    restart: always
    volumes:
      - postgres_data:/var/lib/postgresql/data
    environment:
      POSTGRES_DB: kc
      POSTGRES_USER: kc
      POSTGRES_PASSWORD: pw
  keycloak:
    image: docker.io/jboss/keycloak:16.1.1
    environment:
      DB_VENDOR: POSTGRES
      DB_ADDR: postgres
      DB_DATABASE: kc
      DB_USER: kc
      DB_SCHEMA: public
      DB_PASSWORD: pw
      KEYCLOAK_USER: admin
      KEYCLOAK_PASSWORD: pwkc
      PROXY_ADDRESS_FORWARDING: "true"
    ports:
      - 127.0.0.1:8080:8080
    depends_on:
      - postgres

Anything else?

No response

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
pfpuluxcommented, Apr 19, 2022

With the sequence

docker stop kc_postgres_1
docker rm kc_postgres_1
docker volume prune -f

docker-compose up -d postgres

and then restore the dump, the issue is gone.

1reaction
jerosacommented, Feb 9, 2022

Today I’ve tried again to upgrade the database but I’m not able to reproduce it again. I’m using docker-compose and redefining the standalone.xml file so maybe in my attempts I did something wrong or use the incorrect version of the file.

Sorry to not being able to help more. If I reproduce the issue I will look into that table and post it here.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Update to 11.0.3 failed · Issue #4504 · nextcloud/server - GitHub
It can be solved by manually changing the types on the indicated tables. Log in as postgres user into your database, then run...
Read more >
Documentation: 9.0: Migration Between Releases - PostgreSQL
Migration Between Releases. This section discusses how to migrate your database data from one PostgreSQL release to a newer one.
Read more >
Important Upgrade Notes - Mattermost Documentation
On MySQL, if you encounter an error “Failed to apply database migrations” when upgrading to v6.4.0, it means that there is a mismatch...
Read more >
Migrating your OpenProject installation to PostgreSQL 13
In the following, we assume that you initially let OpenProject setup your PostgreSQL installation, using a local database. NOTE: RedHat and CentOS are ......
Read more >
Postgres - FATAL: database files are incompatible with server
I checked the logs and the following line appears over and over again: FATAL: database files are incompatible with server DETAIL: The data...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found