PostgreSQL database is not created using keycloak

Viewed 958

I need to create a new external PostgreSQL database to replace the default H2 database that Keycloak uses by default. When I create a database using the keycloak file, the database is not created when running Keycloak:

Caused by: org.postgresql.util.PSQLException: FATAL: database "sso" does not exist
    at org.postgresql.jdbc@42.2.5//org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2440)
    at org.postgresql.jdbc@42.2.5//org.postgresql.core.v3.QueryExecutorImpl.readStartupMessages(QueryExecutorImpl.java:2559)
    at org.postgresql.jdbc@42.2.5//org.postgresql.core.v3.QueryExecutorImpl.<init>(QueryExecutorImpl.java:133)
    at org.postgresql.jdbc@42.2.5//org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:250)
    at org.postgresql.jdbc@42.2.5//org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49)
    at org.postgresql.jdbc@42.2.5//org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:195)
    at org.postgresql.jdbc@42.2.5//org.postgresql.Driver.makeConnection(Driver.java:454)
    at org.postgresql.jdbc@42.2.5//org.postgresql.Driver.connect(Driver.java:256)
    at org.jboss.ironjacamar.jdbcadapters@1.4.22.Final//org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.createLocalManagedConnection(LocalManagedConnectionFactory.java:321)
    ... 57 more

When I am giving the application database as the value I am able to connect to the database. But my intention is to connect to a different database:

cat Keycloak 
    
CREATE DATABASE IF NOT EXISTS sso;

docker-compose.yaml 
    
    data-keycloak:
      image: jboss/keycloak:$KEYCLOAK_TAG
      container_name: data-keycloak-container
      ports:
        - "$KEYCLOAK_EXTERNAL_PORT:$KEYCLOAK_INTERNAL_PORT"
      depends_on:
        - data-keycloak-db
      environment:
        KEYCLOAK_USER: $KEYCLOAK_USER
        KEYCLOAK_PASSWORD: $KEYCLOAK_PASSWORD
        DB_VENDOR: $KEYCLOAK_DB_VENDOR
        DB_USER: $KEYCLOAK_DB_USER
        DB_PASSWORD: $KEYCLOAK_DB_PASSWORD
        DB_DATABASE: $KEYCLOAK_DB_DATABASE
        DB_ADDR: $KEYCLOAK_DB_ADDR
        DB_SCHEMA: public
        WAIT_HOSTS: data-keycloak-db:$data_KEYCLOAK_DB_PORT
        KEYCLOAK_IMPORT: /tmp/keycloak-realm.json
      volumes:
        - ./keycloak-realm.json:/tmp/keycloak-realm.json
        - ./keycloak:/tmp/keycloak
      networks:
        - $data_NETWORK
0 Answers
Related