首页 > 数据库技术 > 详细

Bash script: report largest InnoDB files

时间:2014-02-28 18:39:55      阅读:506      评论:0      收藏:0      [点我收藏+]

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.

bubuko.com,布布扣
 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
bubuko.com,布布扣

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

Bash script: report largest InnoDB files,布布扣,bubuko.com

Bash script: report largest InnoDB files

原文:http://www.cnblogs.com/xiaotengyi/p/3572650.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!