Pt-query-digest Query Log Analysis tool

Source: Internet
Author: User

1. Introduction to Tools

Pt-query-digest is a tool for analyzing slow queries for MySQL, which analyzes Binlog, general log, Slowlog, It can also be analyzed using showprocesslist or MySQL protocol data crawled by tcpdump. The analysis results can be exported to a file, the analysis process is the parameters of the query statement, and then the parameterized query after the grouping statistics, statistics of the query execution time, frequency, percentage, etc., can be used to identify problems with the analysis of the optimization.
Pt-query-digest is a Perl script that is included in the Percona-toolkit Toolkit:

Percona-toolkit Tool Pack Installation

1. Package download

Visit http://www.percona.com/software/percona-toolkit/to download the latest version of Percona Toolkit or get the latest version with the following command line:

wget percona.com/get/percona-toolkit.tar.gz

wget percona.com/get/percona-toolkit.rpm

I choose here directly from the website to find the latest version of the download:

wget http://www.percona.com/redir/downloads/percona-toolkit/2.1.1/percona-toolkit-2.1.1-1.noarch.rpm

wget http://www.percona.com/redir/downloads/percona-toolkit/2.1.1/percona-toolkit-2.1.1.tar.gz

Download the latest Termreadkey package from http://pkgs.repoforge.org/perl-TermReadKey/

wget http://pkgs.repoforge.org/perl-TermReadKey/perl-TermReadKey-2.30-1.el5.rf.x86_64.rpm



2. Package Installation

My environment is CentOS 5.5-BIT

A. Percona-toolkit rpm installation Method

RPM-IVH perl-termreadkey-2.30-1.el5.rf.x86_64.rpm

RPM-IVH percona-toolkit-2.1.1-1.noarch.rpm

Note: The Term::readkey package needs to be installed, otherwise it will be reported to Perl (Term::readkey) >= 2.10 is needed by Percona-toolkit-2.1.1-1.noarch error

B. Compilation and installation of Percona-toolkit

Tar xzvf percona-toolkit-2.1.1.tar.gz

CD percona-toolkit-2.1.1

Perl makefile.pl

Make

Make Test

Make install


[Email protected]]# chmod u+x pt-query-digest



2. Syntax and important options

pt-query-digest [OPTIONS] [FILES] [DSN]

--create-review-table when you use the--review parameter to output the analysis results to a table, it is created automatically if no tables are available.
--create-history-table when you use the--history parameter to output the analysis results to a table, it is created automatically if no tables are available.
--filter the input slow query is matched and filtered by the specified string for analysis
--limit limit the output percent or number, the default value is 20, the slowest 20 statement output, if 50% is the total response time from the largest to the small sort, the output to the sum of 50% position cutoff.
--host MySQL server address
--user MySQL user name
--password MySQL user password
--history the analysis results to the table, the analysis results are detailed, the next time you use--history, if the same statement exists, and the query is in a different time period and history table, it will be recorded in the data table, You can compare the historical changes of a type of query by querying the same checksum.
--review Save the analysis results to a table, this analysis only to the query criteria parameterized, a type of query a record, relatively simple. The next time you use--review, if you have the same statement analysis, it will not be recorded in the datasheet.
--output analysis Results output types, values can be report (standard analysis Reports), Slowlog (Mysql slow log), JSON, Json-anon, general use report for readability.
--since from when to parse, the value is a string, can be a specified "Yyyy-mm-dd [hh:mm:ss]" format point in time, or it can be a simple time value: s (seconds), H (Hours), M (minutes), D (days), such as 12h means starting from 12 hours ago statistics.
--until cut-off time, with-since can be analyzed for a period of time slow query.

3. Interpretation of the standard analysis report
Part I: Overall statistical results, such as


Overall: How many queries are in total, the previous example being a total of 266 queries.
Time range: The timeframe for query execution.
Unique: The number of unique queries, that is, after the query criteria are parameterized, a total of how many different queries, the example is 55.
Total: min: min Max: Max avg: Average
95%: Put all the values from small to large, the position is located in the number 95%, this number is generally the most valuable reference.
Median: Median, arranges all values from small to large and positions in the middle number.

Part II: Query the results of grouped statistics, such as


By visible, this part of the query is parameterized and grouped, and then the execution of various types of query analysis, the results by the total execution time, from large to small sort.
Response: Total response time.
Time: This query is accounted for in the overall period of the analysis.
Calls: number of executions, that is, the total number of this analysis of this type of query statements.
R/call: The average response time per execution.
Item: Query Object

Part III: Detailed statistical results for each query, such as:


By visible, the detailed statistics of the 12th query, the top table lists the number of executions, the maximum, minimum, average, 95% and other statistical purposes.
Databases: library Name
Users: Number of times each user executes (%)
Query_time Distribution: The query time distribution, the length reflects the interval ratio, in this case 1s-10s between the number of queries is more than 10s twice times.
Tables: Tables involved in the query
Explain: Example



4. Usage examples
(1) Direct analysis of slow query files:
Pt-query-digest Slow.log > Slow_report.log

(2) Analysis of queries within the last 12 hours:

Pt-query-digest--since=12h slow.log > Slow_report2.log

(3) Analysis of 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) Analysis means slow query with SELECT statement
Pt-query-digest--filter ' $event->{fingerprint} =~ m/^select/i ' slow.log> slow_report4.log

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

(6) Query all full-table scans or slow queries
Pt-query-digest--filter ' (($event->{full_scan} | | "") eq "yes") | | (($event->{full_join} | | "") eq "yes") ' slow.log> Slow_report6.log

(7) Save the query to the Query_review table
Pt-query-digest--user=root–password=abc123--review h=localhost,d=test,t=query_review--create-review-table Slow.log

(8) Save the query to the Query_history table
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) Crawl the MySQL TCP protocol data via tcpdump and then analyze
Tcpdump-s 65535-x-nn-q-tttt-i any-c-Port 3306 > Mysql.tcp.txt
Pt-query-digest--type tcpdump mysql.tcp.txt> slow_report9.log

(10) Analysis Binlog
Mysqlbinlog mysql-bin.000093 > Mysql-bin000093.sql
Pt-query-digest--type=binlog mysql-bin000093.sql > Slow_report10.log

(11) Analysis of general log
Pt-query-digest--type=genlog localhost.log > Slow_report11.log

Pt-duplicate-key-checker--host=localhost--user=test_froad--password=test123--databases=openapi

Pt-duplicate-key-checker--host=10.43.1.100--user=root--password=123456--databases=openapi
Pt-mysql-summary--host=10.43.1.100--user=root--password=123456
Pt-deadlock-logger--user=test_froad--password=test123 h=localhost–print--databases=froadpoints

Pt-query-digest Query Log Analysis tool

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.