问题描述
你好康纳和克里斯 :-),
几天前,我发现这个奇妙的SQL脚本检查表空间的可用空间由Tom Kyte编写- https://asktom。oracle。com/Misc/free。html 。
所以我花了一些时间格式化和对齐它 (顺便说一句Kb成Mb)。 The following is full code,
从我的代码中可以看到,我想知道为什么它不使用 “union all” 子句来进行联合查询dba_free_space和dba_temp_free_space在内联视图 “a” 上 (但是,它使用 “union all” 来进行联合查询dba_data_files和dba_temp_files在线视图 “b”)?
最好的问候
赵全文
几天前,我发现这个奇妙的SQL脚本检查表空间的可用空间由Tom Kyte编写- https://asktom。oracle。com/Misc/free。html 。
所以我花了一些时间格式化和对齐它 (顺便说一句Kb成Mb)。 The following is full code,
set linesize 200
set pagesize 200
column dummy noprint
column pct_used format 999。9 heading "%|Used"
column name format a25 heading "Tablespace Name"
column Mbytes format 999,999,999 heading "MBytes"
column Used_Mbytes format 999,999,999 heading "Used|MBytes"
column Free_Mbytes format 999,999,999 heading "Free|MBytes"
column Largest_Mbytes format 999,999,999 heading "Largest|MBytes"
column Max_Size format 999,999,999 heading "MaxPoss|MBytes"
column pct_max_used format 999。9 heading "%|Max|Used"
break on report
compute sum of Mbytes on report
compute sum of Free_Mbytes on report
compute sum of Used_Mbytes on report
select ( select decode(extent_management,'LOCAL','*',' ') ||
decode(segment_space_management,'AUTO','a ','m ')
from dba_tablespaces
where tablespace_name = b。tablespace_name
) || nvl(b。tablespace_name,nvl(a。tablespace_name,'UNKOWN')) name
, Mbytes_alloc Mbytes
, Mbytes_alloc-nvl(Mbytes_free,0) Used_Mbytes
, nvl(Mbytes_free,0) Free_Mbytes
, ((Mbytes_alloc-nvl(Mbytes_free,0))/Mbytes_alloc)*100 pct_used
, nvl(Mbytes_largest,0) Largest_Mbytes
, nvl(Mbytes_max,Mbytes_alloc) Max_Size
, decode(Mbytes_max,0,0,(Mbytes_alloc/Mbytes_max)*100) pct_max_used
from ( select sum(bytes)/1024/1024 Mbytes_free
, max(bytes)/1024/1024 Mbytes_largest
, tablespace_name
from sys。dba_free_space
group by tablespace_name
) a,
( select sum(bytes)/1024/1024 Mbytes_alloc
, sum(maxbytes)/1024/1024 Mbytes_max
, tablespace_name
from sys。dba_data_files
group by tablespace_name
union all
select sum(bytes)/1024/1024 Mbytes_alloc
, sum(maxbytes)/1024/1024 Mbytes_max
, tablespace_name
from sys。dba_temp_files
group by tablespace_name
) b
where a。tablespace_name (+) = b。tablespace_name
order by 1
/
从我的代码中可以看到,我想知道为什么它不使用 “union all” 子句来进行联合查询dba_free_space和dba_temp_free_space在内联视图 “a” 上 (但是,它使用 “union all” 来进行联合查询dba_data_files和dba_temp_files在线视图 “b”)?
最好的问候
赵全文
专家解答
通常,在临时表空间中的可用空间中没有很多 “兴趣” 或 “价值”,因为我们不以相同的方式对待段。
如果 * 我 * 为一个排序分配了一个大的临时段,那么当我完成后,我们需要清理该段,我们只需要标记它可供其他人使用。
因此,看到临时表空间总是 “满” 并不少见,它只是充满了可以被其他人重复使用的段。如果您真的想获得当前正在使用的temp的图片,则可以在v $ tempseg_usage中折叠
如果 * 我 * 为一个排序分配了一个大的临时段,那么当我完成后,我们需要清理该段,我们只需要标记它可供其他人使用。
因此,看到临时表空间总是 “满” 并不少见,它只是充满了可以被其他人重复使用的段。如果您真的想获得当前正在使用的temp的图片,则可以在v $ tempseg_usage中折叠
文章转载自ASKTOM,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




