Preface
 
    Performance issues are what DBA most concerned thing.There're always a lot of SQL queries which maybe not using appropriated indexes cause bad perfoemance.Whenever that happens,we have to do some performance diagnosis immediately.In most scenarios,we will do that relies on slow log,but it's not enough or efficient I'm afraid.What's the better way then?Another tool of percona called "pt-query-digest" can solve these kind of issues.
 
Introduce
 
    pt-query-digest is a tool focus on log analysis.It is supported to analyze slow log,general log,binlog and so on in different ways.You can also use it to analyze logs and simultaneously put these informations into tables on remote host(server) that you specified.That's really convenient and flexible for us DBA to work efficiently in performance tuning.
 
Procedure
 
Usage
 Usage: pt-query-digest [OPTIONS] [FILES] [DSN]

Parameters introduce

 --limit -- Limit the output conents by count(defualt ) or percentage(default %).
--type -- Indicate a type(default "slowlog",else value is "genlog","binlog","tcpdump",etc.) you want to anaylze.
--processlist -- Analyze from "show processlist" result from specific host(need to input DSN).
--create-history-table -- Create a table to record infomation if use "--history"(default "true").
--create-review-table -- Create a table to record infomation if use "--review"(default "true").
--history -- Save query metrics(such as query time) into a given table which can be checked incremental difference later.
--review -- Save query classes into a given table for later review.It don't report same kind of class.
--output -- Specify the format of query result(default "report").
--since -- Give a specific time with time format of beginning.
--until -- Give a specific time with time format of end.
--group-by -- According to the atrribute of envents to group by(default "figerprint",else value is "tables"&"distill").
--order-by -- According to the atrribute of envents to sort by(default "Query_time:sum").
Examples
 
Make sure the slow log is enabled.
 (root@localhost mysql3306.sock)[(none)]::>show variables like '%slow%';
+---------------------------+----------+
| Variable_name | Value |
+---------------------------+----------+
| log_slow_admin_statements | OFF |
| log_slow_slave_statements | ON |
| slow_launch_time | |
| slow_query_log | ON |
| slow_query_log_file | slow.log |
+---------------------------+----------+
rows in set (0.00 sec) (root@localhost mysql3306.sock)[(none)]::>show variables like '%long_query_time%';
+-----------------+----------+
| Variable_name | Value |
+-----------------+----------+
| long_query_time | 1.000000 |
+-----------------+----------+
row in set (0.00 sec) (root@localhost mysql3306.sock)[(none)]::>show variables like '%log_output%';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| log_output | FILE |
+---------------+-------+
row in set (0.00 sec)

Execute a slow query.

 (root@localhost mysql3306.sock)[(none)]::>select sleep();
+-----------+
| sleep() |
+-----------+
| |
+-----------+
row in set ( min 0.01 sec)

Check slow log for information of above slow query.

 [root@zlm2 :: /data/mysql/mysql3306/data]
#cat slow.log # Time: --23T07::.891778Z
# User@Host: root[root] @ localhost [] Id:
# Query_time: 60.001239 Lock_time: 0.000000 Rows_sent: Rows_examined:
SET timestamp=;
select sleep();

Use pt-query-digest analyze slow log file for more details.

 [root@zlm2 :: ~]
#pt-query-digest /data/mysql/mysql3306/data/slow.log # No events processed. -- Only if the slow query has finished,there will be a result of report. [root@zlm2 :: ~]
#pt-query-digest /data/mysql/mysql3306/data/slow.log # 180ms user time, system time, 25.59M rss, 221.68M vsz
# Current date: Sat Jun ::
# Hostname: zlm2
# Files: /data/mysql/mysql3306/data/slow.log
# Overall: total, unique, QPS, 0x concurrency ______________________
# Time range: all events occurred at --23T07::
# Attribute total min max avg % stddev median
# ============ ======= ======= ======= ======= ======= ======= =======
# Exec time 60s 60s 60s 60s 60s 60s
# Lock time
# Rows sent
# Rows examine
# Query size # Profile
# Rank Query ID Response time Calls R/Call V/M Item
# ==== ================== ============== ===== ======= ===== ======
# 0xF9A57DD5A41825CA 60.0012 100.0% 60.0012 0.00 SELECT # Query : QPS, 0x concurrency, ID 0xF9A57DD5A41825CA at byte ________
# This item is included in the report because it matches --limit.
# Scores: V/M = 0.00
# Time range: all events occurred at --23T07::
# Attribute pct total min max avg % stddev median
# ============ === ======= ======= ======= ======= ======= ======= =======
# Count
# Exec time 60s 60s 60s 60s 60s 60s
# Lock time
# Rows sent
# Rows examine
# Query size
# String:
# Hosts localhost
# Users root
# Query_time distribution
# 1us
# 10us
# 100us
# 1ms
# 10ms
# 100ms
# 1s
# 10s+ ################################################################
# EXPLAIN /*!50100 PARTITIONS*/
select sleep()\G ###All the meaning of above is self-explanatory,you can check official document for details.###
Other expamples
 
