Вы находитесь на странице: 1из 5

Rem Rem $Header: sppurge.sql 20-mar-2002.18:02:43 vbarrier Exp $ Rem Rem sppurge.

sql Rem Rem Copyright (c) 2000, 2002, Oracle Corporation. All rights reserved. Rem Rem NAME Rem sppurge.sql - STATSPACK Purge Rem Rem DESCRIPTION Rem Purge a range of Snapshot Id's between the specified Rem begin and end Snap Id's Rem Rem NOTES Rem Should be run as STATSPACK user, PERFSTAT. Rem Rem Running purge may require the use of a large rollback Rem segment; to avoid rollback segment related errors Rem explicitly specify a large rollback segment before running Rem this script by using the 'set transaction use rollback segment..' Rem command, or alternatively specify a smaller range of Rem Snapshot Id's to purge. Rem Rem Rem MODIFIED (MM/DD/YY) Rem vbarrier 03/20/02 - Optional stats$seg_stat_obj purge Rem cdialeri 04/12/01 - 9.0 Rem cdialeri 04/11/00 - 1261813 Rem cdialeri 03/15/00 - Conform to new structure Rem densor.uk 05/00/94 - Allow purge of range of snaps Rem gwood.uk 10/12/92 - Use RI for deletes to most tables Rem cellis.uk 11/15/89 - Created Rem set feedback off verify off pages 999 undefine dbid inst_num losnapid hisnapid whenever sqlerror exit rollback spool sppurge.out prompt Ora di esecuzione prompt select to_char(sysdate, 'Dy DD-Mon-YYYY HH24:MI:SS') as "Current Time" from dual; /* ------------------------------------------------------------------------- */ --- Get the current database/instance information - this will be used -- later in the report along with bid, eid to lookup snapshots prompt prompt prompt Database Instance currently connected to prompt ======================================== column inst_num heading "Inst Num" new_value inst_num format 99999; column inst_name heading "Instance|Name" new_value inst_name format a10;

column column c; select , , , from

db_name dbid

heading "DB Name" heading "DB Id" dbid db_name inst_num inst_name

new_value db_name new_value dbid

format a10; format 9999999999 just

d.dbid d.name i.instance_number i.instance_name v$database d, v$instance i;

variable dbid number; variable inst_num number; variable inst_name varchar2(20); variable db_name varchar2(20); begin :dbid := &dbid; :inst_num := &inst_num; :inst_name := '&inst_name'; :db_name := '&db_name'; end; / --Parte modificata per cancellare i 100 snapshot piu vecchi column min_snap_id new_val LoSnapId column max_snap_id new_val HiSnapId select min(s.snap_id) min_snap_id, min(s.snap_id)+100 max_snap_id from stats$snapshot s , stats$database_instance di where s.dbid = :dbid and di.dbid = :dbid and s.instance_number = :inst_num and di.instance_number = :inst_num and di.startup_time = s.startup_time and s.snap_time < sysdate-30; ------------------------------------------------------------------- Post warning prompt prompt prompt prompt prompt prompt prompt prompt prompt prompt

Warning ~~~~~~~ sppurge.sql deletes all snapshots ranging between the lower and upper bound Snapshot Id's specified, for the database instance you are connected to. You may wish to export this data before continuing.

--- Obtain snapshot ranges prompt prompt Specify the Lo Snap Id and Hi Snap Id range to purge prompt ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ prompt Using &&LoSnapId for lower bound.

prompt prompt Using &&HiSnapId for upper bound. variable lo_snap number; variable hi_snap number; begin :lo_snap := &losnapid; :hi_snap := &hisnapid; end; / set termout off --- Get begin and end snapshot times - these are used to delete undostat column btime new_value btime column etime new_value etime select to_char(snap_time, 'YYYYMMDD HH24:MI:SS') btime from stats$snapshot b where b.snap_id = :lo_snap and b.dbid = :dbid and b.instance_number = :inst_num; select to_char(snap_time, 'YYYYMMDD HH24:MI:SS') etime from stats$snapshot e where e.snap_id = :hi_snap and e.dbid = :dbid and e.instance_number = :inst_num; variable btime varchar2(25); variable etime varchar2(25); begin :btime := '&btime'; :etime := '&etime'; end; / set termout on set heading off select 'WARNING: LoSnapId or HiSnapId specified does not exist in STATS$SNAPSHOT ' from dual where not exists (select null from stats$snapshot where instance_number = :inst_num and dbid = :dbid and snap_id = :lo_snap) or not exists (select null from stats$snapshot where instance_number = :inst_num and dbid = :dbid and snap_id = :hi_snap); set heading on

--

-- Delete all data for the specified ranges /* Use RI to delete parent snapshot and all child records */ prompt prompt delete where and and set /* /* Rem Rem Rem Deleting snapshots &&losnapid - &&hisnapid.. from stats$snapshot instance_number = :inst_num dbid = :dbid snap_id between :lo_snap and :hi_snap;

termout off; Delete any dangling SQLtext */ The following statement deletes any dangling SQL statements which are no longer referred to by ANY snapshots. This statment has been commented out as it can be very resource intensive.

alter session set hash_area_size=1048576; delete --+ index_ffs(st) from stats$sqltext st where (hash_value, text_subset) not in (select --+ hash_aj full(ss) no_expand hash_value, text_subset from stats$sql_summary ss where ( ( snap_id < :lo_snap or snap_id > :hi_snap ) and dbid = :dbid and instance_number = :inst_num ) or ( dbid != :dbid or instance_number != :inst_num) ); Rem Adding an optional STATS$SEG_STAT_OBJ delete statement delete --+ index_ffs(sso) from stats$seg_stat_obj sso where (dbid, dataobj#, obj#) not in (select --+ hash_aj full(ss) no_expand dbid, dataobj#, obj# from stats$seg_stat ss where ( ( snap_id < :lo_snap or snap_id > :hi_snap ) and dbid = :dbid and instance_number = :inst_num ) or ( dbid != :dbid or instance_number != :inst_num) ); */ set termout on;

/* Delete any undostat rows that cover the snap times */

delete where and and and

from stats$undostat us dbid = :dbid instance_number = :inst_num begin_time < to_date(:btime, 'YYYYMMDD HH24:MI:SS') end_time > to_date(:etime, 'YYYYMMDD HH24:MI:SS');

/* Delete any dangling database instance rows for that startup time */ delete where and and from stats$database_instance di instance_number = :inst_num dbid = :dbid not exists (select 1 from stats$snapshot s where s.dbid = di.dbid and s.instance_number = di.instance_number and s.startup_time = di.startup_time);

/* Delete any dangling statspack parameter rows for the database instance */ delete where and and from stats$statspack_parameter sp instance_number = :inst_num dbid = :dbid not exists (select 1 from stats$snapshot s where s.dbid = sp.dbid and s.instance_number = sp.instance_number);

--commit; prompt prompt prompt Purge of specified Snapshot range complete. If you wish to ROLLBACK prompt the purge, it is still possible to do so. Exitting from SQL*Plus will prompt automatically commit the purge. prompt --spool off set feedback on termout on whenever sqlerror continue exit

Вам также может понравиться