How do I calculate tables size in Oracle
資料來源: 這裡
SELECT owner, table_name, TRUNC(SUM(tb_bytes) / 1024 / 1024) meg, TRUNC(SUM(idx_bytes) / 1024 / 1024) idx_meg, TRUNC(SUM(lob_bytes) / 1024 / 1024) lob_meg, TRUNC(SUM(lob_idx_bytes) / 1024 / 1024) lob_idx_meg FROM (SELECT segment_name table_name, owner, bytes tb_bytes, 0 idx_bytes, 0 lob_bytes, 0 lob_idx_bytes FROM dba_segments WHERE segment_type = 'TABLE' AND owner IN ('XX', 'APPS', 'GIB') UNION ALL SELECT i.table_name, i.owner, 0, s.bytes, 0, 0 FROM dba_indexes i, dba_segments s WHERE s.segment_name = i.index_name AND s.owner = i.owner AND s.segment_type = 'INDEX' AND i.owner IN ('XX', 'APPS', 'GIB') UNION ALL SELECT l.table_name, l.owner, 0, 0, s.bytes, 0 FROM dba_lobs l, dba_segments s WHERE s.segment_name = l.segment_name AND s.owner = l.owner AND s.segment_type = 'LOBSEGMENT' AND l.owner IN ('XX', 'APPS', 'GIB') UNION ALL SELECT l.table_name, l.owner, 0, 0, 0, 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' AND l.owner IN ('XX', 'APPS', 'GIB')) -- WHERE owner IN upper('&owner') GROUP BY table_name, owner HAVING SUM(tb_bytes) / 1024 / 1024 > 5 /* Ignore really small tables */ ORDER BY SUM(tb_bytes) DESC; |