How can I tell how big my Amazon RDS database (MySQL) is?

Here are more organized queries against the INFORMATION_SCHEMA

Sizes By Storage Engine

SELECT
    IFNULL(B.engine, 'Total') "Storage Engine",
    CONCAT(LPAD(REPLACE(FORMAT(B.DSize / POWER(1024, pw), 3), ',', ''), 17, ' '), ' ', SUBSTR(' KMGTP', pw + 1, 1), 'B') "Data Size",
    CONCAT(LPAD(REPLACE( FORMAT(B.ISize / POWER(1024, pw), 3), ',', ''), 17, ' '), ' ', SUBSTR(' KMGTP', pw + 1, 1), 'B') "Index Size",
    CONCAT(LPAD(REPLACE( FORMAT(B.TSize / POWER(1024, pw), 3), ',', ''), 17, ' '), ' ', SUBSTR(' KMGTP', pw + 1, 1), 'B') "Table Size" 
FROM
    (SELECT
            engine,
            SUM(data_length) DSize,
            SUM(index_length) ISize,
            SUM(data_length + index_length) TSize 
        FROM
            information_schema.tables 
        WHERE
            table_schema NOT IN ('mysql', 'information_schema', 'performance_schema')
            AND engine IS NOT NULL 
        GROUP BY engine WITH ROLLUP
    ) B,
    (SELECT 3 pw) A 
ORDER BY TSize;

Sizes By Database

SELECT
    dbname,
    Concat(Lpad(Format(sdsize / Power(1024, pw), 3), 17, ' '), ' ', Substr(' KMGTP', pw + 1, 1), 'B') "Data Size",
    Concat(Lpad(Format(sxsize / Power(1024, pw), 3), 17, ' '), ' ', Substr(' KMGTP', pw + 1, 1), 'B') "Index Size",
    Concat(Lpad(Format(stsize / Power(1024, pw), 3), 17, ' '), ' ', Substr(' KMGTP', pw + 1, 1), 'B') "Total Size" 
FROM
    (SELECT
            Ifnull(db, 'All Databases') DBName,
            Sum(dsize) SDSize,
            Sum(xsize) SXSize,
            Sum(tsize) STSize 
        FROM (SELECT
                    table_schema DB,
                    data_length DSize,
                    index_length XSize,
                    data_length + index_length TSize 
                FROM information_schema.tables 
                WHERE table_schema NOT IN ('mysql','information_schema','performance_schema')
            ) AAA 
        GROUP BY db WITH rollup
    ) AA,
    (SELECT 3 pw) BB 
ORDER BY ( sdsize + sxsize ); 

Sizes By Database/Storage Engine

SELECT
    Statistic,
    DataSize "Data Size",
    IndexSize "Index Size",
    TableSize "Table Size" 
FROM
    (SELECT
            IF(ISNULL(table_schema) = 1, 10, 0) schema_score,
            IF(ISNULL(engine) = 1, 10, 0) engine_score,
            IF(ISNULL(table_schema) = 1, 'ZZZZZZZZZZZZZZZZ', table_schema) schemaname,
            IF(ISNULL(B.table_schema) + ISNULL(B.engine) = 2, "Storage for All Databases", IF(ISNULL(B.table_schema) + ISNULL(B.engine) = 1, CONCAT("Storage for ", B.table_schema), CONCAT(B.engine, " Tables for ", B.table_schema))) Statistic,
            CONCAT(LPAD(REPLACE(FORMAT(B.DSize / POWER(1024, pw), 3), ',', ''), 17, ' '), ' ', SUBSTR(' KMGTP', pw + 1, 1), 'B') DataSize,
            CONCAT(LPAD(REPLACE( FORMAT(B.ISize / POWER(1024, pw), 3), ',', ''), 17, ' '), ' ', SUBSTR(' KMGTP', pw + 1, 1), 'B') IndexSize,
            CONCAT(LPAD(REPLACE(FORMAT(B.TSize / POWER(1024, pw), 3), ',', ''), 17, ' '), ' ', SUBSTR(' KMGTP', pw + 1, 1), 'B') TableSize 
        FROM
            (SELECT
                    table_schema,
                    engine,
                    SUM(data_length) DSize,
                    SUM(index_length) ISize,
                    SUM(data_length + index_length) TSize 
                FROM
                    information_schema.tables 
                WHERE
                    table_schema NOT IN ('mysql', 'information_schema', 'performance_schema')
                    AND engine IS NOT NULL 
                GROUP BY
                    table_schema, engine WITH ROLLUP
            ) B,
            (SELECT 3 pw) A
    ) AA 
