处理SM/AWR占用sysaux很大空间的问题

本文详细介绍了如何处理SM/AWR在SYSAUX表空间中占用大量空间的问题,包括计算occupants大小、查看无效索引、统计表空间、查询SYSAUX区段大小,并通过删除历史分区和优化SQL_PLAN来释放空间。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.计算SYSAUX的occupants的大小

 

select *

  from (SELECT occupant_name "Item",

               trunc((space_usage_kbytes / 1048576), 2) "Space Used (GB)",

               schema_name "Schema",

               move_procedure "Move Procedure"

          FROM v$sysaux_occupants

         ORDER BY 2 desc)

 where rownum <= 10

 

2.查看无效的index

 

select * from dba_indexes where degree not in ('1','0','DEFAULT');

 

3.统计表空间大小

 

select    b.file_id as file_id,

          b.tablespace_name as tablespace_id,

          b.file_name as file_name,

          round(b.bytes / 1024 / 1024 ) as total_size,

          round((b.bytes / 1024 / 1024 ) - sum(nvl(a.bytes / 1024 / 1024 , 0))) as used_size,

          round(sum(nvl(a.bytes / 1024 / 1024 , 0))) as free_size,

          round(sum(nvl(a.bytes, 0)) / (b.bytes) * 100)  as free_percent   

      from dba_free_space a, dba_data_files b   

    where a.file_id = b.file_id   

    group by b.tablespace_name, b.file_name, b.file_id, b.bytes   

    order by b.tablespace_name

 

4.查询分SYSAUX区段的大小

 

select *

  from (select segment_name,

               PARTITION_NAME,

               segment_type,

               bytes / 1024 / 1024

          from dba_segments

         where tablespace_name = 'SYSAUX'

         order by 4 desc)

 where rownum <= 10;

 

5.删除保留旧snapshot信息的历史分区

 

alter table WRH$_ACTIVE_SESSION_HISTORY drop partition WRH$_ACTIVE_1172987837_0

 

select min(snap_id),max(snap_id) from  wrh$_active_session_history;

 

select * from dba_hist_wr_control;

 

SQL> alter table WRH$_SYSSTAT drop partition WRH$_SYSSTA_1172987837_0;

 

Table altered.

 

SQL> select max(SNAP_ID),min(SNAP_ID) from WRH$_PARAMETER;

 

MAX(SNAP_ID) MIN(SNAP_ID)

------------ ------------

       20040         8274

 

SQL> alter table WRH$_PARAMETER drop partition WRH$_PARAME_1172987837_0;

 

Table altered.

 

SQL>  alter table WRH$_SYSTEM_EVENT drop partition WRH$_SYSTEM_1172987837_0;

 

Table altered.

 

SQL> alter table WRH$_SEG_STAT drop partition WRH$_SEG_ST_1172987837_0;

 

Table altered.

 

SQL> alter table WRH$_DLM_MISC drop partition WRH$_DLM_MI_1172987837_0;

 

Table altered.

 

SQL> alter table WRH$_SERVICE_STAT drop partition WRH$_SERVIC_1172987837_0;

 

Table altered.

 

SQL> select count(*) from WRH$_SQLSTAT;

 

  COUNT(*)

----------

     68479

    SQL> select max(SNAP_ID),min(SNAP_ID) from WRH$_SQLSTAT;

 

MAX(SNAP_ID) MIN(SNAP_ID)

------------ ------------

       20039         8274

 

SQL> select min(snap_id),max(snap_id) from  wrh$_active_session_history;

 

MIN(SNAP_ID) MAX(SNAP_ID)

------------ ------------

       19853        20039

 

SQL> alter table WRH$_SQLSTAT drop partition WRH$_SQLSTA_1172987837_0;

 

Table altered.

 

SQL> select max(SNAP_ID),min(SNAP_ID) from WRH$_SQLSTAT;

 

MAX(SNAP_ID) MIN(SNAP_ID)

------------ ------------

       20039        19853

 

SQL> alter table WRH$_LATCH_MISSES_SUMMARY drop partition WRH$_LATCH__1172987837_0;

 

Table altered.

 

SQL> alter table WRH$_LATCH drop partition WRH$_LATCH_1172987837_0;

 

Table altered.

 

SQL> alter table WRH$_EVENT_HISTOGRAM drop partition WRH$_EVENT__1172987837_0;

 

Table altered.

 

SQL> select max(SNAP_ID),min(SNAP_ID) from WRH$_SQL_PLAN;

 

MAX(SNAP_ID) MIN(SNAP_ID)

------------ ------------

       20090         8274

 

SQL> select count(*) from WRH$_SQL_PLAN;

 

  COUNT(*)

----------

   8714427

 

SQL> delete from WRH$_SQL_PLAN where SNAP_ID<19853;

 

8496572 rows deleted.

 

SQL> commit;

 

Commit complete.

 

SQL> select max(SNAP_ID),min(SNAP_ID) from WRH$_SQL_PLAN;

 

MAX(SNAP_ID) MIN(SNAP_ID)

------------ ------------

       20090        19853

 

SQL> alter table  WRH$_SQL_PLAN enable ROW MOVEMENT;

 

Table altered.

 

SQL> alter table  WRH$_SQL_PLAN shrink space;

 

Table altered.

 

SQL> alter table  WRH$_SQL_PLAN disable ROW MOVEMENT;

 

Table altered.

 

6.再次查询表空使用率

 

    select    b.file_id as file_id,

          b.tablespace_name as tablespace_id,

          b.file_name as file_name,

          round(b.bytes / 1024 / 1024 ) as total_size,

          round((b.bytes / 1024 / 1024 ) - sum(nvl(a.bytes / 1024 / 1024 , 0))) as used_size,

          round(sum(nvl(a.bytes / 1024 / 1024 , 0))) as free_size,

          round(sum(nvl(a.bytes, 0)) / (b.bytes) * 100)  as free_percent   

      from dba_free_space a, dba_data_files b   

    where a.file_id = b.file_id   

    group by b.tablespace_name, b.file_name, b.file_id, b.bytes   

    order by b.tablespace_name

 

空间释放完毕。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值