Postgresql – XA Connection for PostgreSQL in Weblogic

postgresqlweblogic

PostgreSQL supports XA Transactions. I need to use them in my WebLogic 12.1.3.0.0.

When I try to create a new generic datasource in the admin console for this I can select 'PostgreSQL' but in the very next page I am warned that this driver is not XA compatible.

I can provide the postgresql-9.1-902.jdbc4.jar which contains the XA driver: org.postgresql.xa.PGXADataSource.

But I did not find a place where I could configure WebLogic to use this.

I can configure the driver class name in the specific connection, so I tried that but then it can't find the class. If I place the jar in the lib dir, the class is found, but the connection fails. Also I'm unsure if WebLogic in this case would use the XA features of Postgres or not.

Best Answer

You can fix this by adding a new element to the file $WL_HOME/wlserver/server/lib/jdbcdrivers.xml

I am unsure about the "UrlHelperClassname" value, though.

  <Driver 
    Database="PostgreSQL - for XA"
    Vendor="PostgreSQL" 
    Type="Type 4"
    DatabaseVersion="9.1"
    ForXA="true"
    ClassName="org.postgresql.xa.PGXADataSource"
    URLHelperClassname="weblogic.jdbc.utils.PostgreSQLJDBC4DriverURLHelper"
    TestSql="SELECT 1">
        <Attribute Name="DbmsName" Required="true" InURL="false"/>
        <Attribute Name="DbmsHost" Required="true" InURL="true"/>
        <Attribute Name="DbmsPort" Required="true" InURL="true" DefaultValue="5432"/>
        <Attribute Name="DbmsUsername" Required="true" InURL="false"/>
        <Attribute Name="DbmsPassword" Required="true" InURL="false"/>
  </Driver>

Then you need to place the postgres jar into $WL_HOME/user_projects/domains/base_domain/lib/.

After restarting WebLogic you can select 'PostgreSQL - for XA' as the Database Type. You will have to enter

"databaseName=YOUR_DATABASE_NAME" in the properties area additional to user, though. Maybe that can be optimized, but this works basically and should urge WebLogic to use XA features.