0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

pt-deadlock-loggerを使ってみる

Posted at

http://www.percona.com/doc/percona-toolkit/2.2/pt-deadlock-logger.html

  • デッドロックの情報を検出、保存してくれるツール。

とりあえずで使ってみる

percona-toolkit(2.2.7)はインストール済み想定

ローカルではなくhost1にあるDBを見に行く

$ # デッドロック情報を保存するテーブルを作成する必要がある為、初回は保存用テーブル作成オプションをつけて実行
$ pt-deadlock-logger --create-dest-table --dest D=test,t=deadlocks -hhost1 -uuser

これでデッドロック情報テーブルを作成し、検出待ちになる
二回目以降は--create-dest-tableを省けばよい

この状態で試にデッドロックを起こしてみる

MySQLでデッドロックを発生させるを参照

こんな感じのが出る

server ts thread txn_id txn_time user hostname ip db tbl idx lock_type lock_mode wait_hold victim query
host1 2014-05-15T17:52:14 2999 0 411 user www.xxx.xx xxx.xx.xx.xx database deadlock_test col RECORD X w 0 
host1 2014-05-15T17:52:14 3036 0 28 user www.xxx.xx xxx.xx.xx.xx database deadlock_test col RECORD X w 1 select * from deadlock_test where col = 1 for update

test.deadlocks

mysql> select * from test.deadlocks\G
*************************** 1. row ***************************
   server: host1
       ts: 2014-05-15 17:52:14
   thread: 2999
   txn_id: 0
 txn_time: 411
     user: user
 hostname: www.xxx.xx
       ip: xxx.xx.xx.xx
       db: database
      tbl: deadlock_test
      idx: col
lock_type: RECORD
lock_mode: X
wait_hold: w
   victim: 0
    query: 
*************************** 2. row ***************************
   server: host1
       ts: 2014-05-15 17:52:14
   thread: 3036
   txn_id: 0
 txn_time: 28
     user: user
 hostname: www.xxx.xx
       ip: xxx.xx.xx.xx
       db: user
      tbl: deadlock_test
      idx: col
lock_type: RECORD
lock_mode: X
wait_hold: w
   victim: 1
    query: select * from deadlock_test where col = 1 for update
2 rows in set (0.00 sec)

バックグランドで指定の時間走らせる

--daemonizeと--run-timeオプションを付けて実行する

$ pt-deadlock-logger --daemonize --run-time=3000 --dest D=test,t=deadlocks -hhost1 -uuser
$ ps aux | grep pt-deadlock-logger 

定期的にINNODB STATUSの内容を引っ張って保存してくれてる感じ

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?