Enabling MySQL slow query logs
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
Scenario
During performance troubleshooting, it can be helpful to know which queries are taking a long time to return a result. MySQL provides a way to log slow running queries that meet certain criteria. This option is disabled by default.
To avoid false positives, you should set the threshold for time to a value high enough that you won't capture query sent to the database, but just the long running ones. The default of 0.5 seconds should be enough to begin, however you may need to increment this upwards if you find too much noise in your slow query log file.
As this procedure requires a restart of MySQL (and thus a restart of your applications) you may wish to schedule some downtime for this to occur with minimal disruption to your user base.
Where is the MySQL Configuration file located?
The location of the MySQL configuration file (either my.cnf
or my.ini
depends on your operating system). MySQL will look at each location in order, and use the first file that it comes across. Often, if the file does not exist, it must be created first.
INSTALLDIR
refers to the location that MySQL was installed to.
Linux based systems
Windows based systems
Enabling Slow Query Profiling
Always back up your data before performing any modifications to the database. If possible, test any alter, insert, update, or delete SQL commands on a staging server first.
- Shut down your applications using MySQL
- Shut down MySQL itself
Add the following configuration options to
my.ini
/my.cnf
:# What's the threshold for a slow query to be logged? long_query_time=0.5 # Where should the queries be logged to? slow_query_log_file=/path/to/logfile # Enable slow query logging - note the dashes rather than underscores slow_query_log=1
- Save the file, and restart MySQL
- Restart your connected applications
Once you have the appropriate logs, follow the instructions at: Troubleshooting slow MySQL performance to analyze them.