http://ylw6006.blog.51cto.com/470441/1135593/
一般来讲除开业务数据存放的表空间,DBA要着重关注SYSTEM,SYSAUX,UNDO,TEMP表空间,SYSTEM表空间的大小一般是衡定的,UNDO和TEMP表空间的大小由数据库的业务情况决定,而SYSAUX表空间在默认条件下你如果不做任何配置,随着时间的推移,会膨胀的越来越大!SYSAUX表空间做为SYSTEM表空间的辅助表空间,主要存放EM相关的内容以及表统计信息,AWR快照,审计信息等,个人认为,如果你的SYSAUX表空间大小超过2G,那么该考虑让他减肥了!
一:使用下列语句查询表空间使用率
- SELECT * FROM (
- SELECT D.TABLESPACE_NAME,
- SPACE || 'M' "SUM_SPACE(M)",
- BLOCKS "SUM_BLOCKS",
- SPACE - NVL (FREE_SPACE, 0) || 'M' "USED_SPACE(M)",
- ROUND ( (1 - NVL (FREE_SPACE, 0) / SPACE) * 100, 2) || '%'
- "USED_RATE(%)",
- FREE_SPACE || 'M' "FREE_SPACE(M)"
- FROM ( SELECT TABLESPACE_NAME,
- ROUND (SUM (BYTES) / (1024 * 1024), 2) SPACE,
- SUM (BLOCKS) BLOCKS
- FROM DBA_DATA_FILES
- GROUP BY TABLESPACE_NAME) D,
- ( SELECT TABLESPACE_NAME,
- ROUND (SUM (BYTES) / (1024 * 1024), 2) FREE_SPACE
- FROM DBA_FREE_SPACE
- GROUP BY TABLESPACE_NAME) F
- WHERE D.TABLESPACE_NAME = F.TABLESPACE_NAME(+)
- UNION ALL
- SELECT D.TABLESPACE_NAME,
- SPACE || 'M' "SUM_SPACE(M)",
- BLOCKS SUM_BLOCKS,
- USED_SPACE || 'M' "USED_SPACE(M)",
- ROUND (NVL (USED_SPACE, 0) / SPACE * 100, 2) || '%' "USED_RATE(%)",
- NVL (FREE_SPACE, 0) || 'M' "FREE_SPACE(M)"
- FROM ( SELECT TABLESPACE_NAME,
- ROUND (SUM (BYTES) / (1024 * 1024), 2) SPACE,
- SUM (BLOCKS) BLOCKS
- FROM DBA_TEMP_FILES
- GROUP BY TABLESPACE_NAME) D,
- ( SELECT TABLESPACE_NAME,
- ROUND (SUM (BYTES_USED) / (1024 * 1024), 2) USED_SPACE,
- ROUND (SUM (BYTES_FREE) / (1024 * 1024), 2) FREE_SPACE
- FROM V$TEMP_SPACE_HEADER
- GROUP BY TABLESPACE_NAME) F
- WHERE D.TABLESPACE_NAME = F.TABLESPACE_NAME(+)
- ORDER BY 1)
- WHERE TABLESPACE_NAME IN ('SYSAUX','SYSTEM','UNDOTBS1','TEMP');
二:查询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 1
三:修改统计信息的保持时间,默认为31天,这里修改为7天,过期的统计信息会自动被删除
- SQL> select dbms_stats.get_stats_history_retention from dual;
- GET_STATS_HISTORY_RETENTION
- ---------------------------
- 31
- SQL> exec dbms_stats.alter_stats_history_retention(7);
- PL/SQL procedure successfully completed.
- SQL> select dbms_stats.get_stats_history_retention from dual;
- GET_STATS_HISTORY_RETENTION
- ---------------------------
- 7
四:修改AWR快照的保存时间为7天(7*24*60),每小时收集一次,也可以通过EM界面查看和修改
- SQL> begin
- dbms_workload_repository.modify_snapshot_settings (
- interval => 60,
- retention => 10080,
- topnsql => 100
- );
- end;
五:删除AWR快照,再次查看SYSAUX表空间使用率,最后表空间使用率降低为38.42%
- 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;