Tuning database connections

Jira uses the database connection pool (DBCP) based on Apache Commons DBCP to manage Jira's access to its underlying database.

In earlier Jira versions, the database connection pool was handled purely through the Apache Tomcat application server running Jira.

From Jira version 4.4, Jira's dbconfig.xml file provides a set of database connection pool settings to Tomcat, which in turn are used by Tomcat to manage Jira's database connection pool.

From JIRA version 5.1, the number of database connection pool settings defined in Jira's dbconfig.xml file has substantially increased.

The information on this page can help you tweak Jira's database connection pool settings. You can do this by using the Jira configuration tool or by directly editing Jira's dbconfig.xml file, as described in the following sections.

The  Advanced tab of the Jira  Configuration Tool makes it easier to both configure and control Jira's database connection pool. The Database monitoring  page (accessible to Jira  system administrators) provides a visual tool for monitoring Jira 's database connection usage.

On this page:

Connection pool architecture

Whenever Jira needs to access (read from or write to) its database, a database connection is required.

A database connection is a large and complex object that handles all communication between Jira and its database. As such, database connections are time-consuming to establish and consume a significant amount of memory on both the client (the Jira application) and the database server.

To avoid the impact of creating a new database connection for each Jira's database access request, a pool of pre-established database connections is maintained. Each new database access request made by Jira uses a connection from this pool of pre-established connections, as required. This results in the following:

  1. When Jira starts up, a minimum number of database connections are established in the pool between Jira and its database.
  2. When Jira needs to access its database, it:
    1. requests a database connection from the pool
    2. uses this database connection to read from and/or write to its database
    3. returns the database connection to the pool when finished

If the frequency of Jira's database access requests begins to exceed the number of available database connections in the pool, extra connections are automatically created to handle the load.

Conversely, if the frequency of Jira's database access requests begins to drop below the number of available database connections in the pool, connections can be automatically closed to release resources back to the system.

Modern databases can handle hundreds of connections relatively easily and with sufficient memory. On the client side, however, these connections can consume a significant amount of memory. Hence, it is generally best to limit the number of connections to a much smaller number while having a sufficient number for the application so that it doesn't wait for a connection when it needs one.

Tuning Jira's database connections

  1. Shut down your Jira installation.
  2. Proceed with one of the following options:

Use Jira configuration tool to start Jira 's database connections

  1. Start the Jira  configuration tool:

    You may need to set the JAVA_HOME environment variable to run the Jira  configuration tool. See Installing Java  for details.
  2. Once the Jira configuration tool is running, select the Advanced tab.
    Jira configuration tool.
  3. Refer to the Connection pool settings for more information about the options on this tab. To specify a value for one of these options, ensure that its leftmost checkbox has been selected first.

    Some options on the preceding screenshot are simple checkboxes. Selecting these checkboxes sets the values of their associated options to "true". Conversely, clearing these checkboxes sets the values of their associated options to "false".

  4. Save your changes. They will be stored as elements in your dbconfig.xml file.

Editing the dbconfig.xml file to start Jira 's database connections

Edit the dbconfig.xml file at the root of your Jira home directory:

  1. Refer to the Connection pool settings  for more information about the elements you can add to your  dbconfig.xml file to fine-tune Jira 's database connection.
  2. Save your edited dbconfig.xml file.
  3. Restart your Jira installation.

DBCP settings

  • The default values of the settings will be written to the dbconfig.xml file after one of the following takes place:
    • You’ve run the Jira setup wizard.
    • You’ve used the  Advanced  tab of the Jira configuration tool to configure your database connection, even if you haven’t selected any leftmost checkbox for any option.
  • If you see the note “when not specified in dbconfig.xml” for the default value of the setting, it means one of the following: 
    • The related element wasn’t written to the dbconfig.xml file after you’ve run the  Jira setup wizard .
    • The related element was written to the dbconfig.xml file in one of the following ways:
      • Manually by the accountable user
      • According to the options on the Advanced  tab specified by selecting their leftmost checkboxes and setting values for these options.
  • If you see the note “when not specified in dbconfig.xml” for the default value of the setting, the system will consider this value even though it may be not present in your dbconfig.xml file.

The following table features all connection pool settings and their configuration.

Jira configuration tool "Advanced" tab option

Element in dbconfig.xml

Explanation 

Recommendations / Notes

Default value*

Maximum Size

pool-max-size

The maximum number of database connections that can be open at any time.

This value should be sufficiently large enough that Jira rarely needs to wait for a database connection to become available when Jira requires one.

See the Monitoring the connection pool section for suggestions on how to set this parameter.

20

Maximum Idle

pool-max-idle

The maximum number of database connections that are allowed to remain idle in the pool.

Specifying a negative number sets no limit on the number of database connections that can remain idle.

If the value of Minimum Idle/Size (see the following setting) is the same as that of Maximum Size (the previous setting), which is the case by default, then this setting has no effect.

Value of Maximum Size

Minimum Idle/Size

pool-min-size

(min-idle)

The minimum number of idle database connections that are kept open at any time.

Having this value set to that of Maximum Size (the previous setting), which is the case by default, means the pool will always have a fixed number of connections and idle connections will never be closed.

On very large Jira installations, there may be some benefit in specifying a lower value for this setting than that of Maximum Size to conserve resources.

