MySQL Slow log analysis tool pt-query-digest

Source: Internet
Author: User
Tags time 0 install perl percona

Before Windows mysql5.6.20 using mysqldumpslow.pl to analyze slow logs, today saw a tool pt-query-digest, originally intended to be installed on Windows, resulting in the execution of C: \ on Windows Program Files\mysql\mysql Server 5.6\bin>pt-query-digest.pl F:\mysql\im-slow.log > F:\mysql\slow_ Report.log, waiting for half an hour will not come out results. It must be a little support for Windows, so just use Linux.

1. First install Perl, login https://www.perl.org/get.html, I choose the latest version.

Unzip later to Perl's installation directory to execute

[email protected] perl-5.22.0]# ./configure-des-dprefix=/usr/perl-5.22.0-dusethreads-uversiononly

Verify that the installation is successful

[Email protected] perl-5.22.0]# perl-version
This was Perl, v5.10.1 (*) built for X86_64-linux-thread-multi
Copyright 1987-2009, Larry Wall
Perl May is copied only under the terms of either the artistic License or the
GNU general public License, which is found in the Perl 5 source kit.
Complete documentation for Perl, including FAQ lists, should is found on
This system using "Man Perl" or "Perldoc perl". If you had access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.


2. Download pt-query-digest,https://www.percona.com/downloads/percona-toolkit/, download percona-toolkit_2.2.14.tar.gz.

After extracting the tar zxvf, come to the installation directory/data/percona-toolkit-2.2.14 execute
[email protected] perl-5.22.0]# perl makefile.pl
[[email protected] perl-5.22.0]# make
[[email protected] perl-5.22.0]# make install

3.pt-query-digest/data/im-slow.log >/data/slow_report.log, this result is almost seconds out compared to Windows half-day out.

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.

# 34.3s User Time, 310ms system time, 44.95M rss, 196.52M vsz
# Current Date:thu 13 10:51:55 2015
# hostname:vm-10.10.x.x
# Files:/data/im-slow.log
# overall:64.10k Total, 179 unique, 0.00 QPS, 0.10x concurrency _________
# time range:2015-02-08 06:52:36 to 2015-07-29 09:02:02
# Attribute Total min max avg 95% StdDev Median
# ============     ======= ======= ======= ======= ======= ======= =======
# Exec Time 1405895s 5s 4899s 22s 32s 111s 10s
# Lock Time 62995s 0 2476s 983ms 1ms 48s 144us
# Rows sent 5.69G 0 44.43M 93.04k 5.75 1.34M 0.99
# Rows Examine 13.96G 0 693.12M 228.36k 44.45k 3.49M 0.99
# Query Size 37.30M 6 335.57k 610.11 918.49 6.98k 537.02


# profile
# Rank Query ID Response time Calls r/call v/m Item
# ==== ================== ================= ===== ========= ===== ========
# 1 0x0f2e6b958872280e 274452.3245 19.5% 26566 10.3310 2.39 SELECT gg_token gg_tenant
# 2 0x816f5d9db1bd38c7 246396.5092 17.5% 15295 16.1096 31 ... INSERT gg_login_history
# 3 0xa3267d6cefa1d5e3 203446.8729 14.5% 100 2034.4687 13 ... SELECT Gg_token Gg_login_history
# 4 0X67A347A2812914DF 170491.0463 12.1% 972 175.4023 44 ... SELECT App_chat_message
# 5 0x8baca5842b7a7490 95999.5908 6.8% 5737 16.7334 37 ... INSERT App_offline_message
# 6 0x2b874bb5cb81dc1f 68234.7809 4.9% 649.8551 87.61 SELECT gg_token gg_login_history
# 7 0x848218fe4d9f7651 51218.6838 3.6% 243.8985 12.52 SELECT Gg_token
# 8 0xbf9265005d4f8d80 40299.7591 2.9% 78 516.6636 28 ... SELECT gg_login_history gg_user gg_user_org gg_org
# 9 0xdcdbc481602798a4 39449.2606 2.8% 3193 12.3549 4.68 SELECT Gg_token


Databases: library name
Users: Number of times each user executes (%)
Query_time Distribution: Query time distribution, length reflects interval ratio
Tables: Tables involved in the query
Explain: Example

