Created
February 11, 2025 05:31
-
-
Save heathdutton/d5d51e2eee7538e3736868b40eaa56eb to your computer and use it in GitHub Desktop.
List the size of all tables on disk in MySQL/InnoDB/AuroraDB for the sake of finding resource hogs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- List the disk size of all tables and partitions in MySQL/InnoDB. | |
SELECT | |
isp.Schema, | |
isp.Table, | |
isp.Partition, | |
ROUND(isit.size / 1e+6) AS 'MB', | |
ROUND(isit.size / 1e+9) AS 'GB', | |
ROUND(isit.size / 1.1e+12, 2) AS 'TiB', | |
isit.File | |
FROM ( | |
SELECT | |
TABLE_SCHEMA AS 'Schema', | |
TABLE_NAME AS 'Table', | |
PARTITION_NAME AS 'Partition', | |
SUM(DATA_LENGTH + INDEX_LENGTH) AS size | |
FROM INFORMATION_SCHEMA.PARTITIONS | |
GROUP BY TABLE_SCHEMA, TABLE_NAME, PARTITION_NAME | |
) isp | |
RIGHT JOIN ( | |
SELECT | |
NAME AS 'File', | |
FILE_SIZE AS size | |
FROM INFORMATION_SCHEMA.INNODB_TABLESPACES | |
) isit | |
ON isit.File = CONCAT(isp.Schema, '/', isp.Table, IFNULL(CONCAT('#p#', isp.Partition), '')) | |
WHERE isit.size > 0 | |
ORDER BY isit.size DESC; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment