Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

How can I enable slow query logging?

Problem

You may need to test and review slow queries on a database. By default slow queries are not logged.

Solution

To enable slow query logging, add 'logslow' => 1  to the 'dboptions' array  array in config.php. This will cause queries over 1 one second (the '1' can be changed to any number of seconds) to be logged in the 'log_queries' table in the database.

Code Block
languagephp
titleExample
$CFG->dboptions = array (                                                                                                                                                                                      
  'dbpersist' => 0,
  'dbport' => '',
  'dbsocket' => '',
  'logslow' => 1
 ;

The 'log_queries' table  table can be exported and sent to Totara Support.

Most database administrations tools e.g. (such as MySQL Workbench, PHPMyAdmin, etc., ) have a graphical user interface for this. You can also do this from the command line on the server.I have included links to the MySQL, PostgreSQL and MSSQL documentation below and we will add this to our how-to article for logging slow queries.

MySQL
PostgreSQL
MSSQL

Note
Only enable slow query logging long enough to test slow queries and immediately disable after testing.