Post

Oracle sort tables by size

Oracle sort tables by size

When a tablespace is filling up and you need to know what’s eating the space, this query is the first thing I run. It queries user_segments — which includes not just the table data but also indexes — and sorts by size descending. Usually one or two tables account for the majority of space.

  • Query is:
1
2
3
4
5
6
7

select segment_name, sum(bytes) / 1024 / 1024 / 1024 GB
from user_segments
where segment_type = 'TABLE'
group by segment_name
order by GB desc;

This post is licensed under CC BY 4.0 by the author.