Is it possible in MySQL / MariaDB to calculate row size like in PostgreSQL ? I'm looking to calculate in a multi tenant application how much space did the user use for the database but I couldn't find anything relevant about this.
-
show table status; ?– NikitaSerbskiyCommented Apr 24, 2020 at 8:36
-
Do you want "row size"? Or "table size"? Or maybe the entire database, if each tenant has his own database?– Rick JamesCommented Apr 30, 2020 at 0:57
-
Yes Rick, row size then I will need the entire database and table size. :D been looking into this for a week by now. :D– BogdanCommented Apr 30, 2020 at 7:58
Add a comment
|
1 Answer
In phpmyadmin you see the size of every table at the end . after you select a database.
if you want to do this in a query do, you need only the put in your own database name instead of testdb
SELECT SUM(Table_Size_MB) 'database_size_MB'
FROM
(SELECT table_name AS "Table",
ROUND(((data_length + index_length + DATA_FREE) / 1024 / 1024), 2) AS "Table_Size_MB"
FROM information_schema.TABLES
WHERE table_schema = "testdb"
ORDER BY (data_length + index_length) DESC) tablessizes;
-
data_length only includes the clusterd index so this excludes blob sizes and text that aren't stored in the table row (after a size of a few K - exact number is an exercise for the reader).– danblackCommented Apr 24, 2020 at 23:56
-
@danblack - I believe that is not true. data_length includes the clustered index (
PRIMARY KEY
) and all the data for the rows. However, the BTree containing the PK excludes the "off-record" big blobs/texts/varchars. Commented Apr 30, 2020 at 0:46 -
data_free
needs to be added to get the disk space consumed. Commented Apr 30, 2020 at 0:56 -
-
Thanks @RickJames good distinction. I'll look carefully before stating something similar again.– danblackCommented Apr 30, 2020 at 2:38