1.Analyze general log.
 pt-query-digest --type=genlog /path/zlm2.log > report1.log

2.Analyze binlog.

 mysqlbinlog -vv --base64-output=decode-rows /path/mysql-bin. > mysql-bin000010.sql
pt-query-digest --type=binlog /path/mysql-bin000001.sql > report2.log

3.Analyze rawlog(It's a general txt file which contains SQL statement).

 echo "select sleep(10);">rawlog.log pt-query-digest --type=rawlog rawlog.log > report3.log

4.Analyze processlist(DSN is indispensable).

 pt-query-digest --processlist h=192.168.1.101,P=,u=repl,p=repl4slave > report4.log -- If connection failed,it will try every second.

5.Analyze tcpdump.

 tcpdump -s  -x -nn -q -tttt -i any -c  port  > tcpdump.log
pt-query-digest --type=tcpdump tcpdump.log > report5.log

6.Analyze slow log since last 24 hours.

 pt-query-digest --since=24h slow.log > report6.log

7.Analyze slow log since time until time.

 pt-query-digest --since '2018-06-23 08:30:00' --until '2018-06-23 10:30:00' slow.log > report7.log

8.Analyze slow log into view table("query_review" table will be created if not specify "-t") of remote host.

 pt-query-digest --review h=192.168.1.102,P=,u=repl,p=repl4slave,D=zlm,t=query_review slow.log > report8.log

9.Analyze slow log into history table("query_history" table will be created like above) of remote host.

 pt-query-digest --review h=192.168.1.102,P=,u=repl,p=repl4slave,D=zlm,t=query_history slow.log > report9.log
Summay
  • There're still some advanced useages I've not demonstrated such as "--group-by","--order-by" and "--filter",etc.
  • pt-query-digest is extraordinarily useful when doing performance diagnosis by different ways.
  • It's recommended to analyze logs on another node(maybe slave) instead of master to reduce consumption of CPU,Memory,IO,etc.
  • pt-query-digest can help you to find out the specific slow quries.Afterwards you can use MySQL profiling("set profiling=1;" then "show profiles;") to survey the perticular resources which are tremendously consumed.

Percona-Tookit工具包之pt-query-digest的更多相关文章

  1. [hdu 6191] Query on A Tree

    Query on A Tree Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 132768/132768 K (Java/Othe ...

  2. Mysql: pt-table-checksum 和 pt-table-sync 检查主从一致性,实验过程

    一.安装 percona 包 1.安装仓库的包 https://www.percona.com/doc/percona-repo-config/yum-repo.html sudo yum insta ...

  3. MySQL ProxySQL读写分离使用初探

    目的 在美团点评DBProxy读写分离使用说明文章中已经说明了使用目的,本文介绍ProxySQL的使用方法以及和DBProxy的性能差异.具体的介绍可以看官网的相关说明,并且这个中间件也是percon ...

  4. ProxySQL 配置详解及读写分离(+GTID)等功能说明 (完整篇)

    ProxySQL是灵活强大的MySQL代理层, 是一个能实实在在用在生产环境的MySQL中间件,可以实现读写分离,支持 Query 路由功能,支持动态指定某个 SQL 进行 cache,支持动态加载配 ...

  5. Linux后台开发工具箱

    https://files-cdn.cnblogs.com/files/aquester/Linux后台开发工具箱.pdf 目录 目录 1 1. 前言 3 2. 脚本类工具 3 2.1. sed命令- ...

  6. MySQL 使用pt-table-checksum 检查主从数据一致性 (实例转)

    1.基本环境: Mysql版本:5.6.12-log Percona-toolkit:2.2.18 Linux:centos6.5 2.安装 源码安装: # 一些依赖包 yum install per ...

  7. Linux后台开发工具箱-葵花宝典

    Linux后台开发工具箱-葵花宝典 一见 2016/11/4 目录 目录 1 1. 前言 4 2. 脚本类工具 4 2.1. 双引号和单引号 4 2.2. 取脚本完整文件路径 5 2.3. 环境变量和 ...

  8. 推荐几款MySQL相关工具

    前言: 随着互联网技术的不断发展, MySQL 相关生态也越来越完善,越来越多的工具涌现出来.一些公司或个人纷纷开源出一些不错的工具,本篇文章主要介绍几款 MySQL 相关实用工具.提醒下,这里并不介 ...

  9. pt-table-checksum

    pt-table-checksum是percona公司提供的一个用于在线比对主从数据一致性的工具. 实现原理 将一张大表分成多个chunk,每次针对一个chunk进行校验,同时将校验的结果通过REPL ...

  10. [知识库分享系列] 二、.NET(ASP.NET)

    最近时间又有了新的想法,当我用新的眼光在整理一些很老的知识库时,发现很多东西都已经过时,或者是很基础很零碎的知识点.如果分享出去大家不看倒好,更担心的是会误人子弟,但为了保证此系列的完整,还是选择分享 ...

随机推荐

  1. git clone 指定的单个目录或文件夹

    git clone 指定的单个目录或文件夹 针对自己的项目 方法一 基于sparse clone变通方法 创建一个空仓库 拉取远程仓库信息 开启 sparse clone 设置过滤 更新仓库 创建空仓 ...

  2. 解析angularjs中的绑定策略

    一.首先回顾一下有哪些绑定策略? 看这个实在是有点抽象了,我们来看具体的实例分析吧! 二.简单的Demo实例 @绑定:传递一个字符串作为属性的值.比如 str : ‘@string’ 控制器中代码部分 ...

  3. Oracle里删除重复记录,保留一项

    我们在使用数据库的时候,有时数据会有所重复,当我们只需要一项数据时,不需要显示重复的记录时 如下就有SQL代码: --查找表中多余的重复记录,重复记录是根据单个字段来判断 select * from ...

  4. mysql在表的某一位置增加一列、删除一列、修改列名

    如果想在一个已经建好的表中添加一列,可以用以下代码: ) not null; 这条语句会向已有的表中加入一列,这一列在表的最后一列位置.如果我们希望添加在指定的一列,可以用: ) not null a ...

  5. 服务器常用命令之 启用/禁用PING状态

    启用 echo 0 > /proc/sys/net/ipv4/icmp_echo_ignore_all  (PING的通) 禁用 echo 1 > /proc/sys/net/ipv4/i ...

  6. Cloud Foundry Session Affinity(Sticky Session)的实现

    会话保持(Session Affinity),有时又称粘滞会话(Sticky Sessions), 是负载均衡领域设计需要着力解决的重要问题之一,也是一个相对比较复杂的问题. 会话保持是指在负载均衡器 ...

  7. CRM和ERP的Sales Organization的映射关系

    在如下的配置里可以维护CRM和ERP的Sales Organization的映射关系. 例如,ERP的编号为0001的销售组织映射到CRM的编号为O 50040102的销售组织: 这种映射关系存储在表 ...

  8. Fiori Launchpad Tile点击后跳转的调试技巧

    在SAP Fiori launchpad 里点击某个tile之后,后台会计算出跳转的目标url返回给前台. 下图中一个个白色的方框就成为tile.每个tile点击之后,会打开一个对应的Fiori应用. ...

  9. selenium启动不了浏览器或者启动后不会写入网址,先更新下浏览器驱动

    平时自动化习惯用Chrome浏览器.有几个月没用selenium启动IE和Firefox,今天跑兼容性测试,需要验证其他浏览器.结果遇到两个异常: 1 IE启动不了,直接报错. 2 Firefox启动 ...

  10. E. XOR and Favorite Number

    题意:很多询问,求每个询问下,有多少个区间,异或=k. 分析:异或也有前缀和.[L,R] = pre[R] ^ pre[L-1]: 莫队算法:是莫涛队长发明的,一种改良版的暴力离线算法. 首先将问题重 ...