mysql slow query analysis tool of PT


1. intro

pt-query-digest is a tool for the analysis of mysql slow queries, it can analyze binlog, General log, slowlog, can also be analyzed by SHOWPROCESSLIST or MySQL protocol data captured by tcpdump. The results can be output to a file, process analysis is the first of query conditions are parameterized, and then after a parameterized query to group statistics, statistics of the execution time of each query, the number, accounting, etc., can make use of analysis The results identify the problem to be optimized.
pt-query-digest is a perl script, simply download and empowerment to execute.
[the root @ test1] # wget percona.com/get/pt-query-digest
[the root @ test1] U # the chmod + Pt-X-Query Digest


2. Important syntax and options
pt-query-digest [OPTIONS] [FILES] [DSN]

When --create-review-table --review parameter used when the analysis result is output to the table, if there is no table is created automatically.
When --create-history-table --history parameter used when the analysis result is output to the table, if there is no table is created automatically.
for slow query input filter to match the specified string after the analysis carried out --filter
--limit limit the number or percentage of output, the default value is 20, is about the slowest 20 statement output, if the press is 50% proportion of the total response time descending order, outputs the sum of 50% position is turned off.
--host mysql server address
--user mysql user name
--password mysql user password
--history save the analysis results to the table, analyze the results in more detail, the next time you use --history, if there is the same statement, and different time intervals and the history table where the query is logged to the data in the table can be relatively certain types of queries by querying the same CHECKSUM historical change.
--review will analyze save the results to the table, this analysis is only carried out a record of the query parameterization, a type of query is relatively simple. When the next time you use --review, if there is the same statement analysis, it will not record the data in the table.
--output analysis result output type, the value may be Report (standard analysis), slowlog (Mysql slow log) , json, json-anon, Report general use, easier to read.
--since from what time to start the analysis, the value of the string, may be a "yyyy-mm-dd [hh : mm: ss]" designated time point format may be a simple time values: s ( sec), h (hour), m (minutes), d (days), it is represented as 12h from 12 hours before the start statistics.
--until deadline, with -since slow query can be analyzed over a period of time.


3. Standard Analysis Reporting Interpretations
Part 1: General statistical results, as follows

Overall: 总共有多少条查询,上例为总共266个查询。
Time range: 查询执行的时间范围。
unique: 唯一查询数量,即对查询条件进行参数化以后,总共有多少个不同的查询,该例为55。
total: 总计   min:最小   max: 最大  avg:平均
95%: 把所有值从小到大排列,位置位于95%的那个数,这个数一般最具有参考价值。
median: 中位数,把所有值从小到大排列,位置位于中间那个数。

The second part: the query packet statistics, as
seen above, this part of the query parameterization and groups, and then the implementation of the various types of queries, with the results when you press the chief executive officer, in descending order.

Response: 总的响应时间。
time: 该查询在本次分析中总的时间占比。
calls: 执行次数,即本次分析总共有多少条这种类型的查询语句。
R/Call: 平均每次执行的响应时间。
Item : 查询对象

Part III: detailed statistics for each query, as follows:
As seen above, the detailed statistical results of the query No. 12, the top table lists the number of executions, maximum, minimum, average, and so the 95% statistical purposes .

Databases: 库名
Users: 各个用户执行的次数(占比)
Query_time distribution : 查询时间分布, 长短体现区间占比,本例中1s-10s之间查询数量是10s以上的两倍。
Tables: 查询中涉及到的表
Explain: 示例

Usage Example 4.

(1) slow query file direct analysis:
Pt-Query-Digest slow.log> slow_report.log

(2) Analysis of the query within the last 12 hours:
Pt-Query-Digest --since = 12h slow.log> slow_report2.log

(3) analytical queries within a specified time range:

pt-query-digest slow.log --since '2014-04-17 09:30:00' --until '2014-04-17 10:00:00'> > slow_report3.log

(4) comprising analysis means select slow query statement
pt-query-digest - filter ' $ event -> {fingerprint} = ~ m / ^ select / i' slow.log> slow_report4.log

(5) for a user query slow
pt-query-digest - filter ' ($ event -> {user} || "") = ~ m / ^ root / i' slow.log> slow_report5.log

(6) Search slow query all full table scan or full join the
pt-query-digest - filter ' (($ event -> {Full_scan} || "") eq "yes") || (($ event -> {Full_join} || "" ) eq "yes") 'slow.log> slow_report6.log

(7) to save the query table query_review
pt-query-digest --user = root -password = abc123 --review h = localhost, D = test, t = query_review - create-review-table slow.log

(8)把查询保存到queryhistory表
pt-query-digest --user=root –password=abc123 --review h=localhost,D=test,t=query
history--create-review-table slow.log_20140401
pt-query-digest --user=root –password=abc123--review h=localhost,D=test,t=query_history--create-review-table slow.log_20140402

(9) gripping the mysql tcpdump tcp protocol data, and then analyze
tcpdump -s -nN the -X-65535 -q -i -tttt the any -C Port 1000 3306> mysql.tcp.txt
Pt-Query-Digest --type tcpdump mysql.tcp.txt> slow_report9.log

(10)分析binlog
mysqlbinlog mysql-bin.000093 > mysql-bin000093.sql
pt-query-digest --type=binlog mysql-bin000093.sql > slow_report10.log

(11)分析general log
pt-query-digest --type=genlog localhost.log > slow_report11.log

The official document: https://www.percona.com/doc/percona-toolkit/2.2/pt-query-digest.html

Guess you like

Origin blog.51cto.com/13120271/2442230
Recommended