/* 查询表分配的空间大小,不管空间是否被占用*/
-- 单位:MB
select segment_name,bytes/1024/1024 "分配空间(MB)"
from user_segments
where segment_type='TABLE'
AND SEGMENT_NAME='TABLE_NAME';
/*查看表实际占用空间大小*/
-- 单位:MB
select segment_name,sum(bytes)/1024/1024 AS "实际使用量(MB)"
from User_Extents
where segment_name='TABLE_NAME'
Group By Segment_Name;
/*查看表空间大小*/
-- 单位MB
Select Tablespace_Name,Sum(bytes)/1024/1024
From dba_Segments Group By Tablespace_Name;
/*查看剩余表空间大小*/
-- 单位MB
SELECT tablespace_name 表空间,sum(blocks*8192/1000000) 剩余空间M
FROM dba_free_space GROUP BY tablespace_name;
/*查看所有表空间总体空间*/
-- 单位MB
select b.name,sum(a.bytes/1000000)总空间
from v$datafile a,v$tablespace b
where a.ts#=b.ts# group by b.name;
/*表空间大小及使用率*/
select
a.a1 表空间名称,
c.c2 类型,
c.c3 区管理,
b.b2/1024/1024 表空间大小M,
(b.b2-a.a2)/1024/1024 已使用M,
substr((b.b2-a.a2)/b.b2*100,1,5) 利用率
from
(select tablespace_name a1, sum(nvl(bytes,0)) a2 from dba_free_space group by tablespace_name) a,
(select tablespace_name b1,sum(bytes) b2 from dba_data_files group by tablespace_name) b,
(select tablespace_name c1,contents c2,extent_management c3 from dba_tablespaces) c
where a.a1=b.b1 and c.c1=b.b1;
/*数据文件大小及使用率*/
select
b.file_name 物理文件名,
b.tablespace_name 表空间,
b.bytes/1024/1024 大小M,
(b.bytes-sum(nvl(a.bytes,0)))/1024/1024 已使用M,
substr((b.bytes-sum(nvl(a.bytes,0)))/(b.bytes)*100,1,5) 利用率
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.bytes
order by b.tablespace_name;
/*临时表空间的名称、大小、数据文件*/
select
a.talbespace_name 表空间名称,
b.bytes 大小bytes,
b.file_name 数据文件名
from dba_tablespaces a, dba_data_files b
Where a.talbespace_name=b.talbespace_name and a.contents='TEMPORARY';
/*查询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;
/*查询oracle系统用户的默认表空间和临时表空间*/
select default_tablespace,temporary_tablespace from dba_users;
/*查询单张表的使用情况*/
select segment_name,bytes
from dba_segments
where segment_name = 'RE_STDEVT_FACT_DAY' and owner = USER;
/*查询所有用户表使用大小的前三十名*/
select * from (select segment_name,bytes from dba_segments where owner = USER order by bytes desc )
where rownum <= 30;
/*查询当前用户默认表空间的使用情况*/
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;
/*查询用户表空间的表*/
select * from user_tables;
还没有评论,来说两句吧...