How to connect to PostgreSQL using JNDI

Still need help?

The Atlassian Community is here for you.

Ask the community

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 Sep 8, 2022

Was this helpful?

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