Bug #1287 | Innodb database file ibdata1 never shrinks after data is removed | ||
---|---|---|---|
Submitted: | 15 Sep 2003 18:54 | Modified: | 12 Jul 2004 13:51 |
Reporter: | Scott Ellsworth | Email Updates: | |
Status: | Not a Bug | Impact on me: | |
Category: | MySQL Server: InnoDB storage engine | Severity: | S1 (Critical) |
Version: | 4.0.14 | OS: | MacOS (MacOS X, Win2k, RH Linux 8 and 9) |
Assigned to: | CPU Architecture: | Any |
[15 Sep 2003 18:54]
Scott Ellsworth
[18 Sep 2003 12:11]
Alexander Keremidarski
Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.mysql.com/documentation/ and the instructions on how to report a bug at http://bugs.mysql.com/how-to-report.php The fact that InnoDB tablespaces can only grow and never shrink is docummented design decision. Like with every other storage management system it is arguable if auto-shrink is wise decision as space can be reused in future. In any case this issue can be only qualified as Feature Request, but not as Bug.
[18 Sep 2003 12:28]
Scott Ellsworth
Where is this documented? I scanned through "file space usage", but the closest I saw was mention of "When you delete data from a table, InnoDB will contract the corresponding B-tree indexes." and a warning about rows not being deleted. This is a real problem when database sizes change, since the ONLY way to fix it is to dump every other innodb table in every other database, physically delete the ibdata1 file, and then restore. This is not pretty. This sure seems like a bug to me, even if it was a design decision. Any case where the user has to go through a laborious process involving root privs is a pain. Scott
[18 Sep 2003 12:44]
Paul DuBois
InnoDB tablespace configuration is covered at: http://www.mysql.com/doc/en/InnoDB_start.html Note that for every file that is part of the tablespace, you must specify a size. When the tablespace is initialized for the first time, each file is allocated to the size specified. The only change in size that may occur thereafter is that the final file named in the table specification may grow if it has the autoextend attribute. Preallocation of tablespace files makes for better performance. By the way, though I am not certain about this, your initial report seems to imply that you believe that InnoDB doesn't allocate space until you load data into your tables. That is not true. It allocates it the first time the server starts up and initializes the tablespace.
[18 Sep 2003 12:53]
Paul DuBois
By the way, it is not necessary to have root privileges to reconfigure the InnoDB tablespace or remove the InnoDB tablespace files. Those operations can be done from the account that is used for running the server.
[18 Sep 2003 13:22]
Scott Ellsworth
The documentation you point to does describe the pre-allocation of tables. It also states what happens as tablespace grows. It is silent on whether tablespace will eventually be recovered and returned to the OS. I was aware that innodb allocates space for its tables at startup, and that preallocation of your expected usage is key to decent performance. That said, if one has usage spikes where tablespace used is double, triple, or two orders of magnitude above the normal usage, then innodb will expand to suit. This is a good feature. What I would like is a means to cause it to decrease again to a size more appropriate for regular usage. I have logins disabled for the mysql user in the name of security. I suppose I could allow sudo in its name, which does make me less worried about root exploits. Scott
[18 Sep 2003 13:36]
Scott Ellsworth
Since this is likely to end up treated as a freq, I have opened freq 1341 to cover this. I would still like it to be treated as a bug, but I understand your point of view and appreciate the comments. Scott
[12 Jul 2004 6:40]
Harsh Parekh
We also faced the similar thing at our place. We are developing a product which supports databases like MS SQL and MySQL. We are developing an archive feature to reduce backup size of working database. MS SQL does shrink nicely. But MySQL (as mentioned by scott in detail) is really a pain for us. I strongly feel it is a bad design of InnoDB though performance was in your mind. - Paresh
[12 Jul 2004 13:51]
Heikki Tuuri
Hi! If you use MySQL-4.1.3, define innodb_file_per_table in my.cnf, and do OPTIMIZE TABLE, the operating system will get the disk space back. That is because the table is stored in its own .ibd file, and OPTIMIZE will rebuild the whole table to another .ibd file, rename the .ibd file, and delete the old .ibd file. Regards, Heikki
[3 Nov 2005 15:06]
Justin Vassallo
Hi, once the file per table option is enabled, i am still stuck with a large ibdata file. was this issue resolved with release 5.0? Cheers J
[27 May 2009 13:44]
Wes Grant
Heikki, That is interesting. I wonder why that directive isn't set by default then. Thanks for the information!
[5 Jun 2009 6:02]
lalit bahuguna
Hi experts... As per the status, this is not a bug. I am facing the same problem. I am running mysql on solaris 10 box, with mysql version 4.0. I have few table, the data on 2-3 table can grow upto 500000-600000 entries. But one of my thread is watching the table entries every 5 min, and if found entries greater then the 500000, truncate the extra entries from the table. The problem is during the process, my ibdata size keep on increasing and ultimately rechaes to 45GB. My query is when I am deleting the entries, so that I am restricting the table entries to 500000 only, why my data size is not shrinking. I tried to delete entries from the mysql prompt also, but result is still same, lbdata is not reduces even a bit value. Can you please suggest me the steps or some reference doc which I have to follow before creating my database. Or is it a bug. Looking forword for a response from your side. Regards, Lalit
[15 Oct 2010 9:06]
Claudiu Cristea
I delete a database (the only one on this server) and I still have a huge /var/lib/mysql/ibdata1 there. The free space is not recovered. Can I delete that file through file system?
[24 Jan 2012 21:41]
gert redlich
January 2012 - Wiesbaden Germany - Hi, I did carefully read all the arguments, why this wasting of diskspace is (or should be) NOT a bug. Sorry, after evaluating a lot of databases within the last 20 years, it remains to be a design bug from innodb structure, to generate a 45 Gigabyte index from a total of some 150 megabyte datafiles. The very old DOS/Netware DATAFLEX did it perfectly better. The benefit in speed compared by myisam needed to be more than 10 : 1 to accept such a growth without a chance of resetting or reshrinking. And that is not true. As I see the first thread in 2003, now IT IS a BUG, that within almost 10 years there has not been written a simple CLI tool to solve that problem. What I did read above are workarounds around the main problem. Or is it a political issue ? G. Redlich Wiesbaden Germany
[25 Sep 2014 16:50]
James Day
Please see Bug #1341 for the related feature request and updates on what is happening in this area. This bug was closed as not a bug because it's working as designed, the other one covers the feature request to get it improved, so it's the one that will be most useful to you. James Day, MySQL Senior Principal Support Engineer, Oracle