I inherited a MySQL InnoDB table that has approximately 200 GB worth of data, as well as several unneeded indices that amount to approximately 500 GB. I've archived approximately 75 percent of the records off site and DELETED the records from my table, and would like to reclaim the space in the table. I'd like to know if I am going to need about 200 GB of free space in order to reclaim the space, or closer to 700 GB.

innodb_file_per_table is on.

MySQL version is 5.5.

And I am considering either running OPTIMIZE TABLE (eg Recover the disk space after deleting rows from table) or using Percona Toolkit's online schema change (eg http://www.percona.com/blog/2013/09/25/how-to-reclaim-space-in-innodb-when-innodb_file_per_table-is-on/). I'd prefer to do the later, because I can avoid write locks, but I'd use OPTIMIZE TABLE if there was a considerable space difference required.

Will I need closer to 200 gb or close to 700 gb of free space in order to reclaim space from InnoDB? If closer to 700GB, would that answer be any different if I first converted the table to MyISAM (eg http://www.percona.com/blog/2014/08/21/the-mysql-ibdata1-disk-space-issue-and-big-tables-part-1/)?

Thank you for your help!

1 Answer 1



SELECT FORMAT(SUM(data_length+index_length)/POWER(1024,3),2) InnoDB_DiskSpace
FROM information_schema.tables
WHERE engine='InnoDB';


    IFNULL(tbl,'Total') table_name,
    FORMAT(SUM(table_bytes)/POWER(1024,3),2) table_size
    SELECT table_name tbl,SUM(data_length+index_length)table_bytes
    FROM information_schema.tables WHERE table_schema='mydb
    GROUP BY table_name WITH ROLLUP
) A ORDER BY ISNULL(tbl) DESC,table_bytes;


SELECT FORMAT(SUM(data_length+index_length)/POWER(1024,3),2) Table_Diskspace
FROM information_schema.tables
WHERE table_schema='mydb;
AND table_name='mytable';

These queries will tell you how much space you need for any table, database, and engine.


If you would like to simulate OPTIMIZE TABLE just to see diskspace usage, you run the following steps on mydb.mytable

use mydb
CREATE TABLE mytable_new LIKE mytable;
INSERT INTO mytable_new SELECT * FROM mytable;
ANALYZE TABLE mytable_new;
SELECT FORMAT(SUM(data_length+index_length)/POWER(1024,3),2) Table_Diskspace
FROM information_schema.tables
WHERE table_schema='mydb;
AND table_name='mytable_new';
# Stop Here. If you are happy with the size, do the last two commands
# If you prefer, drop table mytable_new and do do the online schema change
RENAME TABLE mytable TO mytable_old,mytable_newTO mytable;
DROP TABLE mytable_old;

Doing this can give an idea who big the .ibd file will be after running OPTIMIZE TABLE.


Please do not convert the table to MyISAM. It will be building two files (.MYD and .MYI). Then, you try to converting to InnoDB again. It is essentially the same as doing #SUGGESTION #1. MyISAM is also a little more prone to corruption with no recovery processes in place.


By all means, you can proceed with pt-online-schema-change if your data is live. My answer simply gives you queries to estimate sizes of the tables and approximate temp table sizes for OPTIMIZE TABLE.

If you are doing this during off hours, try my post Recover the disk space after deleting rows from table


  • 1
    Hi Rolando, thanks for this detailed explanation. My concern is I'd really like to estimate how much space I'm going to need to pull this change off before actually using up that much space. The current table takes up about 700GB. I've deleted about 75 percent of the records. If I have 500 GB of free space, will that be enough? Or could it use all 700 gb before it manages to reclaim the space of the deleted records? Commented Nov 23, 2014 at 2:09
  • 1
    My answer gives you an idea how big a table will be during and after OPTIMIZE TABLE. Just try the queries on a couple of midsize tables that need shrinking. If the temp tables have a good size, then my queries will accurate predict how much space you will need. Commented Nov 23, 2014 at 2:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.