Skip to main content

Size Of Table Or Database

MySQL

-- Whole database
SELECT table_schema AS "Database", CONCAT(ROUND(SUM(data_length + index_length) / 1024 / 1024), ' MB') AS "Size" FROM information_schema.TABLES GROUP BY table_schema


-- Table
SELECT
table_name AS `Table`,
CONCAT(ROUND(SUM(data_length + index_length) / 1024 / 1024), ' MB') AS "Size"
FROM
information_schema.TABLES
WHERE
table_schema = "farfalla"
AND table_name = "issues";


-- All tables
SELECT
table_schema AS `Database`,
table_name AS `Table`,
CONCAT(ROUND(((data_length + index_length) / 1024 / 1024), 2), ' MB') `Size`
FROM
information_schema.TABLES
WHERE
table_schema = "farfalla"
ORDER BY
(data_length + index_length)
DESC;


-- Data size and indexes size
SELECT
table_name AS "Table",
ROUND((data_length / 1024 / 1024), 2) AS "Data Size (MB)",
ROUND((index_length / 1024 / 1024), 2) AS "Index Size (MB)"
FROM
information_schema.TABLES
WHERE
table_schema = "farfalla"
ORDER BY
(data_length + index_length)
DESC;

PostgreSQl

-- Whole database
SELECT pg_size_pretty(pg_database_size('polpo')) AS "Size";


-- Table
SELECT pg_size_pretty(pg_total_relation_size('issues_text_content')) AS "Size";


-- All tables
SELECT
relname AS "relation",
pg_size_pretty (
pg_total_relation_size (C .oid)
) AS "total_size"
FROM
pg_class C
LEFT JOIN pg_namespace N ON (N.oid = C .relnamespace)
WHERE
nspname NOT IN (
'pg_catalog',
'information_schema'
)
AND C .relkind <> 'i'
AND nspname !~ '^pg_toast'
ORDER BY
pg_total_relation_size (C .oid) DESC
LIMIT 5;


-- A table's indexes
SELECT pg_size_pretty(pg_indexes_size('issues_text_content'));

Overview


X

Graph View