[keycloak-user] How to have multiple data sources?

Danny Trunk dt at zyres.com
Mon Feb 27 09:20:56 EST 2017


Hello,

I've followed the instructions from 
https://keycloak.gitbooks.io/server-installation-and-configuration/content/topics/database.html
But instead of changing the existing DS and provider, I simply added 
another one:

   <subsystem xmlns="urn:jboss:domain:datasources:4.0">
      <datasources>
        <datasource jndi-name="java:jboss/datasources/ExampleDS" 
pool-name="ExampleDS" enabled="true" use-java-context="true">
           ...
        </datasource>
        <datasource jndi-name="java:jboss/datasources/KeycloakDS" 
pool-name="KeycloakDS" enabled="true" use-java-context="true">
           ...
        </datasource>
        <datasource jndi-name="java:jboss/datasources/myproject" 
pool-name="myproject" enabled="true" use-java-context="true">
<connection-url>jdbc:postgresql://192.168.XX.XX/myproject</connection-url>
            <driver>postgresql</driver>
            <pool>
                <max-pool-size>20</max-pool-size>
            </pool>
            <security>
                <user-name>myproject</user-name>
                <password>password</password>
            </security>
        </datasource>
      </datasources>
   </subsystem>
   <subsystem xmlns="urn:jboss:domain:keycloak-server:1.1">
      ...
      <spi name="connectionsJpa">
         <provider name="default" enabled="true">
            ...
         </provider>
         <provider name="myproject" enabled="true">
             <properties>
                 <property name="dataSource" 
value="java:jboss/datasources/myproject"/>
                 <property name="initializeEmpty" value="false"/>
                 <property name="migrationStrategy" value="validate"/>
             </properties>
         </provider>
      </spi>
      ...
   </subsystem>

That's because I want to set the datasource per realm (If that's possible?).
Now I can't find this connection provider in the admin console. Only the 
default is listed in Server Info > Providers.

Server Version: 2.5.1.Final

By the way: This DS configuration is a mess. It would be much more user 
friendly to simply add a database provider and configure them through 
the admin console.


More information about the keycloak-user mailing list