關於SYS.SM$TS_AVAIL,SYS.SM$TS_USED,SYS.SM$TS_FREE幾個檢視問題

victorymoshui發表於2011-04-07
在表空間維護管理的時候,一直在使用
SELECT A.TABLESPACE_NAME,A.BYTES/1024/1024 TOTAL,
B.BYTES/1024/1024 USED, C.BYTES/1024/1024 FREE,
(B.BYTES*100)/A.BYTES "% USED",
(C.BYTES*100)/A.BYTES "% FREE"
FROM SYS.SM$TS_AVAIL A,SYS.SM$TS_USED B,SYS.SM$TS_FREE C
WHERE A.TABLESPACE_NAME=B.TABLESPACE_NAME
AND A.TABLESPACE_NAME=C.TABLESPACE_NAME;
SELECT a.tablespace_name "表空間名",total "表空間大小",free "表空間剩餘大小",
(total-free) "表空間使用大小",
ROUND((total-free)/total,4)*100 "使用率 %"
FROM  (SELECT tablespace_name,SUM(bytes) free FROM DBA_FREE_SPACE
GROUP BY tablespace_name ) a,
(SELECT tablespace_name,SUM(bytes) total FROM DBA_DATA_FILES
GROUP BY tablespace_name) b
WHERE a.tablespace_name=b.tablespace_name 
該查詢語句,但是最近在工作中,發現在同事所管理的一臺資料庫上使用第一條語句查詢出來的結果卻有些問題,在free和used加起來時卻大大的超過了100%,但是使用第二條查詢語句一切正常。疑問較大。
First,we can analyze how did those 3 views which were SYS.SM$TS_USED,SYS.SM$TS_FREE,SYS.SM$TS_AVAIL  worked.
1)
SQL>select text from dba_views where view_name = upper('sm$ts_used');
TEXT
--------------------------------------------------------------------------------
select tablespace_name, sum(bytes) bytes from dba_segments
    group by tablespace_name
2)
SQL>select text from dba_views where view_name = upper('sm$ts_avail');
TEXT
--------------------------------------------------------------------------------
select tablespace_name, sum(bytes) bytes from dba_data_files
    group by tablespace_name
3)
SQL>select text from dba_views where view_name = upper('sm$ts_free');
TEXT
--------------------------------------------------------------------------------
select tablespace_name, sum(bytes) bytes from dba_free_space
    group by tablespace_name

由於第一條語句做的tablespace_name等值連線,所以如果tablespace_name在某一個檢視中不存在的話,那麼就會出現最後顯示的表空間名稱不全。

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/9390331/viewspace-691839/,如需轉載,請註明出處,否則將追究法律責任。

相關文章