How to connect to PostgreSQL using JNDI
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.
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.
Open $JIRA_INSTALL/conf/server.xml. Within the
Context
element, configure aResource
element oftype="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>