地方エンジニアの学習日記

興味ある技術の雑なメモだったりを書いてくブログ。たまに日記とガジェット紹介。

MySQLのOOM調査に使ったスクリプト

#!/bin/bash

while true; do
    date
    ps aux | grep [m]ysqld
    echo "####"; mysql -e "select * from sys.memory_global_by_current_bytes where current_alloc LIKE '%GiB%';"
    echo "####"; mysql -e "select * from sys.memory_by_thread_by_current_bytes where current_allocated LIKE '%GiB%';"
    echo "####"; mysql -e "select * from sys.memory_global_total;"
    echo "####"; mysql -e "show engine performance_schema status\G" | grep performance_schema.memory -A 2
    echo "####"; mysql -e "show engine innodb status\G" | grep MEMORY -A 19 -B 1
    sleep 30
done

memory_global_by_current_bytesあたりを参照しておけばスレッドごとのメモリ使用量を知ることができる。show engine innodb statusでMEMORYのセクションを見ればページの状況がわかるのでどの機能でどれくらい使っていたかを知ることができる。

あとはMySQLのバグレポートとかで機能名+memory leakとかで調べてみると過去に事象があったりする