天天看點

ORACLE 手動建立或删除snapshot

--如果需要的話DBA可以通過DBMS_WORKLOAD_REPOSITORY過程手動建立、删除或修改snapshots.

調用DBMS_WORKLOAD_REPOSITORY包需要擁有DBA權限。

--1.手動建立Snapshots 手動建立Snapshots通過DBMS_WORKLOAD_REPOSITORY.CREATE_SNAPSHOT過程

--例如

exec dbms_workload_repository.create_snapshot();

-- 然後可以通過 DBA_HIST_SNAPSHOT 視圖檢視剛剛建立的Snapshots資訊。

SELECT * FROM DBA_HIST_SNAPSHOT;

-- 2手動删除Snapshots

--删除Snapshots是使用DBMS_WORKLOAD_REPOSITORY包的另一個過程DROP_SNAPSHOT_RANGE 該過程在執行時可以通過指定snap_id的範圍的方式一次删除多個Snapshot

--例如

select count(0) from dba_hist_snapshot where snap_id between 6770 and 6774;

select max(snap_id) from dba_hist_snapshot;

select dbid from v$database;

exec dbms_workload_repository.drop_snapshot_range(low_snap_id => 6770,high_snap_id => 6774,dbid => 4059638244);

--或者

begin

dbms_workload_repository.drop_snapshot_range(

low_snap_id => 6770,

high_snap_id => 6774,

dbid => 4059638244);

end;

select count(0) from dba_hist_snapshot where snap_id between 6770 and 6774;