Value of Maximum Size

Initial Size

pool-initial-size

The initial number of database connections opened in the pool.

This setting is not usually configured (other than the default value of 0), since a number of database connections are quickly created when Jira starts up.

0
(when not specified in dbconfig.xml)

Maximum Wait Time

pool-max-wait

The length of time (in milliseconds) that Jira is allowed to wait for a database connection to become available (while there are no free ones available in the pool), before returning an error.

Specifying a value of "-1" means that Tomcat will wait indefinitely.

You should specify a time here which is long enough to allow for any contention spikes, but short enough that users will receive a meaningful error rather than just getting no response or a browser timeout.

30000

Advanced settings

Generally, changing the following settings isn't required. Refer to the Apache DBCP documentation if necessary.

Pool Statements

pool-prepared-statements

Enable the pooling of prepared statements for the database connection pool.

Do not amend the default value of false, as it will cause exceptions. For more information, see JRA-44908 - Getting issue details... STATUS

false
(when not specified in dbconfig.xml)

Maximum Open Statements

max-open-prepared-statements

The maximum number of open statements that can be allocated from the statement pool at the same time.

Do not amend the default value as it will cause exceptions.

0
(when not specified in dbconfig.xml)

Validation Query

validation-query

The SQL query that will be used to validate connections from this pool. If specified, this query MUST be an SQL SELECT statement that returns at least one row.

See Surviving connection closures for more information.

select 1
(for MySQL)

(otherwise, not specified in dbconfig.xml)

Validation Query Timeout

validation-query-timeout

The length of time (in seconds) that the system should wait for a validation query to succeed before it considers the database connection broken.

The length of time should be quite short as the validation query should be designed to do a minimum amount of work.

If you specify a Validation Query above, then you should specify a value for the Validation Query Timeout too. If not, a value of "-1" is assumed, which results in the system waiting indefinitely until a validation query succeeds against a broken database connection, which it never will.

This should only be done for MySQL. Using a Validation Query Timeout on any database other than MySQL will cause significant problems with the Jira instance.

3
(for MySQL)

(otherwise, not specified in dbconfig.xml)

Test On Borrow

pool-test-on-borrow

Tests if the database connection is valid when it is borrowed from the database connection pool by Jira.

If the database connection is broken, it is removed from the pool.

This value should always be "false" as Jira borrows a connection for each database operation.

tip/resting Created with Sketch.

If you continue to have problems with database connections closing, try setting this option to "true". However, this should only be used as a last resort and only in the event that decreasing the value of Time Between Eviction Runs has not reduced or prevented problems with database connections closing.

 

True (when not specified in  dbconfig.xml ) , however this does not take effect unless a Validation Query has been explicitly specified, except f or MySQL, which has a default Validation Query, and it will therefore have an effect.

Test On Return

pool-test-on-return

Tests if the database connection is valid when it is returned to the database connection pool by Jira.

If the database connection is broken, it is removed from the pool.

This value should always be "false" as Jira returns borrowed connections for each database operation.

false
(when not specified in dbconfig.xml)

Test While Idle

pool-test-while-idle

Periodically tests if the database connection is valid when it is idle.

If the database connection is broken, it is removed from the pool.

This should be set to "true" for MySQL.

By default, MySQL database servers close database connections if they are not used for an extended period of time. This causes problems with Jira installations (which use MySQL databases) that are largely inactive for long periods, for example overnight. Setting this to "true" will work around this behavior.

Test While Idle only needs to be specified if you have specified a Validation Query above.

true
(for MySQL)

false
(when not specified in dbconfig.xml)

Time Between Eviction Runs

time-between-eviction-runs-millis

The number of milliseconds to sleep between runs of the idle object eviction thread. When non-positive, no idle object eviction thread will be run.

The eviction thread will remove idle database connections when the number of idle connections exceeds Minimum Idle/Size (above).

This should be set to a positive but largish value for MySQL so the evictor runs and tests connections. A reasonable value would be 300000 (5 minutes).

tip/resting Created with Sketch.

If you continue to have problems with database connections closing, try setting this option to a lower value.

 

300000
(for MySQL)

5000
(for HSQLDB)

(otherwise, not specified in dbconfig.xml)

Minimum Evictable Idle Time

min-evictable-idle-time-millis

The minimum amount of time an object may sit idle in the database connection pool before it is eligible for eviction by the idle object eviction (if any).


60000
(for MySQL)

4000
(for HSQLDB)

(otherwise, not specified in dbconfig.xml)

Remove Abandoned

pool-remove-abandoned

Flag to remove abandoned database connections if they exceed the Removed Abandoned Timeout (below).

If an internal failure occurs, it is possible that Jira may borrow a connection and never return it. If this happens too often, then the pool may run short of database connections, causing Jira's performance to degrade or Jira to fail altogether.

This value should be set to "true".

This will allow the pool to recover any abandoned connections and prevent this from affecting system performance.

true

Remove Abandoned Timeout

pool-remove-abandoned-timeout

The length of time (in seconds) that a database connection can be idle before it is considered abandoned.


300

Monitoring the connection pool

Jira provides a view of its database connection usage via the Database Monitoring page. See Monitoring database connection usage for more information.

Last modified on May 25, 2022

Was this helpful?

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