Surviving Connection Closures

When a database server reboots or a network failure has occurred, all connections in the database connection pool are broken. To overcome this issue, JIRA would normally need restarting (or for JIRA WAR distributions, the application server running JIRA would need restarting).

However, database connections in the database connection pool can be validated by running a simple SQL query. If a broken database connection is detected in the pool, a new one is created to replace it.

To do this, you need to specify an optional <validation-query/> element (in the dbconfig.xml file of your JIRA Home Directory), whose content is the query which validates connections in the database connection pool. See the following procedure for details.

Ensuring JIRA validates connections to its database

To ensure JIRA validates database connections in the database connection pool:

  1. Shut down JIRA (or the Tomcat installation running JIRA).
  2. Edit the dbconfig.xml file at the root of your JIRA Home Directory or use the Advanced tab of the JIRA Configuration Tool to configure the relevant settings.
  3. Configure the validation query for your type of database:
    • If editing the dbconfig.xml file, add the <validation-query/> element with the appropriate validation query for your type of database, as shown in the example below for MySQL. (See Determining the Validation Query below for details.)

      <?xml version="1.0" encoding="UTF-8"?>
       
      <jira-database-config>
        <name>defaultDS</name>
        <delegator-name>default</delegator-name>
        <database-type>mysql</database-type>
        <jdbc-datasource>
          <url>jdbc:mysql://dbserver:3306/jiradb?useUnicode=true&amp;characterEncoding=UTF8&amp;sessionVariables=storage_engine=InnoDB</url>
          <driver-class>com.mysql.jdbc.Driver</driver-class>
          <username>jiradbuser</username>
          <password>password</password>
          <pool-min-size>20</pool-min-size>
          <pool-max-size>20</pool-max-size>
          <pool-max-wait>30000</pool-max-wait>
       
          <validation-query>select 1</validation-query>
          <min-evictable-idle-time-millis>60000</min-evictable-idle-time-millis>
          <time-between-eviction-runs-millis>300000</time-between-eviction-runs-millis>
       
          <pool-max-idle>20</pool-max-idle>
          <pool-remove-abandoned>true</pool-remove-abandoned>
          <pool-remove-abandoned-timeout>300</pool-remove-abandoned-timeout>
       
          <pool-test-on-borrow>false</pool-test-on-borrow>
          <pool-test-while-idle>true</pool-test-while-idle>
          <validation-query-timeout>3</validation-query-timeout>
       
        </jdbc-datasource>
      </jira-database-config>
      
    • If using the JIRA Configuration Tool, on the Advanced tab, select the Validation Query check box and enter the appropriate validation query for your type of database. (See Determining the Validation Query below for details.)
  4. Specify a validation query timeout for your validation query, whose value is the appropriate length of time (in seconds) that the system should wait for a validation query to succeed before the system considers the database connection broken:
    • If editing the dbconfig.xml file, add the <validation-query-timeout/> element with the appropriate length of time (in seconds). (warning) This should only be done for MySQL.
    • If using the JIRA Configuration Tool, on the Advanced tab, select the Validation Query Timeout check box and enter the appropriate length of time (in seconds).
  5. You may wish to specify the following options, which relate to the above validation query options (see Tuning Database Connections - Connection pool settings section for details):

    JIRA Configuration Tool 'Advanced' tab option

    Element in dbconfig.xml

    Test While Idle pool-test-while-idle
    Time Between Eviction Runs time-between-eviction-runs-millis
    Minimum Evictable Idle Time min-evictable-idle-time-millis
  6. Save your edited dbconfig.xml file (or click the Save button if using the JIRA Configuration Tool).

  7. Restart JIRA (or the Tomcat installation running JIRA).

(info) Please Note: If you continue to have problems with connections closing, you may need to set the time-between-eviction-runs-millis parameter to a lower value or as a last resort, set test-on-borrow to true. For more information about test-on-borrow, see Tuning Database Connections - Connection pool settings section.

Determining the Validation Query and Timeout

Different database types have slightly different SQL syntax requirements for their validation query. The validation query should be as simple as possible, as this is run every time a connection is retrieved from the pool. The validation query timeout should only be set for MySQL.

The following validation queries are recommended for the following types of databases:

Database Type

Validation Query

Validation Query Timeout

MySQL

select 1

3

Microsoft SQL Server

select 1

N/A

Oracle

select 1 from dual

N/A 

PostgreSQL

select version();

N/A

(warning) If the Validation Query Timeout is used on any database other than MySQL it will cause significant problems with the JIRA instance.

Result

You should now be able to recover from a complete loss of all connections in the database connection pool without the need to restart JIRA or the application server running JIRA.

(warning) Performance Considerations:

  • Setting this option has a performance impact. The overall decrease in performance should be minimal, as the query itself is quick to run. In addition, the query will only execute when you make a connection. Thus, if the connection is kept for the duration of a request, the query will only occur once per request.
  • If you are running a large JIRA installation, you may wish to assess the performance impact of this change before implementing it.

Was this helpful?

Thanks for your feedback!

Why was this unhelpful?

Have a question about this article?

See questions about this article

Powered by Confluence and Scroll Viewport