Unable to see Keycloak Tables in Postgres

  docker, keycloak, postgresql

Although I tell Keycloak to use Postgres and the initial log indicates that it is using Postgres, Postgres database is not receiving a keycloak schema or any data.

keycloak/Dockerfile

FROM jboss/keycloak:14.0.0

HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3 CMD curl --fail http://localhost:8080/auth/realms/master

EXPOSE ${KEYCLOAK_PORT}

CMD ["-b", "0.0.0.0"]

docker-compose

keycloak_db:
  image: postgres:13
  volumes:
    - keycloak_db_data:/var/lib/postgresql/data
  restart: always
  environment:
    POSTGRES_DB: ${KEYCLOAK_DB_DATABASE}
    POSTGRES_USER: ${KEYCLOAK_DB_USER}
    POSTGRES_PASSWORD: ${KEYCLOAK_DB_PASSWORD}
  ports:
    - ${KEYCLOAK_DB_PORT}:5432

keycloak:
  build:
    context: keycloak
    dockerfile: Dockerfile
  restart: always
  environment:
    KEYCLOAK_LOGLEVEL: INFO
    ROOT_LOGLEVEL: INFO
    DB_VENDOR: POSTGRES
    DB_SCHEMA: 'public'
    DB_ADDR: ${KEYCLOAK_DB_ADDR}
    DB_PORT: ${KEYCLOAK_DB_PORT}
    DB_DATABASE: ${KEYCLOAK_DB_DATABASE}
    DB_USER: ${KEYCLOAK_DB_USER}
    DB_PASSWORD: ${KEYCLOAK_DB_PASSWORD}
    KEYCLOAK_HOST: ${VITE_KEYCLOAK_HOST}
    KEYCLOAK_PORT: ${VITE_KEYCLOAK_PORT}
    KEYCLOAK_USER: ${KEYCLOAK_USER}
    KEYCLOAK_PASSWORD: ${KEYCLOAK_PASSWORD}
    KEYCLOAK_REALM: ${KEYCLOAK_REALM}
    KEYCLOAK_CLIENT: ${KEYCLOAK_CLIENT}
  ports:
    - ${VITE_KEYCLOAK_PORT}:8080
  depends_on:
    keycloak_db:
      condition: service_started
  command: -b 0.0.0.0

docker-compose.override.yml

keycloak:
  build:
    args:
      INSTALL_DEV: "true"
  volumes:
    - ${pwd}/logs:/opt/jboss/keycloak/standalone/log
  environment:
    KEYCLOAK_LOGLEVEL: DEBUG
    ROOT_LOGLEVEL: INFO
    JDBC_PARAMS: "useSSL=false"

keycloak log

keycloak_1  | Added 'admin' to '/opt/jboss/keycloak/standalone/configuration/keycloak-add-user.json', restart server to load user
keycloak_1  | -b 0.0.0.0
keycloak_1  | =========================================================================
keycloak_1  | 
keycloak_1  |   Using PostgreSQL database
keycloak_1  | 
keycloak_1  | =========================================================================

Later in the log it show H2 database is being used/mentioned.

keycloak_1  | [0m[0m18:14:36,051 INFO  [org.keycloak.connections.jpa.DefaultJpaConnectionProviderFactory] (ServerService Thread Pool -- 65) Database info: {databaseUrl=jdbc:h2:/opt/jboss/keycloak/standalone/data/keycloak, databaseUser=SA, databaseProduct=H2 1.4.197 (2018-03-18), databaseDriver=H2 JDBC Driver 1.4.197 (2018-03-18)}

I noticed this jboss – Unable to use postgres with keycloak – Stack Overflow

Is more required to connect to Postgres beyond specifying DB with Environment variables? For example, Keycloak docs mention hacking internal xml configs.

Source: Docker Questions

LEAVE A COMMENT