1. 有兩種含義的表大小。一種是分配給一個表的物理空間數量,而不管空間是否被使用。可以這樣查詢獲得字節數:
方法一:
select t.owner,t.segment_name,t.tablespace_name,sum(bytes/1024/1024/1024) gb
from dba_segments t
where t.tablespace_name='&TBS_NAME'
group by t.owner,t.segment_name,t.tablespace_name
order by 4 desc;
或者
Select Segment_Name,Sum(bytes)/1024/1024 From User_Extents Group By Segment_Name
方法二:
select *
from (select t.owner,
t.segment_name,
round(table_bytes / 1024 / 1024 / 1024, 0) TAB_GB,
round(index_bytes / 1024 / 1024 / 1024, 0) IDX_GB
from (select OWNER, SEGMENT_NAME, bytes table_bytes
from dba_SEGMENTS
where segment_type = 'TABLE') t,
(select ui.table_name, sum(us.bytes) index_bytes
from dba_indexes ui, dba_segments us
where ui.index_name = us.segment_name
and us.segment_type = 'INDEX'
group by ui.table_name) i
where t.segment_name = i.table_name(+)
order by TAB_GB desc)
where rownum < 200;
方法三
另一種表實際使用的空間。這樣查詢:
analyze table emp compute statistics;
select num_rows * avg_row_len
from user_tables
where table_name = 'EMP';
2. 查看每個表空間的大小
Select Tablespace_Name,Sum(bytes)/1024/1024 From Dba_Segments Group By Tablespace_Name
3. 通過block查詢
-- Wasted space
select
table_name,
round(blocks*8/1024,2) as "size (MB)",
round(num_rows*avg_row_len/1024/1024,2) as "actual_data (MB)",
round(blocks*8/1024,2) - round(num_rows*avg_row_len/1024/1024,2) as "wasted_space (MB)"
from sys.user_tables
where round(blocks*8/1024,2) > round(num_rows*avg_row_len/1024/1024,2)
order by 4 desc
;
1.查詢oracle表空間的使用情況
select b.file_id 文件ID,
b.tablespace_name 表空間,
b.file_name 物理文件名,
b.bytes 總字節數,
(b.bytes-sum(nvl(a.bytes,0))) 已使用,
sum(nvl(a.bytes,0)) 剩餘,
sum(nvl(a.bytes,0))/(b.bytes)*100 剩餘百分比
from dba_free_space a,dba_data_files b
where a.file_id=b.file_id
group by b.tablespace_name,b.file_name,b.file_id,b.bytes
order by b.tablespace_name
2.查詢oracle系統用戶的默認表空間和臨時表空間
select default_tablespace,temporary_tablespace from dba_users
3.查詢單張表的使用情況
select segment_name,bytes from dba_segments where segment_name = 'RE_STDEVT_FACT_DAY' and owner = USER
RE_STDEVT_FACT_DAY是您要查詢的表名稱
4.查詢所有用戶表使用大小的前三十名
select * from (select segment_name,bytes from dba_segments where owner = USER order by bytes desc ) where rownum <= 30
5.查詢當前用戶默認表空間的使用情況
select tablespacename,sum(totalContent),sum(usecontent),sum(sparecontent),avg(sparepercent)
from
(
SELECT b.file_id as id,b.tablespace_name as tablespacename,b.bytes as totalContent,(b.bytes-sum(nvl(a.bytes,0))) as usecontent,sum(nvl(a.bytes,0)) as sparecontent,sum(nvl(a.bytes,0))/(b.bytes)*100 as sparepercent
FROM dba_free_space a,dba_data_files b
WHERE a.file_id=b.file_id and b.tablespace_name = (select default_tablespace from dba_users where username = user)
group by b.tablespace_name,b.file_name,b.file_id,b.bytes
)
GROUP BY tablespacename