percona-toolkit学习笔记(七)
- 2019 年 10 月 5 日
- 筆記
pt-fifo-split
功能:
模拟切割文件并通过管道传递给先入先出队列而不用真正的切割文件
说明:
pt-fifo-split读取大文件中的数据并打印到fifo文件,每次达到指定行数就往fifo文件中打印一个EOF字符,读取完成以后,关闭掉fifo文件并移走,然后重建fifo文件,打印更多的行。这样可以保证你每次读取的时候都能读取到制定的行数直到读取完成。注意此工具只能工作在类unix操作系统。这个程序对大文件的数据导入数据库非常有用,具体参考:https://www.percona.com/blog/2008/07/03/how-to-load-large-files-safely-into-innodb-with-load-data-infile/
实例:
一次读取100行记录
pt-fifo-split–lines 100 /root/all.sql
while[ -e /tmp/pt-fifo-split ]; do cat /tmp/pt-fifo-split; done
pt-find
功能:Find MySQL tables and executeactions, like GNU find
说明:
pt-findsearches for MySQL tables and executes actions, like GNU find. The default action is to print the databaseand table name.
实例:
pt-find –ctime -1 –engine MyISAM-uroot -proot -h localhost # 列出创建时间小于1天且使用MyISAM引擎的数据表
pt-find –engine InnoDB -uroot-proot -h localhost # 列出InnoDB引擎的表
pt-find –ctime -1 -uroot -proot-h localhost –exec-plus "drop table %s" # 将找到的符合条件的table删除掉
pt-find –tablesize +500M -uroot-proot -h localhost # 列出总大小超过500M的表
pt-find hellodb -uroot -proot -hlocalhost # 列出hellodb库里的所有表
pt-find –printf"%Tt%D.%Nn" -uroot -proot -hlocalhost | sort -rn # 列出所有表的total data and index size,并从大到小排序
pt-fingerprint
功能:Convert queries into fingerprints.
用于生成查询指纹。主要将将sql查询生成queryID,pt-query-digest中的ID即是通过此工具来完成的。 类似于Oracle中的SQL_ID,涉及绑定变量,字面量等
说明:
pt-findsearches for MySQL tables and executes actions, like GNU find. The default action is to print the databaseand table name.
实例:
#pt-fingerprint –query "select a,b,c from hellodb.students wherestuid=22"
pt-ioprofile
功能:pt-ioprofile的原理是对某个pid附加一个strace进程进行IO分析
pt-ioprofileuses "strace" and "lsof" to watch a process’s IO and printout a table of files and I/O activity. By default, it watches the mysqld process for 30 seconds.
pt-kill
功能:Kill掉符合指定条件mysql语句
官方示例:
Kill queries runninglonger than 60s:
# pt-kill –busy-time 60 –kill
Print, do not kill,queries running longer than 60s:
# pt-kill –busy-time 60 –print
Check for sleepingprocesses and kill them all every 10s:
# pt-kill –match-command Sleep–kill –victims all –interval 10
Print all loginprocesses:
# pt-kill –match-state login–print –victims all
See which queries inthe processlist right now would match:
# mysql -e "SHOWPROCESSLIST" > proclist.txt
# pt-kill –test-matchingproclist.txt –busy-time 60 –print
pt-stalk
功能:用于收集mysql数据库故障时的相关信息便于后续诊断处理。Collect forensic data about MySQLwhen problems occur
pt-stalk等待触发条件触发,然后收集数据帮助错误诊断,它被设计成使用root权限运行的守护进程,因此你可以诊断那些你不能直接观察的间歇性问题。默认的诊断触发条件为SHOW GLOBAL STATUS。也可以指定processlist为诊断触发条件,使用–function参数指定。
范例1:指定诊断触发条件为status,同时运行语句超过20的时候触发,收集的数据存放在/tmp/test目录下:
# pt-stalk –function status
–variable Threads_running–threshold 20
–dest /tmp/test — -uroot -proot -h192.168.2.11
范例2:指定诊断触发条件为processlist,超过20个状态为statistics触发,收集的数据存放在/tmp/test目录下:
# pt-stalk –function processlist
–variable State –matchstatistics –threshold 20
–dest /tmp/test — -uroot -proot -h192.168.2.11