# Query 1:0.03 QPS, 0.30x concurrency, ID 0x0f2e6b958872280e at byte 28156661
# This item was included in the because it matches--limit.
# scores:v/m = 2.39
# time range:2015-06-16 00:05:14 to 2015-06-26 11:33:23
# Attribute pct Total min max avg 95% StdDev Median
# ============ === ======= ======= ======= ======= ======= ======= =======
# Count 41 26566
# Exec Time 274452s 5s 54s 10s 12s 5s 10s
# Lock Time 0 24s 64us 40ms 885us 1ms 738us 839us
# Rows sent 0 80.00k 0 13 3.08 4.96 1.29 2.90
# Rows Examine 8 1.15G 44.73k 45.59k 45.43k 44.45k 0 44.45k
# Query size 13.78M 542 544 543.73 537.02 0 537.02
# String:
# Databases IM
# Hosts 10.100.252.38 (13301/50%) ... 1 more
# Users IM
# Query_time Distribution
# 1us
# 10US
# 100US
# 1ms
# 10ms
# 100ms
# 1s ########################################################
# 10s+ ################################################################
# Tables
# SHOW TABLE STATUS from ' im ' like ' gg_token ' \g
# SHOW CREATE TABLE ' im '. ' Gg_token ' \g
# SHOW TABLE STATUS from ' im ' like ' gg_tenant ' \g
# SHOW CREATE TABLE ' im '. ' Gg_tenant ' \g
# EXPLAIN/*!50100 partitions*/
Select token0_.token_id as token_id1_119_, token0_.tenant_id as tenant_10_119_, Token0_.account as account2_119_, Token0 _.client_id as client_i3_119_, token0_.create_date as create_d4_119_, token0_.host as host5_119_, token0_.last_auth_ Date as last_aut6_119_, token0_.session_id as session_7_119_, Token0_.token as token8_119_, token0_.user_id as User_id9_1 19_ from Gg_token token0_ to outer join Gg_tenant tenant1_ on token0_.tenant_id=tenant1_.tenant_id where token0_.user_id = ' 00014806a5a95f25ab ' and tenant1_.tenant_id= ' 0001456d92804b00 ' \g


# Query 2:0.00 QPS, 0.02x concurrency, ID 0x816f5d9db1bd38c7 at byte 17658778
# This item was included in the because it matches--limit.
# scores:v/m = 314.49
# time range:2015-03-21 13:31:25 to 2015-07-18 15:11:32
# Attribute pct Total min max avg 95% StdDev Median
# ============ === ======= ======= ======= ======= ======= ======= =======
# Count 23 15295
# Exec Time 246397s 5s 2498s 16s 32s 71s 11s
# Lock time 32142s 0 2476s 2s 125us 71s 89us
# Rows sent 0 0 0 0 0 0 0 0
# Rows examine 0 0 0 0 0 0 0 0
# Query Size 9 3.55M 221 258 243.36 246.02 7.37 234.30
# String:
# Databases IM
# Hosts 10.101.252.35 (7709/50%) ... 3 more
# Users IM
# Query_time Distribution
# 1us
# 10US
# 100US
# 1ms
# 10ms
# 100ms
# 1s #############################################
# 10s+ ################################################################
# Tables
# SHOW TABLE STATUS from ' im ' like ' gg_login_history ' \g
# SHOW CREATE TABLE ' im '. ' Gg_login_history ' \g
INSERT into Gg_login_history (login_history_id,username,resource,clientid,login_time,logout_time) VALUES (' 930e0b3e-d26b-4cc3-a02f-be0b1009744c ', ' 000148b62c6a6e290 ', ' Android ', ' 354273054207050 ', ' 2015-04-13 23:04:42 ', ' 2015-04-13 23:07:46 ') \g

The most commonly used methods of use:

(1) Direct analysis of slow query files:
Pt-query-digest Slow.log > Slow_report.log
(2) Analysis of queries within the last 1 hours:
Pt-query-digest--since=1h slow.log > Slow_report.log
(3) Analysis of queries within a specified time range:
Pt-query-digest slow.log--since ' 2015-04-17 10:30:00 '--until ' 2015-04-17 18:00:00 ' >slow_report.log
(4) Analysis means slow query with SELECT statement
Pt-query-digest--filter ' $event->{fingerprint} =~ m/^select/i ' slow.log> slow_report.log
(5) 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_report.log

Detailed instructions for use:

Https://www.percona.com/doc/percona-toolkit/2.1/pt-query-digest.html

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

MySQL Slow log analysis tool pt-query-digest

Related Article

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.