How to get the storage space of a table in the MariaDB MyRocks storage engine

1.1k views Asked by At

I'm trying to get the space that a table using the MyRocks storage engine takes on disk and I'm getting inconsistent results between what I expect, a query on information_schema and the size as reported by the OS.

To get the size as reported by MariaDB, I'm using the following select statement:

select table_name 'Table Name',
      (data_length+index_length)/power(1024,3) 'Table Size in GB' 
from information_schema.tables where table_schema="MyTableName";

Which returns a really small number for what I'm doing, to the point where I'm doubtful that it's reporting the actual size (0.4GB for 4 000 000 rows with a lot of text).

If I run the command du -h /var/lib/mysql/#rocksdb/, I'm getting a disk size of 2.4GB, which is a bit more than what I would expect. However, if I understand correctly, MyRocks compacts data as data is inserted, so it's possible that the disk space reported by the du command is unrepresentative of the actual table size.

So, is there a reliable method to get the size of a table? Am I already using the correct way to get the table size?

1

There are 1 answers

5
Lukasz Szozda On

It looks like you need to use POWER(1024,3) instead of POWER(2014,3) assuming that storage engine is MyISAM:

select table_name AS `Table Name`,
      (data_length+index_length)/power(1024,3) AS `Table Size in GB` 
from information_schema.tables 
where table_schema='MyTableName';

And calculation:

(data_length+index_length)/(2014*2014*2014) = 0.4
=> 
(data_length+index_length) = 3267671497,6

3267671497,6/(1024*1024*1024) = 3.04GB

DATA_LENGTH

For MyISAM, DATA_LENGTH is the length of the data file, in bytes.

For InnoDB, DATA_LENGTH is the approximate amount of memory allocated for the clustered index, in bytes. Specifically, it is the clustered index size, in pages, multiplied by the InnoDB page size.)