【发布时间】:2020-03-17 11:43:45
【问题描述】:
谁能帮我找到临时表空间使用的大小?哪个查询将从下面返回正确的值?
SELECT t.tablespace_name,df.allocated_bytes as ALLOCATED_BYTES,decode(sign(df.allocated_bytes-NVL(f.used_bytes,0)),1,df.allocated_bytes - NVL(f.used_bytes,0),0) as FREE_BYTES,decode(sign(df.allocated_bytes-NVL(f.used_bytes,0)),1,NVL(f.used_bytes,0),df.allocated_bytes) as USED_BYTES,decode(sign(NVL(df.allocated_blocks,0)-NVL(f.used_blocks,0)),1,NVL(df.allocated_blocks,0)-NVL(f.used_blocks,0),0) FREEBLOCKS,NVL(df.allocated_blocks,0) ALLOCATEDBLOCKS FROM sys.dba_tablespaces t,(SELECT h.tablespace_name, ROUND(sum((ss.used_blocks*tt.block_size)),2) used_bytes, SUM(NVL(ss.used_blocks, 0)) used_blocks FROM V$TEMP_SPACE_HEADER h,***v$sort_segment*** ss,sys.dba_tablespaces tt where ss.tablespace_name(+)=h.tablespace_name and ss.tablespace_name(+)=tt.tablespace_name and ss.con_id = (select con_id from v$mystat where rownum=1) GROUP BY h.tablespace_name) f,(select tablespace_name,sum(decode(sign(maxbytes-bytes),1,maxbytes,bytes)) allocated_bytes,sum(blocks) allocated_blocks from dba_temp_files group by tablespace_name) df WHERE t.contents='TEMPORARY' and t.tablespace_name = f.tablespace_name(+) and t.tablespace_name=df.tablespace_name(+) order by t.tablespace_name
或
SELECT t.tablespace_name,df.allocated_bytes as ALLOCATED_BYTES,decode(sign(df.allocated_bytes-NVL(f.used_bytes,0)),1,df.allocated_bytes - NVL(f.used_bytes,0),0) as FREE_BYTES,decode(sign(df.allocated_bytes-NVL(f.used_bytes,0)),1,NVL(f.used_bytes,0),df.allocated_bytes) as USED_BYTES,decode(sign(NVL(df.allocated_blocks,0)-NVL(f.used_blocks,0)),1,NVL(df.allocated_blocks,0)-NVL(f.used_blocks,0),0) FREEBLOCKS,NVL(df.allocated_blocks,0) ALLOCATEDBLOCKS FROM sys.dba_tablespaces t,(SELECT h.tablespace_name, SUM(NVL(p.bytes_used, 0)) used_bytes, SUM(NVL(ss.used_blocks, 0)) used_blocks FROM V$TEMP_SPACE_HEADER h,***V$TEMP_EXTENT_POOL p***,v$sort_segment ss where p.tablespace_name(+)=h.tablespace_name and ss.tablespace_name(+)=h.tablespace_name GROUP BY h.tablespace_name) f,(select tablespace_name,sum(decode(sign(maxbytes-bytes),1,maxbytes,bytes)) allocated_bytes,sum(blocks) allocated_blocks from dba_temp_files group by tablespace_name) df WHERE t.contents='TEMPORARY' and t.tablespace_name = f.tablespace_name(+) and t.tablespace_name=df.tablespace_name(+) order by t.tablespace_name
谢谢!
【问题讨论】:
-
您发布了两个非常长且格式错误的查询。如果您希望人们阅读它们,您应该对其进行编辑,以便无需滚动即可阅读和比较它们。
-
两者都不是。它们都返回语法错误。 “来自 v$temp_space_header h,v$sort_segment”是怎么回事。这些星号是否突出了两个查询之间的区别?如果是这样,即使我删除了这些,我也会收到语法错误。 ss.con_id - 无效的标识符。我不会再找了。让我们退后一步,问(我们总是应该),“您要解决的业务问题是什么?”如果我们知道这一点,我们可能会发现这些查询根本没有用,或者您认为的问题实际上不是。
-
与您的问题无关,但是:即使是 Oracle 也建议停止使用
(+)运算符并改用标准的left join
标签: database oracle tablespace