Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

statspack purge automate

Posted on 2016-11-02
7
Medium Priority
?
299 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 74

Accepted Solution

by:
sdstuber earned 2000 total points
ID: 41870519
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
ID: 41870594
how do I set this up then to purge?
0
 
LVL 1

Author Comment

by:bkreynolds48
ID: 41870595
I only want to keep 60 days
0
Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

 
LVL 74

Expert Comment

by:sdstuber
ID: 41870597
>>>> 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
ID: 41870642
does the job then run right away and then weekly?  or do I have to manually execute it?
0
 
LVL 74

Expert Comment

by:sdstuber
ID: 41870668
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
ID: 41870688
thanks for you help
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.
Suggested Courses

927 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