清理SYSAUX表空间:
- 创建临时表,保存近8天的数据
sql
create table test.ash_bak_20220119 as select * from sys.WRH$_ACTIVE_SESSION_HISTORY where SAMPLE_TIME>=sysdate-9;
SQL> select count(*) from test.ash_bak_20220119;
COUNT(*)
----------
12648
1 row selected.
- 禁用AWR
sql
exec dbms_workload_repository.modify_snapshot_settings(interval => 0);
- truncate WRH$_ACTIVE_SESSION_HISTORY
sql
TRUNCATE TABLE sys.WRH$_ACTIVE_SESSION_HISTORY;
- truncate 完成后,重建 WRH$_ACTIVE_SESSION_HISTORY表的索引,并从备份表恢复数据
sql
insert into sys.WRH$_ACTIVE_SESSION_HISTORY select * from test.ash_bak_20220119;
commit;
- 查看索引状态(USABLE是未失效,UNUSABLE是失效)
sql
set line 300 pages 200
col owner for a20
col index_name for a30
select index_owner,
index_name,
partition_name,
status,
tablespace_name,
last_analyzed
from dba_ind_partitions
where index_name in (select index_name
from dba_indexes
where table_name in ('WRH$_ACTIVE_SESSION_HISTORY')
and table_owner = 'SYS');
INDEX_OWNER INDEX_NAME PARTITION_NAME STATUS TABLESPACE_NAME LAST_ANAL
------------------------------ ------------------------------ ------------------------------ -------- ------------------------------ ---------
SYS WRH$_ACTIVE_SESSION_HISTORY_PK WRH$_ACTIVE_3552434506_0 USABLE SYSAUX 04-DEC-21
SYS WRH$_ACTIVE_SESSION_HISTORY_PK WRH$_ACTIVE_SES_MXDB_MXSN USABLE SYSAUX 07-FEB-20
- 如果索引失效重建索引(测试的时候是没有失效的,索引为本地索引)
sql
ALTER INDEX SYS.WRH$_ACTIVE_SESSION_HISTORY_PK REBUILD PARTITION WRH$_ACTIVE_3552434506_0 tablespace SYSAUX;
ALTER INDEX SYS.WRH$_ACTIVE_SESSION_HISTORY_PK REBUILD PARTITION WRH$_ACTIVE_SES_MXDB_MXSN tablespace SYSAUX;
- 启动AWR
sql
exec dbms_workload_repository.modify_snapshot_settings(interval => 60);
- 测试awr和ash可能正常生成
---手动生成snapshot
sql
exec dbms_workload_repository.create_snapshot;
@?/rdbms/admin/awrrpt
@?/rdbms/admin/ashrpt
- 删除备份表
sql
drop table test.ash_bak_20220119 purge;