MySQL ran out of disk creating an index, now I can’t reclaim the disk

disk-spaceindexMySQLtemporary-tables

I've run a command on my MySQL database to add an index to a large table containing 8 million records (ironically so I could start deleting some of them):

CREATE INDEXindex_audit_logs_on_idONaudit_logs“

As part of that, MySQL will create a temporary table. I have 40GB of total disk, and this table is 25 GB, so I ran out of disk space while doing this. My commmand errored:


Mysql2::Error: The table '#sql-2b9f_2178' is full: CREATE INDEX `index_audit_logs_on_id` ON `audit_logs`

However, I am still out of disk space now!

/dev/sdc 40G 38G 20K 100% /var/lib/mysql

I don't see this temporary table. Is there something I can do to reclaim by 15GB of disk space?

Best Answer

CREATE INDEX

If the files #sql-2b9f_2178.* were left behind by the failed operation, rm them.

The CREATE INDEX was copying the table over to create the index. This is the new copy, before it is swapped into place.

Two important bits of info: What ENGINE is used for the table? What version of MySQL? There have been a number of changes in this area; I suspect you have an antique version and/or are using MyISAM. Recommend upgrading.

Deleting

Do you have any index on the table? If so, then the following blog has a number of techniques that may be viable for helping clean up the table: Big Deletes .

However, there may still be an issue of recovering disk space. So...

If the amount of data you need to keep is small enough to fit, then focus on this part of the blog: Deleting more than half a table .

Still, there may be a problem.

If MyISAM, no problem -- simply DROP the old table and RENAME TABLE.

If InnoDB, then you really need to be using innodb_file_per_table = ON. Set this globally, and re-login in order to get the value.

But... There may still be problems. We can continue this discussion after you have answered my questions.