-
-
Save daohoan122/5fc235a731602ae9650b81ef65f9a9dd to your computer and use it in GitHub Desktop.
calculating 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 | |
FROM | |
(SELECT segment_name table_name, owner, bytes | |
FROM dba_segments | |
WHERE segment_type = 'TABLE' | |
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 in UPPER('&owner') | |
GROUP BY table_name, owner | |
HAVING SUM(bytes)/1024/1024 > 10 /* Ignore really small tables */ | |
ORDER BY SUM(bytes) desc | |
; |
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
select owner ||'.' || table_name as table_name, | |
round((num_rows * avg_row_len)/1024/1024,2) as MB, | |
initial_Extent | |
from all_tables | |
where blocks is not null and not owner in ('SYS', 'SYSTEM') | |
order by MB desc |
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
select | |
round((t.num_rows * t.avg_row_len)/1024/1024,2) as MB, | |
round(((t.blocks - t.empty_blocks) * 8192)/1024/1024,2) as MB_BLOCKS, | |
t.num_rows as linhas, | |
'alter table ' ||t.owner || '.' || t.table_name || ' move storage(initial 64k next 64k pctincrease 0);' | |
from all_tables t | |
where t.blocks is not null and not owner in ('SYS', 'SYSTEM') | |
order by MB desc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment