Skip to content

PopSQL: limited support.

Migrate now →

Largest tables and their free space

Data, index and reclaimable space per table. A large data_free is fragmentation an OPTIMIZE TABLE would recover.

MySQL · SQL
SELECT CONCAT(table_schema, '.', table_name) AS table_name,
       table_rows AS estimated_rows,
       ROUND((data_length + index_length) / 1048576, 1) AS total_mb,
       ROUND(data_length / 1048576, 1) AS data_mb,
       ROUND(index_length / 1048576, 1) AS index_mb,
       ROUND(data_free / 1048576, 1) AS free_mb
FROM information_schema.tables
WHERE table_schema NOT IN ('mysql', 'information_schema', 'performance_schema', 'sys')
  AND table_type = 'BASE TABLE'
ORDER BY (data_length + index_length) DESC
LIMIT 25

This query is part of the "MySQL health" pack: connect the database in DataRunner and install the whole pack — queries, dashboard and checks — at once.