暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

oracle查看表空间

原创 onion 2022-04-08
589

方式1:

sqlplus / as sysdba
col TABLESPACE_NAME for a20
select tbs_used_info.tablespace_name,
tbs_used_info.alloc_mb,
tbs_used_info.used_mb,
tbs_used_info.max_mb,
tbs_used_info.free_of_max_mb,
tbs_used_info.used_of_max || '%' used_of_max_pct
from (select a.tablespace_name,
round(a.bytes_alloc / 1024 / 1024) alloc_mb,
round((a.bytes_alloc - nvl(b.bytes_free,
0)) / 1024 / 1024) used_mb,
round((a.bytes_alloc - nvl(b.bytes_free,
0)) * 100 / a.maxbytes) used_of_max,
round((a.maxbytes - a.bytes_alloc + nvl(b.bytes_free,
0)) / 1048576) free_of_max_mb,
round(a.maxbytes / 1048576) max_mb
from (select f.tablespace_name,
sum(f.bytes) bytes_alloc,
sum(decode(f.autoextensible,
'YES',
f.maxbytes,
'NO',
f.bytes)) maxbytes
from dba_data_files f
group by tablespace_name) a,
(select f.tablespace_name,
sum(f.bytes) bytes_free
from dba_free_space f
group by tablespace_name) b
where a.tablespace_name = b.tablespace_name(+)) tbs_used_info
order by tbs_used_info.used_of_max desc;





方式2:

set linesize 160 pagesize 1000;
col TABLESPACE_NAME for a20;
col FREE_PCT for a10;
compute sum of Total_MB on report;
compute sum of MAX_MB on report;
break on report;
col FREE_PCT_MAX for a10;
select a.*,b.STATUS,b.CONTENTS
from
(
SELECT total.tablespace_name
,Round(total.MB) AS Total_MB
,Round(free.MB) AS Free_MB
,Round(total.MB-free.MB) AS Used_MB
,Round((free.MB / total.MB) * 100) || '%' AS Free_Pct
,Round(total.MAX_MB) AS MAX_MB
,Round((total.MAX_MB-(total.MB-free.MB))/total.MAX_MB * 100) || '%' AS Free_Pct_Max
FROM (
SELECT tablespace_name
,sum(bytes) / 1024 / 1024 AS MB
FROM dba_free_space
GROUP BY tablespace_name
) free
,(
SELECT tablespace_name
,sum(CASE AUTOEXTENSIBLE
WHEN 'YES'
THEN MAXBYTES
ELSE BYTES
END) / 1024 / 1024 AS MAX_MB
,sum(BYTES) / 1024 / 1024 AS MB
FROM dba_data_files
GROUP BY tablespace_name
) total
WHERE free.tablespace_name = total.tablespace_name
union all
SELECT total.tablespace_name
,Round(total.MB) AS Total_MB
,Round(free.MB) AS Free_MB
,Round(total.MB-free.MB) AS Used_MB
,Round((free.MB / total.MB) * 100) || '%' AS Free_Pct
,Round(total.MAX_MB) AS MAX_MB
,Round((total.MAX_MB-(total.MB-free.MB))/total.MAX_MB * 100) || '%' AS Free_Pct_Max
FROM (
SELECT tablespace_name
,sum(free_space) / 1024 / 1024 AS MB
FROM dba_temp_free_space
GROUP BY tablespace_name
) free
,(
SELECT tablespace_name
,sum(CASE AUTOEXTENSIBLE
WHEN 'YES'
THEN MAXBYTES
ELSE BYTES
END) / 1024 / 1024 AS MAX_MB
,sum(BYTES) / 1024 / 1024 AS MB
FROM dba_temp_files
GROUP BY tablespace_name
) total
WHERE free.tablespace_name = total.tablespace_name) a, dba_tablespaces b
where a.tablespace_name=b.tablespace_name;

「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论