Want to get all Sql queries during the page load.
can any one help me on How to log all Magento 2 SQL queries ?
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.
Sign up to join this communityIn your app/etc/di.xml, replace the line:
<preference for="Magento\Framework\DB\LoggerInterface" type="Magento\Framework\DB\Logger\Quiet"/>
with
<preference for="Magento\Framework\DB\LoggerInterface" type="Magento\Framework\DB\Logger\File"/>
<type name="Magento\Framework\DB\Logger\File">
<arguments>
<argument name="logAllQueries" xsi:type="boolean">true</argument>
<argument name="debugFile" xsi:type="string">log/sql.log</argument>
</arguments>
</type>
Flush Magento cache (in backend, or by executing bin/magento cache:flush
) after this.
Log file is located here: var/log/sql.log
bin/magento dev:query-log:enable
. (copied my answer from Magento 2 log database queries)
var/debug/db.log
(not a file in var/log
)
Nov 7, 2019 at 16:31
Alternative (to the answer of Siju Joseph),
if you don't want to change your magento config, you can also configure mysql itself: activate slow.log and set it to 0 seconds.
Therefore edit /etc/mysql/my.cnf
and set slow_query_log
to 'on' and long_query_time
to '0'.
This will result in all mysql queries getting logged.