Database Logs

Most database systems provide logs that record query execution times. These logs can be a valuable source of information to identify slow queries. You can configure logging levels and output formats according to your database system.


-- Enable slow query logging in MySQL
SET GLOBAL slow_query_log = 'ON';
SET GLOBAL long_query_time = 1; -- Define the threshold (in seconds) for slow queries

-- View slow query log
SHOW VARIABLES LIKE 'slow_query_log%';
SHOW VARIABLES LIKE 'long_query_time';
SHOW VARIABLES LIKE 'slow_query_log_file';