2024-07-11
한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina
Locating slow queries is a key step in database optimization, especially for relational databases such as MySQL, PostgreSQL, etc. The following are the general steps to locate and optimize slow queries:
Most relational databases support slow query logging, which can help record SQL statements whose execution time exceeds a set threshold. First, you need to make sure that the slow query log is enabled.
existmy.cnf
ormy.ini
Add or modify the following lines in the configuration file:
[mysqld]
slow_query_log = 1
slow_query_log_file = /var/log/mysql/slow.log
long_query_time = 2