zoukankan      html  css  js  c++  java
  • Bash script: report largest InnoDB files

    The following script will report the largest InnoDB tables under the data directory: schema, table & length in bytes. The tables could be non-partitioned, in which case this is simply the size of the corresponding .ibd file, or they can be partitioned, in which case the reported size is the sum of all partition files. It is assumed tables reside in their own tablespace files, i.e. created with innodb_file_per_table=1.

     1 (
     2     mysql_datadir=$(grep datadir /etc/my.cnf | cut -d "=" -f 2)
     3     cd $mysql_datadir
     4     for frm_file in $(find . -name "*.frm")
     5     do
     6         tbl_file=${frm_file//.frm/.ibd}
     7         table_schema=$(echo $frm_file | cut -d "/" -f 2)
     8         table_name=$(echo $frm_file | cut -d "/" -f 3 | cut -d "." -f 1)
     9         if [ -f $tbl_file ]
    10         then
    11             # unpartitioned table
    12             file_size=$(du -cb $tbl_file 2> /dev/null | tail -n 1) 
    13         else
    14             # attempt partitioned innodb table
    15             tbl_file_partitioned=${frm_file//.frm/#*.ibd}
    16             file_size=$(du -cb $tbl_file_partitioned 2> /dev/null | tail -n 1)
    17         fi
    18         file_size=${file_size//total/}
    19         # Replace the below with whatever action you want to take,
    20         # for example, push the values into graphite.
    21         echo $file_size $table_schema $table_name
    22     done
    23 ) | sort -k 1 -nr | head -n 20

    We use this to push table statistics to our graphite service; we keep an eye on table growth (we actually do not limit to top 20 but just monitor them all). File size does not report the real table data size (this can be smaller due to tablespace fragmentation). It does give the correct information if you're concerned about disk space. For table data we also monitor SHOW TABLE STATUS /INFORMATION_SCHEMA.TABLES, themselves being inaccurate. Gotta go by something.

    参考:

    http://code.openark.org/blog/mysql/bash-script-report-largest-innodb-files

  • 相关阅读:
    程序编译与代码优化 -- 早期(编译期)优化
    Java字节码指令
    知识点
    Openresty配置文件上传下载
    Openresty + nginx-upload-module支持文件上传
    G1日志分析
    Garbage First(G1)垃圾收集器
    Java内存分析工具jmap
    编译JDK1.7
    Java服务CPU占用高问题定位方法
  • 原文地址:https://www.cnblogs.com/xiaotengyi/p/3572650.html
Copyright © 2011-2022 走看看