Working with JNDI

Applications such as GeoServer are in position to work with database connection pools set up by the application server. The Java Naming and Directory Interface (JNDI) can be used to create a connection pool for a JDBC data source.

These instructions will set up a JNDI connection pool on the Tomcat application server using a PostgreSQL data source:

  1. Copy the JDBC Driver for your database to <$TOMCAT_HOME>/lib (typically /usr/share/tomcat8/lib/). The JDBC driver can often be found on the website of your DBMS provider, or in the installed version of your database.


    The PostgreSQL JDBC Driver can be found at the PostgreSQL web site or in the geoserver/WEB-INF/lib directory.

  2. Remove the JDBC Driver from the WEB-INF/lib directory (typically /opt/boundless/suite/geoserver/WEB-INF/lib) inside the GeoServer webapps directory. It should be named postgresql-X.X-XXX.jdbc3.jar.

  3. Register the connection pool with the Tomcat Java Naming and Directory Interface (JNDI). This is done by adding a <Resource\> entry to the $TOMCAT_HOME/conf/context.xml (typically /etc/tomcat8/context.xml) configuration file. For example, given a PostgreSQL database named test with a user name and password of admin, the configuration would look like this:

      <Resource name="jdbc/postgres" auth="Container" type="javax.sql.DataSource"
                username="admin" password="admin"
                maxActive="20" maxIdle="10" maxWait="-1"/>


    For more information about the possible parameters and their values refer to the DBCP documentation.

  4. When adding a store in GeoServer, select the JNDI option. Enter the following information:

    • The jndiReferenceName used by the application server.
    • The schema used by the database.

    Using the configuration example above, the jndiReferenceName would be java:comp/env/jdbc/postgres.

For more information, including how to configure JNDI for Oracle and SQL Server data sources, see the GeoServer user manual.