Solved

statspack purge automate

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

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

Why doesn't the Oracle optimizer use my index? Querying too much data Most Oracle developers know that an index is useful when you can use it to restrict your result set to a small number of the total rows in a table. So, the obvious side…
How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

790 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