一般来讲除开业务数据存放的表空间,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
~~~~~~~~~~~~~~临时删除的办法~~~~~~~~~~~~~~~··
truncate table WRH$_ACTIVE_SESSION_HISTORY; truncate table WRH$_EVENT_HISTOGRAM; truncate table WRH$_SQLSTAT; truncate table WRH$_LATCH_MISSES_SUMMARY; truncate table WRH$_LATCH; truncate table WRH$_SYSSTAT; truncate table WRH$_SEG_STAT; truncate table WRH$_PARAMETER; truncate table WRH$_SYSTEM_EVENT; truncate table WRH$_SQL_PLAN; truncate table WRH$_DLM_MISC; truncate table WRH$_SERVICE_STAT; truncate table WRH$_TABLESPACE_STAT; truncate table WRH$_ROWCACHE_SUMMARY; truncate table WRH$_MVPARAMETER;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~···
select distinct 'truncate table '||segment_name||';',s.bytes/1024/1024 from dba_segments s where s.segment_name like 'WRH$%' and segment_type in ('TABLE PARTITION', 'TABLE') and s.bytes/1024/1024>100 order by s.bytes/1024/1024/1024 desc; |