Question

I enabled below variable in my.cnf:

log_slow_queries  = "/var/log/mysql/mysql-slow.log" 
long_query_time  = 2 
log-queries-not-using-indexes

and restarted the MySQL service. Then mysql-slow.log keeps recording 2 queries (both are small table with full scan, no index involved) repeatedly every 5 seconds. Both of the queries actually took less than 0.01 second. and the log file becomes bigger and bigger.

My server version: 5.5.31-0ubuntu0.12.04.1-log (Ubuntu).

I wonder how frequently the log file will do the writing job, even a redundant job? Can we control some other system variables to slow down this work? There are also some similar question, such as:

rotating mysql slow query log

Mysql slow query log is logging faster queries

Logging slow queries in MySQL

......

Can some experts explain it?

Thanks very much!

Was it helpful?

Solution

As per documentation on the slow query log, this is by design

The server uses the controlling parameters in the following order to determine whether to write a query to the slow query log:

  1. The query must either not be an administrative statement, or --log-slow-admin-statements must have been specified.

  2. The query must have taken at least long_query_time seconds, or log_queries_not_using_indexes must be enabled and the query used no indexes for row lookups.

  3. The query must have examined at least min_examined_row_limit rows.

Also, further explanation on what this variable setting does,

If you are using this option with the slow query log enabled, queries that are expected to retrieve all rows are logged. See Section 5.2.5, “The Slow Query Log”. This option does not necessarily mean that no index is used. For example, a query that uses a full index scan uses an index but would be logged because the index would not limit the number of rows.

The queries will be logged every time they fire, until they are modified to not match the behavior triggering their log. You can rotate the logs if you're concerned about diskspace, as suggested in one of the questions you linked. See this literature on logrotate and example configuration.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top