Solved

statspack purge automate

Posted on 2016-11-02
7
50 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
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
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
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 73

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

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.

Question has a verified solution.

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

Suggested Solutions

This article started out as an Experts-Exchange question, which then grew into a quick tip to go along with an IOUG presentation for the Collaborate confernce and then later grew again into a full blown article with expanded functionality and legacy…
Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

919 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

12 Experts available now in Live!

Get 1:1 Help Now