List the largest tables / collections
Oracle
SELECT segment_name, segment_type,
ROUND(bytes/1024/1024, 1) AS mb
FROM dba_segments
WHERE segment_type IN ('TABLE','TABLE PARTITION')
ORDER BY bytes DESC
FETCH FIRST 10 ROWS ONLY;Remove the segment_type filter to see indexes as well.
PostgreSQL
SELECT relname AS table,
pg_size_pretty(pg_total_relation_size(relid)) AS total
FROM pg_catalog.pg_statio_user_tables
ORDER BY pg_total_relation_size(relid) DESC
LIMIT 10;pg_total_relation_size is the sum of table + indexes + TOAST; use pg_relation_size for the table only.
MySQL
SELECT table_name,
ROUND((data_length + index_length)/1024/1024, 1) AS mb
FROM information_schema.tables
WHERE table_schema = DATABASE()
ORDER BY (data_length + index_length) DESC
LIMIT 10;For a specific schema, use WHERE table_schema = 'name'.
SQL Server
SELECT TOP 10 OBJECT_NAME(object_id) AS table_name,
SUM(reserved_page_count) * 8 / 1024 AS mb
FROM sys.dm_db_partition_stats
GROUP BY object_id
ORDER BY mb DESC;reserved_page_count covers all reserved pages (data + indexes).
MongoDB
db.getCollectionNames()
.map(c => ({ name: c, mb: +(db[c].stats().storageSize/1048576).toFixed(1) }))
.sort((a, b) => b.mb - a.mb)
.slice(0, 10)storageSize is the compressed on-disk size. The cost of stats() is low even on large collections.
Redis
redis-cli --bigkeys
# To rank by memory (bytes): redis-cli --memkeysBoth scan the whole keyspace with SCAN (they do not block the server but add load); the difference is the metric: --bigkeys reports the largest keys by element count/length per type, --memkeys by memory consumption via MEMORY USAGE. For a single key use MEMORY USAGE <key>.