How to connect to PostgreSQL using JNDI

Platform Notice: Data Center - This article applies to Atlassian products on the Data Center platform.

Note that this knowledge base article was created for the Data Center version of the product. Data Center knowledge base articles for non-Data Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Except Fisheye and Crucible

The content on this page relates to platforms which are not supported for JIRA Applications. Consequently, Atlassian cannot guarantee providing any support for it. Please be aware that this material is provided for your information only and using it is done so at your own risk.

Purpose

While using JavaMelody to monitor JIRA, it may be required to provide the database connection using JNDI. This page describes how to connect JIRA to PostgreSQL using JNDI parameters.

(info) Please note that the JNDI parameters shown below such as maxActive are from Tomcat 7. In Tomcat 8+ , some of these have changed. For example, maxActive has been updated to maxTotal. For help with Tomcat 8 and above, please refer to the KB on JNDI database connection needs an upgrade to Jira 7.x or above.


Solution


This solution is based on Apache Tomcat documentation.


  1. Open $JIRA_INSTALL/conf/server.xml. Within the Context element, configure a Resource element of type="javax.sql.DataSource" as in the example below. Note that you need to copy only the first <Resource ... > from the following snippet:

    server.xml - <Resource ...>
                    <Context path="/jira" docBase="${catalina.home}/atlassian-jira" reloadable="false" useHttpOnly="true">
    					<!-- The following Resource is for JNDI -->
    					<Resource name="jdbc/jirads" auth="Container" type="javax.sql.DataSource"
                              username="database_user"
                              password="database_password"
                              driverClassName="org.postgresql.Driver"
                              url="jdbc:postgresql://localhost:5432/jira_database"
                              connectionProperties=""
                              maxActive="100"
                              maxWait="10000"
                              validationQuery="select version();"
                              removeAbandoned="true"
                              logAbandoned="true"
                              testWhileIdle="true"
                              timeBetweenEvictionRunsMillis="60000"
                              minEvictableIdleTimeMillis="300000"
                        />
                        <Resource name="UserTransaction" auth="Container" type="javax.transaction.UserTransaction" factory="org.objectweb.jotm.UserTransactionFactory" jotm.timeout="60"/>
                        <Manager pathname=""/>
                    </Context>
  • Configure the $JIRA_HOME/dbconfig.xml as follows:

    dbconfig.xml
    <jira-database-config>
      <name>defaultDS</name>
      <delegator-name>default</delegator-name>
      <database-type>postgres72</database-type>
      <schema-name>public</schema-name>
      <jndi-datasource>
        <jndi-name>java:comp/env/jdbc/jirads</jndi-name>
      </jndi-datasource>
    </jira-database-config>

Last modified on Mar 14, 2025

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.