Setting up lightweight validationQuery for MySQL

 

Platform notice: Server and Data Center only. This article only applies to Atlassian products on the Server and Data Center platforms.

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

Problem

To avoid the impact of creating a new database connection for each database access request made by Application (JIRA, Confluence, Stash), a pool of pre-established database connections is maintained. As part of this we need to make sure that connection inside the pool are validated. This needs to be done in order to prevent connections in pool to be broken, which may occur after database server reboots or a network failure. There is a lightweight validation query which can be used with MySQLConnector/J

The following appears in the tcpdump

17:36:54.292582 IP localhost.59437 > localhost.mysql: Flags [P.], seq 1272:1285, ack 846, win 522, options [nop,nop,TS val 311544791 ecr 311523797], length 13
......y.	....select 1

Diagnosis

Environment

  • Database MySQL, JDBC Mysql Connector/J >= 5.1.3

Cause

Using connection pool without validation query may lead to broken connection and application will not be able to survive connection closures. Using usual validation query like 'select 1' will create higher load on MySQL server as it needs to parse request. 

Resolution

Enable lightweight validation-query in the application database settings (please check relevant documentation for that).

To use this feature, specify a validation query in your connection pool that starts with /* ping */. Note that the syntax must be exactly as specified.

Configuration example for JIRA:

dbconfig.xml
    <validation-query>/* ping */ select 1</validation-query>    
    <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>

Related Content

Tuning Database Connections

http://dev.mysql.com/doc/connector-j/en/connector-j-usagenotes-j2ee-concepts-connection-pooling.html

Last modified on Mar 30, 2016

Was this helpful?

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