As Magento 2 has a large structure, so at certain point of time we came across a need to find out the queries which are taking more time than usual in order to optimize our store.
Slow query log is a place where database server stores queries which are taking more time than the given threshold.
There is a command in Magento 2 using which we can enable/disable logging slow queries.
//To enable logging
php bin/magento dev:query-log:enable
//To disable logging
php bin/magento dev:query-log:disable
The logs are generated in var/debug/db.log file. We can pass the threshold time using --query-time-threshold switch. We can see all the available switches using php bin/magento dev:query-log:enable --help command.
Thank you. Happy debugging ;)
Try this free module. https://github.com/Freento/sqllog.
It makes it simple to view and analyze queries from the admin, and you can set rules for specific pages, requests, or commands.