MySQL自我保護(hù)工具--pt-kill

MySQL出現(xiàn)運(yùn)行時間過長的SQL(慢SQL),會使線上數(shù)據(jù)庫壓力倍增,影響業(yè)務(wù)穩(wěn)定性及可用性
1. 背景
生產(chǎn)環(huán)境數(shù)據(jù)庫出現(xiàn)運(yùn)行時間過長的SQL,會影響數(shù)據(jù)庫性能,如果同時出現(xiàn)多個類似SQL,則會影響數(shù)據(jù)庫的可用性,從而導(dǎo)致業(yè)務(wù)不可用或體驗(yàn)差的情況。
在出現(xiàn)此類SQL的情況下,DBA人工干預(yù)需要一定的時間,在此期間如果SQL量比較大,且業(yè)務(wù)不停請求時,人工干預(yù)比較麻煩,無法及時處理。因此需要借助工具進(jìn)行監(jiān)控并自動kill超預(yù)期執(zhí)行的SQL。
2.? 工具介紹
pt-kill的主要使用場景簡介如下
2.1 查殺select大于30s的會話
#?只打印-查殺select大于30s的會話pt-kill --host=127.0.0.1 --port=3306 --user=root --password=rootpwd --match-db='machine' --match-info "select|SELECT" --busy-time 30 --victims all --interval 10 --daemonize --print --log=/tmp/pt_select.log# 執(zhí)行殺操作-查殺select大于30s的會話pt-kill?--host=127.0.0.1?--port=3306?--user=root?--password=rootpwd?--match-db='machine'?--match-info?"select|SELECT"?--busy-time?30?--victims?all?--interval?10?--daemonize?--kill?--log=/tmp/pt_select_kill.log
2.2 查殺某IP來源的會話
# 只打印-查殺某IP來源的會話pt-kill --host=127.0.0.1 --port=3306 --user=root --password=rootpwd --match-db='machine' --match-host "192.168.65.129" --busy-time 30 --victims all --interval 10 --daemonize --print --log=/tmp/pt_select.log# 執(zhí)行殺操作-查殺某IP來源的會話pt-kill --host=127.0.0.1 --port=3306 --user=root --password=rootpwd --match-db='machine' --match-host "192.168.65.129" --busy-time 30 --victims all --interval 10 --daemonize --kill --log=/tmp/pt_select_kill.log
2.3 查殺指定用戶的會話
# 只打印-查殺指定用戶的會話pt-kill --host=127.0.0.1 --port=3306 --user=root --password=rootpwd --match-db='machine' --match-user "u2" --busy-time 30 --victims all --interval 10 --daemonize --print --log=/tmp/pt_select.log# 執(zhí)行殺操作-查殺指定用戶的會話pt-kill --host=127.0.0.1 --port=3306 --user=root --password=rootpwd --match-db='machine' --match-user "u2" --busy-time 30 --victims all --interval 10 --daemonize --kill --log=/tmp/pt_select_kill.log
查殺進(jìn)行filesort的SQL
# 只打印-殺掉正在進(jìn)行filesort的sqlpt-kill --host=127.0.0.1 --port=3306 --user=root --password=rootpwd --match-db='machine' --match-command Query --match-state "Sorting result" --run-time 1 --busy-time 30 --victims all --interval 10 --daemonize --print --log=/tmp/pt_select.log# 執(zhí)行殺操作-殺掉正在進(jìn)行filesort的sqlpt-kill?--host=127.0.0.1?--port=3306?--user=root?--password=rootpwd?--match-db='machine'?--match-command?Query?--match-state?"Sorting?result"?--run-time?1?--busy-time?30?--victims?all?--interval?10?--daemonize?--kill?--log=/tmp/pt_select_kill.log
查殺Creating sort index的SQL
# 只打印pt-kill --host=127.0.0.1 --port=3306 --user=root --password=rootpwd --match-db='machine' --match-command Query --match-state "Creating sort index" --run-time 1 --busy-time 30 --victims all --interval 10 --daemonize --print --log=/tmp/pt_select.log# 執(zhí)行殺操作pt-kill --host=127.0.0.1 --port=3306 --user=root --password=rootpwd --match-db='machine' --match-command Query --match-state "Creating sort index" --run-time 1 --busy-time 30 --victims all --interval 10 --daemonize --kill --log=/tmp/pt_select_kill.log
3. 注意
對線上MySQL數(shù)據(jù)庫部署pt-kill工具,需要與業(yè)務(wù)方溝通相關(guān)策略,并將查殺結(jié)果記錄在日志中定期推送kill的SQL至相關(guān)人員

1.??MySQL高可用之MHA集群部署
2.??mysql8.0新增用戶及加密規(guī)則修改的那些事
3.? 比hive快10倍的大數(shù)據(jù)查詢利器-- presto
4. ?監(jiān)控利器出鞘:Prometheus+Grafana監(jiān)控MySQL、Redis數(shù)據(jù)庫
5.? PostgreSQL主從復(fù)制--物理復(fù)制
6.??MySQL傳統(tǒng)點(diǎn)位復(fù)制在線轉(zhuǎn)為GTID模式復(fù)制



評論
圖片
表情
