Solved

statspack purge automate

Posted on 2016-11-02
7
27 Views
Last Modified: 2016-11-02
I need to setup - automate - statspack purge
oracle 11g on aix 7.1
can someone show me how to setup this job so that it will run once a week?
not sure how I find out how old the records are for statspack
0
Comment
Question by:bkreynolds48
  • 4
  • 3
7 Comments
 
LVL 73

Accepted Solution

by:
sdstuber earned 500 total points
Comment Utility
Try something like this...

BEGIN
    DBMS_SCHEDULER.create_job(
        job_name          => 'PURGE_STATS_PACK',
        job_type          => 'PLSQL_BLOCK',
        job_action        => q'[DECLARE
    v_purge_count   INTEGER;
    v_threshold     DATE := SYSDATE - 7; -- delete snapshots older than one week
BEGIN
    FOR x IN (  SELECT dbid,
                       instance_number,
                       MIN(snap_id) min_snap,
                       MAX(snap_id) max_snap,
                       MIN(snap_time) min_time
                  FROM stats$snapshot
                 WHERE snap_time < v_threshold
              GROUP BY dbid, instance_number
              ORDER BY min_time)
    LOOP
        v_purge_count :=
            statspack.purge(
                i_begin_snap        => x.min_snap,
                i_end_snap          => x.max_snap,
                i_snap_range        => TRUE,
                i_extended_purge    => TRUE,
                i_dbid              => x.dbid,
                i_instance_number   => x.instance_number
            );
        DBMS_OUTPUT.put_line(
               'DBID: '
            || x.dbid
            || ' Instance: '
            || x.instance_number
            || ' Snapshots purged: '
            || v_purge_count
        );
    END LOOP;
END;]',
        start_date        => SYSDATE,
        repeat_interval   => 'FREQ=weekly',
        enabled           => TRUE,
        comments          => 'Job to periodically purge old statspack snapshots'
    );
END;
/

Open in new window



Alternatively,  put the pl/sql block into a stored procedure and then call the procedure instead of the block.

Note the purge procedure also has parameters for specifying date ranges, but I wrote it this way so I could test the query and check the ranges of snapshots myself prior to submitting them to a purge.
0
 
LVL 1

Author Comment

by:bkreynolds48
Comment Utility
how do I set this up then to purge?
0
 
LVL 1

Author Comment

by:bkreynolds48
Comment Utility
I only want to keep 60 days
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 73

Expert Comment

by:sdstuber
Comment Utility
>>>> how do I set this up then to purge?

what do you mean?  that's exactly what it does


>>>> I only want to keep 60 days

change    SYSDATE - 7    to SYSDATE - 60
0
 
LVL 1

Author Comment

by:bkreynolds48
Comment Utility
does the job then run right away and then weekly?  or do I have to manually execute it?
0
 
LVL 73

Expert Comment

by:sdstuber
Comment Utility
it will be submitted to run immediately if you leave this...

start_date        => SYSDATE,


if you want it to start at some other time,  change SYSDATE to the date/time you want
0
 
LVL 1

Author Closing Comment

by:bkreynolds48
Comment Utility
thanks for you help
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Truncate is a DDL Command where as Delete is a DML Command. Both will delete data from table, but what is the difference between these below statements truncate table <table_name> ?? delete from <table_name> ?? The first command cannot be …
How to Create User-Defined Aggregates in Oracle Before we begin creating these things, what are user-defined aggregates?  They are a feature introduced in Oracle 9i that allows a developer to create his or her own functions like "SUM", "AVG", and…
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now