A large MySQL association table with 500M rows recently ballooned into 1B rows due to a bug (now fixed). Disk usage went from ~130GB to 240GB.
Unfortunately there is not room on this server for any of the standard remedies (OPTIMIZE
or ALTER TABLE table ENGINE=InnoDB
, dump & rebuild, build into temporary table & rename & drop old table, etc.). I only have 50GB remaining.
Here's the question:
While I've successfully removed over 100M rows so far (1B down to 850M), disk usage has actually grown by 10GB (to 250GB). Yes, new records are also being added every second, but I'm deleting far faster than they are being added.
- Will InnoDB ever release this space?
- Why does the table disk usage
grow, while I'm shrinking the row count?
Any other advice to reclaim unused disk space when the regular solutions don't fit?
Best Answer
InnoDB tablespace size for individual tables (
.ibd
) can be reduced withOPTIMIZE
andALTER TABLE ... ENGINE=InnoDB;
, but the system tablespace fileibdata1
can be never be shrunk.The source of ibdata1's growth in in the undo logs.
I have written posts about this since July 2013. I first learned about this phenomenon from Percona's post Reasons for run-away main Innodb Tablespace.
Suggestion #1
If you mysqldump the data into another server running mysql in a newly installed instance, you could setup replication to it, then failover and trash the old master.
Suggestion #2
If you do not have another server, you'll have stop the application, mysqldump the data, drop all DBs, shutdown mysql, delete ibdata1, start mysql (which recreates ibdata1, reload the mysqldump). See my very old post Howto: Clean a mysql InnoDB storage engine?