When calculating the size of a table in an Oracle database, it is incorrect to just look at the data size. It is necessary to calculate the size of the index, lobsegment and lobindex objects of the table. Because when we move the table to another database, all objects belonging to the table will also be moved.
The following query can be used to calculate the actual size of all tables in a schema. You must write the user/schema name you want to calculate instead of the “YOUR_USER/SCHEMA_NAME” section in the query.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | SELECT owner, table_name, TRUNC(sum(bytes)/1024/1024) MB FROM (SELECT segment_name table_name, owner, bytes FROM dba_segments WHERE segment_type in ('TABLE','TABLE SUBPARTITION','TABLE PARTITION') UNION ALL SELECT i.table_name, i.owner, s.bytes FROM dba_indexes i, dba_segments s WHERE s.segment_name = i.index_name AND s.owner = i.owner AND s.segment_type in ('INDEX','INDEX SUBPARTITION','INDEX PARTITION') UNION ALL SELECT l.table_name, l.owner, s.bytes FROM dba_lobs l, dba_segments s WHERE s.segment_name = l.segment_name AND s.owner = l.owner AND s.segment_type = 'LOBSEGMENT' UNION ALL SELECT l.table_name, l.owner, s.bytes FROM dba_lobs l, dba_segments s WHERE s.segment_name = l.index_name AND s.owner = l.owner AND s.segment_type = 'LOBINDEX') WHERE owner in UPPER('YOUR_USER/SCHEMA_NAME') GROUP BY table_name, owner ORDER BY SUM(bytes) desc; |