Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

statspack purge automate

Posted on 2016-11-02
7
Medium Priority
?
255 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that useā€¦
Shell script to create broker configuration file using current broker Configuration, solely for purpose of backup on Linux. Script may need to be modified depending on OS-installation. Please deploy and verify the script in a test environment.
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 Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.

688 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