With InnoDB, how can I claim back index space?

不羁的心 提交于 2019-12-13 17:10:50

问题


I have some large InnoDB databases, close to 1TB.

In order to free up some space while working on an alternative storage, I deleted some unused InnoDB indexes hoping that it would free up some space.

It freed nothing.

As it's InnoDB, will the engine use the empty allocated space for further inserts and indexing ?

Thanks


回答1:


InnoDB stores data in a tablespace. By default, there is one single tablespace and data of all the databases is stored in one file. This file has data dictionary, tables, as well as indexes in it. There is a global parameter innodb_data_file_path that defines this tablespace file. It has a syntax like ibdata1:256M:autoextend, this means at the beginning a file of size 256 MB will be created and then whenever the data size exceeds this, the file will be auto-extended. The innodb_autoextend_increment variable defines in MB's that by how much each increment should be.

How you will get your Index Space?

You should first backup all InnoDB tables and change setting in my.ini/my.cnf as innodb_file_per_table and restart MySQL server. Now import those tables now each table will have it's own tablespace which can shrink size on deleting a table.

These are possible workarounds:

  • Separate Files per Table: InnoDB provides this option where data (data + indexes) for each table can be stored in a separate file through a global variable innodb_file_per_table.
  • Fixed Tablespace size: One way to work around with the tablespace file size problems is to fix the tablespace size (remove autoextend) to an extrapolated value. So, when you hit the limit, you know it is time to cleanup.
  • Move to MyISAM: For all the tables (or even databases), for which you feel data is not that critical to have transactions et al, move them to MyISAM.



回答2:


Answer here: https://stackoverflow.com/a/8932289/82114

If you don't use innodb_file_per_table, reclaiming disk space is possible, but quite tedious, and requires a significant amount of downtime.

The "How To" can be found here: http://dev.mysql.com/doc/refman/5.6/en/innodb-data-log-reconfiguration.html

Be sure to also retain a copy of your schema in your dump.

Currently, you cannot remove a data file from the system tablespace. To decrease the system tablespace size, use this procedure:

Use mysqldump to dump all your InnoDB tables.

Stop the server.

Remove all the existing tablespace files, including the ibdata and ib_log files. If you want to keep a backup copy of the information, then copy all the ib* files to another location before the removing the files in your MySQL installation.

Remove any .frm files for InnoDB tables.

Configure a new tablespace.

Restart the server.

Import the dump files.




回答3:


You should reorganize the InnoDB infrastructure. Why? Because ibdata1 never shrinks. With innodb_file_per_table disabled, it will bloat ibdata1 in a hurry? Aside from data and indexes, what lives in ibdata1?

  • Data dictionary
  • Double write buffer (handles Background Page Writes)
  • Insert Buffer (andles Changes to Secondary Indexes)
  • Rollback Segments
  • Undo Tablespace

That being said, you need to migrate your data out, delete all InnoDB relayed files, and reload with two things:

  • innodb_file_per_table enabled
  • bigger transaction logs

I wrote up how to do this back on Oct 29, 2010 : Howto: Clean a mysql InnoDB storage engine?

Going forward you could alwsy shrink individual InnoDB tables. For example, to shrink mydb.mytable:

ALTER TABLE mydb.mytable ENGINE=InnoDB;


来源:https://stackoverflow.com/questions/11751792/with-innodb-how-can-i-claim-back-index-space

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!