I have a table with about 600 million rows. I ran the following commands and noticed
select table_schema "DB name (table_schema)",
-> sum((data_length+index_length)/1024/1024/1024) AS "DB size in GB" from
-> information_schema.tables group by table_schema;
+------------------------+-------------------+
| DB name (table_schema) | DB size in GB |
+------------------------+-------------------+
| my_db | 4423.946937561025 |
+------------------------+-------------------+
The whole db is 4.4GB
The table with 600 million rows is:
+------------------------------------+-----------+
| Table | Size (MB) |
+------------------------------------+-----------+
| my_table | 3729084 |
So this table is 3.7TB in size.
I went to the file system and issued:
sudo du -hs * | sort -rh | head -5
11T my_table.ibd
My table is taking up 11TB in storage.
I ran the following command on the database:
SHOW VARIABLES LIKE 'innodb_file_per_table';
+-----------------------+-------+
| Variable_name | Value |
+-----------------------+-------+
| innodb_file_per_table | ON |
+-----------------------+-------+
1 row in set (0.01 sec)
So is it normal for an innodb file to be that large? If not, is there something that can be done to optimize its storage on disk?
I am running a master slave database:
sudo mysql –version
mysql Ver 14.14 Distrib 5.7.26, for Linux (x86_64) using EditLine wrapper
I am running this on an Ubuntu instance;
lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 16.04.5 LTS
Release: 16.04
Codename: xenial
Be gentle with your answers as managing mysql is new to me. I usually just write programs to read from mysql and haul the data to something like Elasticsearch or HBase for big data analytics.
Thank you…Amro
Best Answer
Of course, it never does.
In your case, you have about 66.67% fragmentation
I have wickedly good script you can run to calculate the fragmentation based on the difference between the
.ibd
filesize and the(data_length+index_length)
of the any table:You will have too run this script as the OS root user or another OS that has rights to read the
datadir
GIVE IT A TRY !!!
I wrote How to monitor mysql percentage disk utilization? like 6 years ago based on the same principles