SYSAUX表空間使用率高問題處理

studywell發表於2016-01-26
---SYSAUX表空間使用率高問題處理

--參考:http://ylw6006.blog.51cto.com/470441/1135593/

--一:使用下列語句查詢表空間使用率
SELECT
d.tablespace_name "表空間",
d.status "狀  態",
TO_CHAR(NVL(a.bytes / 1024 / 1024, 0),'99,999,990.900') "總容量(MB)",
TO_CHAR(NVL(a.bytes - NVL(f.bytes, 0), 0)/1024/1024,'99999999.999') "已使用(MB)",
TO_CHAR(NVL(f.bytes, 0)/1024/1024,'99999999.999') "未使用(MB)",
TO_CHAR(NVL((a.bytes - NVL(f.bytes, 0)) / a.bytes * 100, 0), '990.00') "使用率(%)"
FROM sys.dba_tablespaces d, (select tablespace_name, sum(bytes) bytes from dba_data_files
group by tablespace_name) a, (select tablespace_name, sum(bytes) bytes from dba_free_space group by tablespace_name) f WHERE
d.tablespace_name = a.tablespace_name(+) AND d.tablespace_name = f.tablespace_name(+) AND NOT (d.extent_management like 'LOCAL'
AND d.contents like 'TEMPORARY')
UNION ALL SELECT d.tablespace_name "表空間",d.status "狀  態",  TO_CHAR(NVL(a.bytes / 1024 / 1024, 0),'99,999,990.900') "總容量(MB)",
TO_CHAR(NVL(t.bytes, 0)/1024/1024,'99999999.999')  "已使用(MB)",
TO_CHAR(Nvl(a.bytes-NVL(t.bytes, 0),0)/1024/1024,'99999999.999') "未使用(MB)",
TO_CHAR(NVL(t.bytes / a.bytes * 100, 0), '990.00') "使用率(%)" FROM sys.dba_tablespaces d, (select tablespace_name, sum(bytes)
bytes from dba_temp_files group by tablespace_name) a, (select tablespace_name, sum(bytes_cached) bytes from v$temp_extent_pool
group by tablespace_name) t WHERE d.tablespace_name = a.tablespace_name(+) AND d.tablespace_name = t.tablespace_name(+) AND
d.extent_management like 'LOCAL' AND d.contents like 'TEMPORARY';


--二:查詢SYSAUX表空間內各個分類專案佔儲存空間的比重,很明顯可以看出來AWR快照佔用了2G左右的空間,統計資訊為149M左右,同時資料庫關閉了審計audit_trail,所以審計表aud$不佔空間    
 SELECT occupant_name "Item",
           space_usage_kbytes / 1048576 "Space Used (GB)",
           schema_name "Schema",
           move_procedure "Move Procedure"
      FROM v$sysaux_occupants
 order by 2 desc;
 
 select *   FROM v$sysaux_occupants s order by s.SPACE_USAGE_KBYTES desc;
     
--三:修改統計資訊的保持時間,預設為31天,這裡修改為7天,過期的統計資訊會自動被刪除
    select dbms_stats.get_stats_history_retention from dual;
    exec dbms_stats.alter_stats_history_retention(7);       
    select dbms_stats.get_stats_history_retention from dual;
    
   -- 檢視系統的當前的MOVING_WINDOW_SIZE
    select dbid,baseline_name,baseline_type,moving_window_size from dba_hist_baseline;
    exec dbms_workload_repository.modify_baseline_window_size(2);
    
 
--四:修改AWR快照的儲存時間為3天(3*24*60),每小時收集一次,也可以透過EM介面檢視和修改
    --當前預設保留時間
    select * from dba_hist_wr_control;

  SQL> begin
             dbms_workload_repository.modify_snapshot_settings (
                interval => 60,
                retention => 4320,
                topnsql => 100
              );
    end;
        
--五:刪除AWR快照,再次檢視SYSAUX表空間使用率,
    select min(snap_id),max(snap_id) from dba_hist_snapshot;//查詢最最小和最大快照ID      
     select * from dba_hist_snapshot;
     
    begin
         dbms_workload_repository.drop_snapshot_range(
           low_snap_id => 37170,
          high_snap_id => 37370,
          dbid => 1296073523);
    end;
   

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

相關文章