Measuring free space in InnoDB’s global tablespace
With innodb_file_per_table=1, InnoDB places every table’s data and indexes in a separate .ibd file, but there is still a “global” system tablespace, stored by default in a file named ibdata1. This contains some of each table’s data, such as the undo log and insert buffer. If it is fixed-size, you can fill it up and crash the server, as I’ve mentioned in a few recent blog posts.
In older versions of MySQL, the SHOW TABLE STATUS command showed the amount of space free in the tablespace as an entry in the Comment column. If you weren’t using innodb_file_per_table, you could use this to see how full your tablespace was.
The servers I’m managing use innodb_file_per_table=1, so I thought perhaps I can find out how full the system tablespace is by disabling innodb_file_per_table, creating a table, and enabling it again. This quickly reminded me that the setting is global only, not per-connection. It would be nice to have more flexibility for that option.
But then I discovered that it didn’t work anyway. My new table, created in the system tablespace instead of in its own file, doesn’t show anything in the Comment column. And the INFORMATION_SCHEMA.TABLESPACES table appears to be a stub; it is empty and the docs say nothing meaningful about it.
Are there any other options for measuring the space usage in the tablespace? I’d rather do this within the server itself than use an external tool like xtrabackup.



AFAIK:
INFORMATION_SCHEMA.TABLESPACES is used by NDB
Justin Swanhart
7 Sep 12 at 10:45 am
You can use the InnoDB tablespace monitor if you don’t want to use an external tool like Xtrabackup.
#1 Pick a table that is in the central tablespace.
#2 Create the following table in the test database:
create table innodb_tablespace_monitor(c1 int) engine=innodb;
#3 select * from selected_table limit 1;
#4 drop table test.innodb_tablespace_monitor;
#5 examine your error log
http://dev.mysql.com/doc/refman/5.5/en/innodb-monitors.html#innodb-tablespace-monitor
Justin Swanhart
7 Sep 12 at 10:56 am
This sounds like it might give you the info you’re after:
http://dev.mysql.com/doc/refman/5.5/en/innodb-monitors.html#innodb-tablespace-monitor
AussieDan
7 Sep 12 at 11:06 am
I’d completely forgotten the tablespace monitor. (Now I forget what’s actually IN it.) Thanks Dan and Justin!
Xaprb
7 Sep 12 at 2:14 pm
InnoDB shows free space in the data_free column since early versions of 5.1. So this won’t show up in the Comment field on any recent version.
Andrew
7 Sep 12 at 7:06 pm
Thanks Andrew! That’s too obvious. They should make it harder to find.
Xaprb
7 Sep 12 at 9:00 pm
Andrew, the data_free column doesn’t show the free space in the “global” system tablespace (ibdata) or I don’t really understand what do you mean…
Cédric
10 Sep 12 at 10:40 am