Query to check table size in Oracle

Last updated on July 27th, 2019 at 05:53 pm

We often need to find out how big is that particular oracle table. Suppose you did huge data load and want to know the oracle table size. We can use below Query to check table size in Oracle

For oracle table size in MB

select
owner as "Schema"
, segment_name as "Object Name"
, segment_type as "Object Type"
, round(bytes/1024/1024,2) as "Object Size (Mb)"
, tablespace_name as "Tablespace"
from dba_segments
where segment_name=’<table_name>’;

For oracle table size in GB

select
owner as "Schema"
, segment_name as "Object Name"
, segment_type as "Object Type"
, round(bytes/1024/1024/1024,2) as "Object Size (Mb)"
, tablespace_name as "Tablespace"
from dba_segments
where segment_name=’<table_name>’;

If you dont have access to dba_segments ,then you can use user_segments also

For size in MB

select segment_name as "Object Name"
, segment_type as "Object Type"
, round(bytes/1024/1024,2) as "Object Size (Mb)"
, tablespace_name as "Tablespace"
from user_segments
where segment_name=’<table_name>’;

For size in GB

select
segment_name as "Object Name"
, segment_type as "Object Type"
, round(bytes/1024/1024/1024,2) as "Object Size (Mb)"
, tablespace_name as "Tablespace"
from user_segments
where segment_name=’<table_name>’;

we can also use this query to find the top ten biggest table in particular table or particular schema

Top 10 big tables in Particular schema

select * from (select
owner as "Schema"
, segment_name as "Object Name"
, segment_type as "Object Type"
, round(bytes/1024/1024/1024,2) as "Object Size (Mb)"
, tablespace_name as "Tablespace"
from dba_segments
where owner=’<schema>’  and segment_type='TABLE' order by 4 desc)  where rownum < 11;

Top 10 big tables in Particular tablespace

select * from (select
owner as "Schema"
, segment_name as "Object Name"
, segment_type as "Object Type"
, round(bytes/1024/1024/1024,2) as "Object Size (Mb)"
, tablespace_name as "Tablespace"
from dba_segments
where tablespace_name =’<tablespace name>' and segment_name='TABLE' order by 4 desc ) where rownum <11;

Here is the query if you want to know space associated with the indexes on the table also

with tables
as
(
select segment_name tname, to_char(bytes/1024/1024,'999,999.99') table_size
from user_segments
where segment_type = 'TABLE'
and segment_name not like 'BIN%'
),
indexes
as
(
select table_name, index_name, scbp, rn,
(select to_char(bytes/1024/1024,'999,999.99') from user_segments where segment_name = INDEX_NAME and segment_type = 'INDEX') index_size
from (
select table_name, index_name,
substr( max(sys_connect_by_path( column_name, ', ' )), 3) scbp,
row_number() over (partition by table_name order by index_name) rn
from user_ind_columns
start with column_position = 1
connect by prior table_name = table_name
and prior index_name = index_name
and prior column_position+1 = column_position
group by table_name, index_name
)
)
select decode( nvl(rn,1), 1, tables.tname ) tname,
decode( nvl(rn,1), 1, tables.table_size ) table_size,
rn "INDEX#",
indexes.scbp,
indexes.index_name,
indexes.index_size
from tables, indexes
where tables.tname = indexes.table_name(+)
and tables.tname = '&1'
order by tables.tname, indexes.rn
/

Hope you like this article on Query to check table size in Oracle

Related Articles

Tablespace Name ,Size ,Free space,datafiles ,growth in Oracle Database

How to Alter Table in Oracle

Oracle Create table Syntax,Tip and Examples

How to Alter Table in Oracle

How to alter table add column oracle

asktom question

Leave a Reply