转载自:https://www.cnblogs.com/yiyuf/p/4284448.html
step1. 确认到底是哪个段占用了sysaux空间:
select segment_name,sum(bytes)/1024/1024 from dba_segments where tablespace_name=‘SYSAUX‘ group by segment_name order by 2 desc
SEGMENT_NAME SUM(BYTES)/1024/1024
WRH$_ACTIVE_SESSION_HISTORY 7360.375
WRH$_ACTIVE_SESSION_HISTORY_PK 1400.257
从上面看就是ASH(v$active_session_history)历史记录没有清理造成
step2. 检查有多少条无效记录:
SQL> SELECT COUNT(1) Orphaned_ASH_Rows
FROM wrh$_active_session_history a
WHERE NOT EXISTS
(SELECT 1
FROM wrm$_snapshot
WHERE snap_id = a.snap_id
AND dbid = a.dbid
AND instance_number = a.instance_number
);
ORPHANED_ASH_ROWS
-----------------
23392228
step3.清楚多余记录,由于rows过多,清理速度有点慢。
SQL>DELETE FROM wrh$_active_session_history a
WHERE NOT EXISTS (SELECT 1
FROM wrm$_snapshot
WHERE snap_id = a.snap_id
AND dbid = a.dbid
AND instance_number = a.instance_number);
23392228 rows deleted.
SQL>commit;
期间需要注意归档日志的产生量,避免造成磁盘空间不足等麻烦。同时可以适当的多添加几组redolog来加速delete操作。
step4. shrink tablespace
alter table WRH$_ACTIVE_SESSION_HISTORY shrink space;
step5. re-check
column OCCUPANT_NAME format a15
SELECT occupant_name,
occupant_desc,
space_usage_kbytes
FROM v$sysaux_occupants
WHERE occupant_name LIKE ‘%AWR%‘;
SELECT PARTITION_NAME FROM DBA_IND_PARTITIONS WHERE INDEX_NAME=‘WRH$_ACTIVE_SESSION_HISTORY_PK‘;
PARTITION_NAME
------------------------------
WRH$_EVENT_HISTO_MXDB_MXSN
WRH$_ACTIVE_2645903699_6157
step6 rebuild index
SQL> alter index sys.WRH$_ACTIVE_SESSION_HISTORY_PK rebuild partition WRH$_ACTIVE_2645903699_12505;
Index altered.
SQL> alter index sys.WRH$_ACTIVE_SESSION_HISTORY_PK rebuild partition WRH$_ACTIVE_2645903699_6157;
Index altered.