ITPub博客

首页 > 数据库 > Oracle > 回收InnoDB表空间

回收InnoDB表空间

原创 Oracle 作者:幕南风 时间:2014-07-03 14:23:58 0 删除 编辑

以下论述均假定innodb_file_per_table开启

先用常规optimize回收:

mysql> select count(*) from t;
+----------+
| count(*) |
+----------+
|  1200096 |
+----------+

[mysql@even employees]$ ls -alh t.ibd
-rw-rw---- 1 mysql dba 72M 10-08 17:39 t.ibd

mysql> delete from t limit 800000;

mysql> select count(*) from t;
+----------+
| count(*) |
+----------+
|   400096 |
+----------+

[mysql@even employees]$ ls -alh t.ibd
-rw-rw---- 1 mysql dba 72M 10-08 17:41 t.ibd


mysql> optimize table t;
+-------------+----------+----------+-------------------------------------------------------------------+
| Table       | Op       | Msg_type | Msg_text                                                          |
+-------------+----------+----------+-------------------------------------------------------------------+
| employees.t | optimize | note     | Table does not support optimize, doing recreate + analyze instead |
| employees.t | optimize | status   | OK                                                                |
+-------------+----------+----------+-------------------------------------------------------------------+

[mysql@even employees]$ ls -alh t.ibd
-rw-rw---- 1 mysql dba 29M 10-08 17:43 t.ibd



来看下这种方法的缺陷

mysql> show processlist;
+----+------+-----------+-----------+---------+------+-------------------+------------------+
| Id | User | Host      | db        | Command | Time | State             | Info             |
+----+------+-----------+-----------+---------+------+-------------------+------------------+
|  5 | root | localhost | NULL      | Query   |    0 | NULL              | show processlist |
|  6 | root | localhost | employees | Query   |   64 | copy to tmp table | optimize table t |
+----+------+-----------+-----------+---------+------+-------------------+------------------+

mysqladmin debug结果如下

Thread database.table_name          Locked/Waiting        Lock_type

6       employees.t                 Locked - read         Read lock without concurrent inserts

用optimize缺点显而易见:读锁,特别当你有大表时性能恐怕会深受影响
这里推荐使用percona公司:pt-online-schema-change,避免加锁

$ pt-online-schema-change -uroot -poracle --alter "ENGINE=InnoDB" D=employees,t=t --execute

执行pt工具时有可能发生的类似错误:

Cannot chunk the original table  There is no good index and the table is oversized

这是因为被作用的表需要含有主键或者唯一索引,这或许也能成为这款工具的小bug吧


参考文章:
http://hidba.org/?p=795
http://www.mysqlperformanceblog.com/2013/09/25/how-to-reclaim-space-in-innodb-when-innodb_file_per_table-is-on/


By 迦夜

2013-10-8

All life is a game of luck!

<!-- Baidu Button BEGIN -->

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/26515977/viewspace-1208312/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: 下厨房事故认识Linux文件句柄(fd)
下一篇: Oracle DG故障诊断一则:alter database recover to logical standby new_logical_dbname卡住
请登录后发表评论 登录
全部评论
腾讯数据库工程师

注册时间:2012-05-10

最新文章