0

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.

3
  • show table status; ? Commented 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 James
    Commented 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
    – Bogdan
    Commented Apr 30, 2020 at 7:58

1 Answer 1

1

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;
5
  • 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).
    – danblack
    Commented 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.
    – Rick James
    Commented Apr 30, 2020 at 0:46
  • data_free needs to be added to get the disk space consumed.
    – Rick James
    Commented Apr 30, 2020 at 0:56
  • ok i added the information for DATA_FREE to the mix.
    – nbk
    Commented Apr 30, 2020 at 1:00
  • Thanks @RickJames good distinction. I'll look carefully before stating something similar again.
    – danblack
    Commented Apr 30, 2020 at 2:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.