Search code examples
postgresqljdbcdatasourcewebsphere-libertyfailover

How to enable failover for a postgresql jdbc data source


I have a data source defined in a Liberty application server for postgresql

<dataSource jdbcDriverRef="PostgreSQLDriver" ...>
  <properties password="..." user="admin" serverName="server" portNumber="2020" databaseName="dbname" ssl="false"
</dataSource>

I see that I can enable failover on a jdbc connection by specifying a url like:

jdbc:postgresql://host1:port,host2:port,host3:port/dbname

Is there any way that this failover url can be provided to a application server datasource?


Solution

  • Yes, you can specify any key/value pair on the <properties> element and Liberty will supply it to the vendor data source class. In this case, the property would be URL="jdbc:postgresql://host1:port,host2:port,host3:port/dbname"

    Also, note that in more recent versions of Liberty, there is a properties.postgresql which is specific to Postgres and better documents the available settings for it.

    Here is an example,

    <dataSource jdbcDriverRef="PostgreSQLDriver" ...>
      <properties.postgresql password="..." user="admin" URL="jdbc:postgresql://host1:port,host2:port,host3:port/dbname" ssl="false"
    </dataSource>