Skip to content

Instantly share code, notes, and snippets.

@mehdip2007
Last active April 5, 2020 10:18
Show Gist options
  • Save mehdip2007/74752a40304657b2c3cbe7f88e4dc289 to your computer and use it in GitHub Desktop.
Save mehdip2007/74752a40304657b2c3cbe7f88e4dc289 to your computer and use it in GitHub Desktop.
Query table size including partitions, indexes
SELECT owner,
table_name,
TRUNC(sum(bytes)/1024/1024) Meg
FROM
(SELECT segment_name table_name,
owner,
bytes
FROM dba_segments
WHERE segment_type = 'TABLE'
UNION
all
SELECT segment_name table_name,
owner,
bytes
FROM dba_segments
WHERE segment_type = '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 = 'INDEX'
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 NOT IN ('SYS','OUTLN','SYSTEM','DBSNMP','APPQOSSYS','WMSYS','EXFSYS','CTXSYS','XDB','ORDSYS','ORDDATA','MDSYS' ,'OLAPSYS','SYSMAN','APEX_030200','FLOWS_FILES','SCOTT','OWBSYS')
GROUP BY table_name, owner
HAVING SUM(bytes)/1024/1024 > 800 /* Ignore really small tables */
ORDER BY SUM(bytes) desc;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment