Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
54 views

How To Log All Magento SQL

This document discusses three methods for logging all SQL queries in Magento: 1) Using the Neon Profile SQL tool which logs queries by acting as a SQL proxy. 2) Editing the lib/Varien/Db/Adapter/Pdo/Mysql.php file to enable native Magento logging to the var/debug/pdo_mysql.log file. 3) Activating the Zend SQL profiler in the local.xml file to access detailed query profiling information programmatically.

Uploaded by

Santosh Kumar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views

How To Log All Magento SQL

This document discusses three methods for logging all SQL queries in Magento: 1) Using the Neon Profile SQL tool which logs queries by acting as a SQL proxy. 2) Editing the lib/Varien/Db/Adapter/Pdo/Mysql.php file to enable native Magento logging to the var/debug/pdo_mysql.log file. 3) Activating the Zend SQL profiler in the local.xml file to access detailed query profiling information programmatically.

Uploaded by

Santosh Kumar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

How to log all Magento SQL?

If you want to be sure all SQL is actually logged, I suggest to use a third party software:
 Neon Profile SQL is actually free and works fine
( you need to edit local.xml to attach Magento to Neon ... it works as a kind of SQL proxy logging
everything that pass through it)
In alternative a native Magento/Varien approach could be the following one:
1. edit lib/Varien/Db/Adapter/Pdo/Mysql.php
2. change the following properties to true (line 103 )
3. you will have a log file to be created here var/debug/pdo_mysql.log
Here line to be changed: ( comments are self explanatory )
protected $_debug = true;
protected $_logQueryTime = 0.05;
protected $_logAllQueries = true;
protected $_logCallStack = true;

In case you have enabled $_logCallStack you will have also a TRACE parte

2. Besides these basic information, one can get more info by calling “Varien_Profiler::getSqlProfiler($conn);”
like on the example shown below.

$conn = Mage::getSingleton('core/resource')->getConnection('core_setup');
$conn->getProfiler()->setEnabled(true);
 
echo Varien_Profiler::getSqlProfiler($conn);

3. Activate the Zend SQL Profiler with the following node in your app/etc/local.xml
<resources>
<default_setup>
<connection>
<profiler>1</profiler>
Then you can access the profiler somewhere in your code and retrieve a lot of informations about all executed
queries:
$profiler = Mage::getSingleton('core/resource')->getConnection('core_write')-
>getProfiler();

To simply output all queries:


print_r($profiler->getQueryProfiles());
You can add these two lines at the end of index.php to see all queries at the bottom of each page. Be aware that
this will break AJAX requests that return a JSON response, so you might consider logging the queries instead of
printing them, with this code (again, add it at the end of index.php):

$profiler = Mage::getSingleton('core/resource')->getConnection('core_write')-
>getProfiler();
Mage::log(print_r($profiler->getQueryProfiles(), true), null, 'queries.log', true);

Then you will find all queries in var/log/queries.log


Don't forget to remove the lines again after you finished debugging!

You might also like