简体   繁体   中英

Keycloak + postgresql configuration

I tried to configure keycloak server with my postgresql db. After many tries with a lot of configs I decided to ask the question. I have the next configurations: module.xml which is located in keycloak/modules/org/postgresql/main Also in that directory I put jdbc-driver with name 'postgresql-42.2.16.jar'

<?xml version="1.0" ?>
<module xmlns="urn:jboss:module:1.1" name="org.postgresql">

<resources>
    <resource-root path="postgresql-42.2.16.jar"/>
</resources>

<dependencies>
    <module name="javax.api"/>
    <module name="javax.transaction.api"/>
</dependencies>
</module>

standalone.xml which is located in keycloak/standalone/configuration In that xml I configured

drivers:

<drivers>
    <driver name="postgresql" module="org.postgresql">
        <xa-datasource-class>org.postgresql.xa.PGXADataSource</xa-datasource-class>
    </driver>
    <driver name="h2" module="com.h2database.h2">
        <xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
    </driver>
</drivers>

datasources:

<datasources>
    <datasource jndi-name="java:jboss/datasources/KeycloakDS" pool-name="KeycloakDS" enabled="true" use-java-context="true">
        <connection-url>jdbc:postgres://192.168.99.100:5432/keycloak</connection-url>
        <driver>postgresql</driver>
        <pool>
            <max-pool-size>20</max-pool-size>
        </pool>
        <security>
            <user-name>keycloak</user-name>
            <password>password</password>
        </security>
    </datasource>
    <datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true" statistics-enabled="${wildfly.datasources.statistics-enabled:${wildfly.statistics-enabled:false}}">
         <connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE</connection-url>
         <driver>h2</driver>
         <security>
             <user-name>sa</user-name>
             <password>sa</password>
         </security>
    </datasource>
 
...
</datasources>

keycloak server config:

<subsystem xmlns="urn:jboss:domain:keycloak-server:1.1">
    <spi name="connectionsJpa">
        <provider name="default" enabled="true">
            <properties>
                <property name="dataSource" value="java:jboss/datasources/KeycloakDS"/>
                <property name="initializeEmpty" value="false"/>
                <property name="migrationStrategy" value="manual"/>
                <property name="migrationExport" value="${jboss.home.dir}/keycloak-database-update.sql"/>
            </properties>
        </provider>
    </spi>
</subsystem>

And when I'm trying to start my keycloak server I got the exception:

17:56:19,859 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) 
WFLYCTL0013: Operation ("add") failed - address: ([
("subsystem" => "datasources"),
("data-source" => "KeycloakDS")
]) - failure description: {
"WFLYCTL0412: Required services that are not installed:" => ["jboss.jdbc-driver.postgresql"],
"WFLYCTL0180: Services with missing/unavailable dependencies" => [
    "jboss.driver-demander.java:jboss/datasources/KeycloakDS is missing [jboss.jdbc- 
driver.postgresql]",
    "org.wildfly.data-source.KeycloakDS is missing [jboss.jdbc-driver.postgresql]"
]
}
17:56:19,860 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) 
WFLYCTL0013: Operation ("add") failed - address: ([
("subsystem" => "datasources"),
("data-source" => "KeycloakDS")
]) - failure description: {
"WFLYCTL0412: Required services that are not installed:" => [
    "jboss.jdbc-driver.postgresql",
    "jboss.jdbc-driver.postgresql"
],
"WFLYCTL0180: Services with missing/unavailable dependencies" => [
    "jboss.driver-demander.java:jboss/datasources/KeycloakDS is missing [jboss.jdbc- 
driver.postgresql]",
    "org.wildfly.data-source.KeycloakDS is missing [jboss.jdbc-driver.postgresql]",
    "org.wildfly.data-source.KeycloakDS is missing [jboss.jdbc-driver.postgresql]"
]
}

  

It's looks like I configured my datasource in wrong way, but I can't find the error. I checked this check list and it doesn't resolve my issue.

Could you please retry with the following connection string:

jdbc:postgresql://192.168.99.100:5432/keycloak

instead of

jdbc:postgres://192.168.99.100:5432/keycloak

Also, consider letting the SPI/connectionsJpa block at defaults (I believe in particular that initializeEmpty should be true) and I don't remember that I had to add/modify this block, so please double-check.

You may also disable or comment the ExampleDS (h2) dataSource.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM