我怎么知道我的Amazon RDS数据库(MySQL)有多大?


Answers:


13

这是针对INFORMATION_SCHEMA的更有条理的查询

存储引擎大小

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;

数据库大小

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 ); 

数据库/存储引擎的大小

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;

警告

在三个(3)查询中的每个查询中,您都会看到(SELECT 3 pw)。该pw代表电源1024来显示特定单位的结果:

  • (SELECT 0 pw) 将以字节显示报告
  • (SELECT 1 pw) 将以千字节为单位显示报告
  • (SELECT 2 pw) 将以兆字节显示报告
  • (SELECT 3 pw) 将以千兆字节显示报告
  • (SELECT 4 pw) 将以兆字节为单位显示报告
  • (SELECT 5 pw) 将以PetaBytes显示报告(如果运行此报告,请与我联系)

这是一个报表查询,其格式略有减少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;

试试看 !!!


你真棒!
Player1

7

我终于找到了简单的方法,只需单击几下即可直接从亚马逊获取此信息。

  1. 登录到RDS管理仪表板
  2. 点击“数据库实例”
  3. 单击您感兴趣的实例。那应该扩展它并显示更多有关它的信息。
  4. 查看左侧的“监视”标签(默认情况下应选中)
  5. 有一个“存储”监视器,它可以显示已使用的空间并显示可用空间的图表:

在此处输入图片说明


从RDS文档,freeable内存是“多少RAM,可用的数据库实例,以MB为单位”,而不是实例的存储使用率:docs.aws.amazon.com/AmazonRDS/latest/UserGuide/...
埃文Kroske

@EvanKroske看起来“可用存储空间”实际上是我想要的指标。感谢您的文档链接。
Stephen Ostermiller

自从我编写此答案以来,AWS似乎已经对整个界面进行了改进。我已经根据我今天看到的内容对其进行了更新。
Stephen Ostermiller

看来他们可能已经对其进行了改进,但我没有看到“监视”选项卡。并且存储仅列出分配的总大小。
布赖恩·托马斯

2

show table status from mydatabsename; 其中mydatabasename是您的数据库名称。

这将显示每个表的指标Data_length和Index_length以及其他指标。您必须总计这些列,并记住它们以字节为单位,因此您必须除以1024以获取kb,然后再除以1024以获取兆,然后再除以1024以获取gig。这也显示了索引/数据库分配中的可用空间。

如果您想探索,可以得到更详细的信息和sum():http : //dev.mysql.com/doc/refman/5.5/en/show-table-status.html

SELECT SUM(DATA_FREE) FROM INFORMATION_SCHEMA.PARTITIONS;

显示索引/数据库分配中的剩余空间...

SELECT SUM(Data_length) FROM INFORMATION_SCHEMA.PARTITIONS;

SELECT SUM(Index_length) FROM INFORMATION_SCHEMA.PARTITIONS;

...显示使用的数据和索引大小(您必须添加它们以进行总分配)

如果您想进一步剖析...

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";

当然,您也可以像我在这里找到的那​​样使用MySQL Workbench:http//dev.mysql.com/downloads/tools/workbench/,但这假定您具有对数据库服务器的端口访问权限。不过,您也可以离线进行很多操作,因此值得下载。请注意,工作台不会对我没有意义的sum()分配。但是话又说回来,我也没有最新版本。


我在这个RDS实例中有100多个数据库。是否有一种方便的方法来查询所有查询并汇总所有内容?
斯蒂芬Ostermiller

@Stephen Ostermiller 100个数据库或100个表?数据库由一个或多个模式组成。模式通常是带有相关表的主题区域。
closetnoc

100个数据库,每个数据库约有20个表。
斯蒂芬Ostermiller

我正在尝试我所引用的页面上的示例...将在几秒钟内回复您。
closetnoc

@Stephen Ostermiller更新了答案。希望这可以帮助。
closetnoc

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.