52893 TID использует 100% ЦП на моем сервере
Как найти запрос, соответствующий этому TID? Для меня, эта таблица пуста
ПОКАЗАТЬ ПОЛНЫЙ СПИСОК ПРОЦЕССОВ; может быть более полезным, если процесс еще выполняется. Будет указан полный запрос.
MySQL и MariaDB необязательно создают файл или таблицу «slowlog».
Настроить:
⚈ Set long_query_time = 1 -- Preferrable in my.cnf We may change that threshold up or down later, but this is a reasonable start.
⚈ Set up the slowlog to be captured to FILE.
⚈ Turn on (the details of this vary with the Version)
⚈ Wait at least 24 hours.
Запись slow_log в файл - это предпочтительно, так как есть инструменты для сжатия, такие как:
log_output = FILE
slow_query_log = ON
slow_query_log_file = (fullpath to some file)
long_query_time = 1
log_slow_admin_statements = ON
log_queries_not_using_indexes = OFF
Ноты:
⚈ log_output can be TABLE to write to mysql.slow_log, or FILE,TABLE to write both
⚈ slow_query_log_file has a default; is not needed for TABLE
⚈ long_query_time is a float, and can be as low as 0, but that gets verbose; default is a 'useless' 10
⚈ admin statements tend to be slow but infrequent
⚈ not_using_indexes is mostly clutter; simply worry about those that are slow
⚈ If running on a Slave, consider using log_slow_slave_statements
⚈ Beginning with 8.0.14, also have log_slow_extra = ON
Другие варианты (в зависимости от версии; неполный):
log_slow_rate_limit=100
log_slow_rate_type=query
log_slow_verbosity=full
slow_query_log_always_write_time=1
slow_query_log_use_global_control=all
innodb_monitor_enable=all
userstat=1
Соберите для меня результаты (желательно с помощью FILE):
⚈ Digest the results using either of these:
`pt-query-digest` -- from Percona.com
`mysqldumpslow -s t`
⚈ Grab the first few (perhaps 5) queries. They will be sorted by (frequency * avg-time), which is the most useful.
⚈ Provide SHOW CREATE TABLE -- for each table
⚈ Provide EXPLAIN SELECT ... -- for each query
Анализ результатов. Обычно (не всегда) я могу дать конкретное предложение по ускорению каждого запроса:
⚈ Add a particular index (often 'composite')
⚈ Reformulate the query (a simple case is not hiding an indexed column in a function; more complex involves adding/removing subqueries)
⚈ Recommend schema change
⚈ Possibly even an architectural change (EAV is a common problem)