ORDER BY schemaname, schema_score, engine_score;

CAVEAT

In each of the three(3) queries, you will see (SELECT 3 pw). The pw stands for the Power Of 1024 to display the results in specific units:

  • (SELECT 0 pw) will Display the Report in Bytes
  • (SELECT 1 pw) will Display the Report in KiloBytes
  • (SELECT 2 pw) will Display the Report in MegaBytes
  • (SELECT 3 pw) will Display the Report in GigaBytes
  • (SELECT 4 pw) will Display the Report in TeraBytes
  • (SELECT 5 pw) will Display the Report in PetaBytes (please contact me if you run this one)

Here is a report query with a little less formatting in KB:

SELECT
    IFNULL(db, 'Total') "Database",
    datsum / power(1024, pw) "Data Size",
    ndxsum / power(1024, pw) "Index Size",
    totsum / power(1024, pw) "Total" 
FROM
    (
        SELECT
            db,
            SUM(dat) datsum,
            SUM(ndx) ndxsum,
            SUM(dat + ndx) totsum 
        FROM
            (
                SELECT table_schema db, data_length dat, index_length ndx 
                FROM information_schema.tables 
                WHERE engine IS NOT NULL AND table_schema NOT IN ('information_schema', 'mysql')
            ) AA 
        GROUP BY db WITH ROLLUP
    ) A,
    (SELECT 1 pw) B;

Give it a Try !!!


I finally found the easy way to get this information directly from Amazon with a couple of clicks.

  1. Log into the RDS management dashboard
  2. Click on "DB Instances"
  3. Click on the instance in which you are interested. That should expand it and show much more info about it.
  4. View the "Monitoring" tab. enter image description here
  5. There is a "Free Storage Space" graph:

show table status from mydatabsename; where mydatabasename is your database name.

This shows you the metrics Data_length and Index_length per table and other metrics. You would have to total these columns and remember that they are in bytes so you would have to divide by 1024 to get kb and then by 1024 again to get megs and then by 1024 again to get gigs. This also shows the free space within your index/database allocation.

You can get more granular and sum() if you want to explore: http://dev.mysql.com/doc/refman/5.5/en/show-table-status.html

SELECT SUM(DATA_FREE) FROM INFORMATION_SCHEMA.PARTITIONS;

Shows remaining space in index/database allocation...

SELECT SUM(Data_length) FROM INFORMATION_SCHEMA.PARTITIONS;

SELECT SUM(Index_length) FROM INFORMATION_SCHEMA.PARTITIONS;

...shows data and index size used (you will have to add them for total allocation)

If you want to dissect things a bit more...

select sum(Data_length) from INFORMATION_SCHEMA.PARTITIONS where TABLE_SCHEMA = "myschema";

select sum(Index_length) from INFORMATION_SCHEMA.PARTITIONS where TABLE_SCHEMA = "myschema";

select sum(DATA_FREE) from INFORMATION_SCHEMA.PARTITIONS where TABLE_SCHEMA = "myschema";

select sum(Data_length) from INFORMATION_SCHEMA.PARTITIONS where TABLE_SCHEMA = "myschema" and TABLE_NAME = "aspecifictable";

select sum(Index_length) from INFORMATION_SCHEMA.PARTITIONS where TABLE_SCHEMA = "myschema" and TABLE_NAME = "aspecifictable";

Of course you can also use the MySQL Workbench like I do found here: http://dev.mysql.com/downloads/tools/workbench/ but that assumes you have port access to your database server. Still, you can do a lot offline too so worth the download. Please note that the workbench does not sum() allocations which does not make sense to me. But then again, I do not have the latest version either.