Parajsa.com


Parajsa Shqiptare Forum

Cfare ju duhet te dini?

 

Kthehuni Mbrapa   Parajsa Shqiptare Forum | Albanian Paradise | Webmaster

How-To Enable Logging of Slow Queries in MySQL Database

Pergjigju
 
LinkBack Alternativa Teme Vleresoni Temen
  #1  
Te vjeter 03-07-2008, 21:24
Minifotoja e anetarit Administratori
Parajsa Shqiptare
 
Reg: 06-07-02
Lokalizimi: London
Postime: 2,031
Images: 2351
Faqe ne Ditar: 2
How-To Enable Logging of Slow Queries in MySQL Database

How-To Enable Logging of Slow Queries in MySQL Database

One of the main requirements for a fast web server is to has efficient and effective SQL statements or queries that are optimized. Any non-optimal SQL (Structured Query Language) commands or statements that take too long or lengthy time to execute will use up a lot of system resources, causing MySQL database to run slower, and then more and more queries backlogs queuing up, and when connection limit is reached, visitors are been denied or refused connection. In worst case scenario, your web server will go down as well, or continuously underperform. The case is especially true when you are using MyISAM table type which uses table-level locking instead of row-level locking in a high traffic website.

Sometime, a single SQL query may be the cause of all the server’s problems. MySQL has built-in functionality to capture slow query log or identify queries that are not optimal and take a long time to finish, which allows you to log all slow running queries which took over defined number of seconds to execute by MySQL database engine to a file. Slow query log is not activated or on by default MySQL installation, thus it is one of the less-used logs.

To enable slow query log, simply add the following line to MySQL configuration file (my.cnf or my.ini), and then restart the MySQL server:

log-slow-queries

or

log-slow-queries = [path to the log file]


Replace [path to the log file] with actual path to the slow query log file you want the MySQL to write the log to, which is the optional value.

Or you can start mysqld with with the –log-slow-queries[=file_name] option to enable the slow query log. In both syntaxes, if not log file name is specified, the default name is host_name-slow.log, stored in the MySQL data file directory. If a filename is given, but not as an absolute pathname, the server writes the file in the data directory too.

After enabling slow query log, MySQL will create, capture and log to the log file with all SQL statements that took more than long_query_time seconds to execute, which is by default set to 10 seconds. The time to acquire the initial table locks is not counted as execution time. mysqld writes a statement to the slow query log after it has been executed and after all locks have been released, so log order might be different from execution order.

You can then examine all the SQL queries that took longer than the pre-defined number of seconds (10 seconds by default) in the host_name-slow.log, and then take the necessary steps to optimize the SQL statements. The slow query log will tell you about what was time the query completed, how long the query took to run, how long it took to secure its locks, how many rows were sent back as a result, how many rows were examined to determine the result, which database was used, and the actual query itself. But bear in mind that a SQL query contained in the log may have already optimum, but executed slowly due to the system resources been used up by the actual slow statement that need to be fine tuned.
__________________
The heaven's sound is composed inside your heart, listen to its beat to syncronize your life onto the angel's steps.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Live!Google!Sphinn!Stumbleupon!Yahoo!Spurl this Post!Reddit! Wong this Post!
Pergjigjuni me Citim
Pergjigju

Bookmarks

Tags
how-to, logging, queries

Alternativa Teme
Vleresojeni kete Teme
Vleresojeni kete Teme:

Rregullore Postimi
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is aktivizuar
Buzeqeshjet jane te aktivizuar
Kodi [IMG] eshte i aktivizuar
Kodi HTML eshte i dizaktivizuar
Trackbacks are aktivizuar
Pingbacks are aktivizuar
Refbacks are aktivizuar
Kapercim Forumesh


Te gjitha oret jane ne GMT +1. Ora tani eshte 14:49.




Parajsa Shqiptare