Created
September 13, 2016 09:58
-
-
Save dev-brutus/f60d8f675879302c843189029505aac0 to your computer and use it in GitHub Desktop.
How do I calculate tables size in Oracle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
COLUMN TABLE_NAME FORMAT A32 | |
COLUMN OBJECT_NAME FORMAT A32 | |
COLUMN OWNER FORMAT A10 | |
SELECT | |
owner, | |
table_name, | |
TRUNC(sum(bytes)/1024/1024) Meg, | |
ROUND( ratio_to_report( sum(bytes) ) over () * 100) Percent | |
FROM | |
(SELECT segment_name table_name, owner, bytes | |
FROM dba_segments | |
WHERE segment_type IN ('TABLE', 'TABLE PARTITION', 'TABLE SUBPARTITION') | |
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 PARTITION', 'INDEX SUBPARTITION') | |
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 IN ('LOBSEGMENT', 'LOB PARTITION') | |
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('&owner') | |
GROUP BY table_name, owner | |
HAVING SUM(bytes)/1024/1024 > 10 /* 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
See http://stackoverflow.com/a/266964/2266681