8 Replies Latest reply on Jun 24, 2013 3:00 PM by sgilda

    How to add PostgreSql driver with pooled datasource in JBoss 7?

    breakpoint

      Hello

       

      I am moving from Glassfish 3.1.1 where I had a pooled datasource, not XA. I am trying to configure this in JBoss 7 and I am having difficulities.

      I have registered a PostgreSql module. In the standalone.xml file I am trying to add a new driver element inside the drivers element (only the example H2 driver is currently registered). I have looked at the XSD for datasources and I found that driver element can have a element named datasource-class. The example use xa-datasource-class, but that wouldn't be correct in my case would it since I don't won't XA datasource. Now after registering the driver and added a datasource, I go to the web console. Checking the standalone.xml file afterwards result in a closed postgresql driver element. It has automatically removed the datasource-class element.

       

      Could someone show an example of how to use PostgreSql pooled datasource in Jboss 7? And how to configure a basic datasource with it?

        • 1. Re: How to add PostgreSql driver with pooled datasource in JBoss 7?
          sfcoy

          Have a look at Install and Configure the PostgreSQL Database from the JBoss AS Quickstarts documentation.

          • 2. Re: How to add PostgreSql driver with pooled datasource in JBoss 7?
            breakpoint

            Ok, thanks. However, the article still doesn't show how to add a datasource for pooled connections. I was using this class on Glassfish: http://jdbc.postgresql.org/documentation/publicapi/org/postgresql/ds/PGConnectionPoolDataSource.html

            That isn't XA. Is it required on JBoss to use the XA datasource from PostgreSql since all tutorials/articles use that?

            • 3. Re: How to add PostgreSql driver with pooled datasource in JBoss 7?
              sfcoy

              A non-XA DataSource is always pooled in JBossAS/WildFly.

              This fragment shows a Postgresql datasource that  I've used in the past:

              {code:xml}<datasource jta="true" jndi-name="java:jboss/myDS" pool-name="MyDSPool" enabled="true" use-ccm="false">

                        <connection-url>jdbc:postgresql://localhost:5432/mydb</connection-url>

                        <driver-class>org.postgresql.Driver</driver-class>

                        <driver>postgresql91</driver>

                        <transaction-isolation>TRANSACTION_READ_COMMITTED</transaction-isolation>

                        <pool>

                           <min-pool-size>5</min-pool-size>

                           <max-pool-size>20</max-pool-size>

                        </pool>

                        <security>

                           <user-name>...</user-name>

                           <password>...</password>

                        </security>

                        <validation>

                           <validate-on-match>false</validate-on-match>

                           <background-validation>false</background-validation>

                        </validation>

                        <statement>

                           <share-prepared-statements>false</share-prepared-statements>

                        </statement>

              </datasource>{code}

              • 4. Re: How to add PostgreSql driver with pooled datasource in JBoss 7?
                breakpoint

                But doesn't this have a driver registration element like the XADatasource? I mean in the drivers element tag? I see you have the driver-class in the code you posted though. I don't get it, when are you supposed to use the drivers element, and the datasource-class element? From the XSD for datasource I found xa-datasource-class, datasource-class and driver-class.

                • 5. Re: How to add PostgreSql driver with pooled datasource in JBoss 7?
                  sfcoy

                  I think the driver-class element is actually redundant in this case, because it's specified by the META-INF/services/java.sql.driver file in the postgresql-nnn.jdbc4.jar.

                   

                  I also have the following "drivers" configured:

                  {code:xml}

                  <drivers>

                      <driver name="postgresql91" module="org.postgresql.jdbc">

                          <xa-datasource-class>org.postgresql.xa.PGXADataSource</xa-datasource-class>

                      </driver>

                  </drivers>

                  {code}

                  This is referenced by the "driver" element of the datasource.

                   

                  The datasource definition is not provided in the Quickstart article because it is embedded in the applications where needed. Note that my module name is different from the article too.

                  • 6. Re: How to add PostgreSql driver with pooled datasource in JBoss 7?
                    breakpoint

                    What do you mean by embedded in the application?

                    • 7. Re: How to add PostgreSql driver with pooled datasource in JBoss 7?
                      sfcoy

                      The sample apps sometimes contain a *-ds.xml file that defines the datasource.

                       

                      I'm not sure why as I think we're trying discourage people from doing it that way.

                      • 8. Re: How to add PostgreSql driver with pooled datasource in JBoss 7?
                        sgilda

                        The '*-ds.xml' files should only be used in a development environment. In a production environment, you need runtime management of your datasources, so you configure the datasources in the server configuration file using the management console or jboss-cli scripts.

                         

                        The quickstarts are meant to be somewhat self-contained. They provide the '*-ds.xml' files for ease of use and demonstration purposes only.