Slow query logging is used to determine where database time is spent. If there is a query that is running inefficiently this mechanism will help isolate it.
Question: How do I turn on slow query logging?
Answer: To log all slow queries , follow these steps:
There are two major methods to turn on slow query logging:
1) Log into the application as an administrator
2) Click the "Admin" link
3) Click "System Settings"
4) Make sure "Log slow queries:" is checked.
5) Set "Slow query time threshold (msec):" to 100
Or...
1) Open your config.php file, located in the main Sugar directory
2) Locate this line:
3) Change the line to:PHP Code:'dump_slow_queries' => false,
4) Locate this line:PHP Code:'dump_slow_queries' => true,
5) Change the line to:PHP Code:'slow_query_time_msec' => '500',
6) Save the filePHP Code:'slow_query_time_msec' => '100',
(If you want a full log of all queries change the slow query time to -1 since many queries run in less than 1 ms).
Here is a sample of the contents of sugarcrm.log after the slow query log is turned on. Note: all messages are logged as FATAL to ensure that they make it into the logfile.
This sample shows 2 "slow" queries. Each one has an easily identified log statement "FATAL SugarCRM - Slow Query", followed by the etime in seconds for the query. After this, there is a newline and then the query is presented in the formatting in which it was sent to the database. Putting the query on its own line make it easy to find and easy to cut/paste into another program for further diagnosis.Code:11/22/05 10:47:41,170 [6448] FATAL SugarCRM - Slow Query (time:0.031598 SELECT count(*) FROM contacts LEFT JOIN users ON contacts.assigned_user_id=users.id LEFT JOIN accounts_contacts ON contacts.id=accounts_contacts.contact_id LEFT JOIN accounts ON accounts_contacts.account_id=accounts.id LEFT JOIN teams ON contacts.team_id=teams.id AND (teams.deleted=0) where contacts.deleted=0 AND (accounts.deleted is NULL or accounts.deleted=0) 11/22/05 10:47:41,183 [6448] FATAL SugarCRM - Slow Query (time:0.012344 SELECT contacts.*, accounts.name as account_name, accounts.id as account_id, accounts.assigned_user_id account_id_owner, users.user_name as assigned_user_name ,teams.name AS team_name FROM contacts LEFT JOIN users ON contacts.assigned_user_id=users.id LEFT JOIN accounts_contacts ON contacts.id=accounts_contacts.contact_id LEFT JOIN accounts ON accounts_contacts.account_id=accounts.id LEFT JOIN teams ON contacts.team_id=teams.id AND (teams.deleted=0) where contacts.deleted=0 AND (accounts.deleted is NULL or accounts.deleted=0) ORDER BY contacts.last_name, contacts.first_name asc LIMIT 0,20
Lets take apart the first log entry in the example:
This shows the time and date when the query was executed. Then comes the common log statement to identify it as a slow query "FATAL SugarCRM - Slow Query".Code:11/22/05 10:47:41,170 [6448] FATAL SugarCRM - Slow Query (time:0.031598
This is the actual query that was executed against the database.Code:SELECT count(*) FROM contacts LEFT JOIN users ON contacts.assigned_user_id=users.id LEFT JOIN accounts_contacts ON contacts.id=accounts_contacts.contact_id LEFT JOIN accounts ON accounts_contacts.account_id=accounts.id LEFT JOIN teams ON contacts.team_id=teams.id AND (teams.deleted=0) where contacts.deleted=0 AND (accounts.deleted is NULL or accounts.deleted=0)
If you have a use case that is bad, turn on logging, clear the sugarcrm.log file, and perform the use case. Then copy the logfile. At this point, you should have a log of all the queries that took more that 1/10th of a second to execute along with the exact time of the query. These queries can be used to run explain plans for determining why the query is slow and hopefully optimizing indexes on the database.
Jacob


LinkBack URL
About LinkBacks




Bookmarks