SYSAUX表空間清理


最近zabbix告警某業務sysaux表空間使用率超過95%,使用sql查看sysaux表空間設置了32G,32G的表空間竟然使用了95%。一般來講除開業務數據存放的表空間,DBA要着重關注SYSTEM,SYSAUX,UNDO,TEMP表空間,SYSTEM表空間的大小一般是衡定的,UNDO和TEMP表空間的大小由數據庫的業務情況決定,而SYSAUX表空間在默認條件下你如果不做任何配置,隨着時間的推移,會膨脹的越來越大!SYSAUX表空間做為SYSTEM表空間的輔助表空間,主要存放EM相關的內容以及表統計信息,AWR快照,審計信息等,那么怎么清理sysaux表空間呢?

1、查詢表空間使用率

set line 200 pagesize 9999
col tablespace_name for a20
select b.tablespace_name,round(sum(b.bytes)/1024/1024,0) sum_MB,
round(sum(b.bytes)/1024/1024,0)-round(sum(nvl(a.bytes,0))/1024/1024,0) use_MB,
round(sum(nvl(a.bytes,0))/1024/1024,0) free_MB,
round((sum(b.bytes)-sum(nvl(a.bytes,0)))/sum(b.bytes),4)*100 use_precent
from (select tablespace_name,file_id,sum(bytes) bytes from dba_free_space group by tablespace_name,file_id) a,
dba_data_files b
where a.file_id(+)=b.file_id and a.tablespace_name(+)=b.tablespace_name
group by b.tablespace_name
union all
select b.tablespace_name,round(b.bytes/1024/1024,0) sum_MB,
round(nvl(a.bytes,0)/1024/1024,0) use_MB,
round(b.bytes/1024/1024,0)-round(nvl(a.bytes,0)/1024/1024,0) free_MB,
round(nvl(a.bytes,0)/b.bytes,4)*100 use_precent
from (select tablespace_name,sum(nvl(bytes_used,0)) bytes from gv$temp_extent_pool group by tablespace_name) a,
(select tablespace_name,sum(bytes) bytes from dba_temp_files group by tablespace_name)b
where a.tablespace_name(+)=b.tablespace_name
order by use_precent desc;

經查詢發現sysaux表空間使用率確實查過95%

2、查詢SYSAUX表空間內各個分類項目占存儲空間的比重,很明顯可以看出來AWR快照占用了27G左右統計信息占了276M左右。查詢語句如下:

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 ;

3、修改統計信息的保持時間,默認為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; 

4、修改AWR快照的保存時間為7天(7*24*60),每小時收集一次

begin 

         dbms_workload_repository.modify_snapshot_settings ( interval => 60, retention => 10080, topnsql => 100); 

end; 

5、刪除AWR快照,最后再次查看SYSAUX表空間使用率

select min(snap_id),max(snap_id) from dba_hist_snapshot;//查詢最最小和最大快照ID 

begin 

     dbms_workload_repository.drop_snapshot_range( low_snap_id => 10758, high_snap_id => 10900, dbid => 387090299); 

end; 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM