Call now: 252-767-6166  
Oracle Training Oracle Support Development Oracle Apps

 
 Home
 E-mail Us
 Oracle Articles
New Oracle Articles


 Oracle Training
 Oracle Tips

 Oracle Forum
 Class Catalog


 Remote DBA
 Oracle Tuning
 Emergency 911
 RAC Support
 Apps Support
 Analysis
 Design
 Implementation
 Oracle Support


 SQL Tuning
 Security

 Oracle UNIX
 Oracle Linux
 Monitoring
 Remote s
upport
 Remote plans
 Remote
services
 Application Server

 Applications
 Oracle Forms
 Oracle Portal
 App Upgrades
 SQL Server
 Oracle Concepts
 Software Support

 Remote S
upport  
 Development  

 Implementation


 Consulting Staff
 Consulting Prices
 Help Wanted!

 


 Oracle Posters
 Oracle Books

 Oracle Scripts
 Ion
 Excel-DB  

Don Burleson Blog 


 

 

 


 

 

 
 

How to purge SQL from AWR

Oracle Database Tips by Donald BurlesonSeptember 25, 2015

Question:  I want to keep several years worth of AWR snapshots but I see that the details for SQL statements is clogging-up by AWR tablespace.  How can I delete SQL details that I no longer want to retain?

Answer:  First, see these important notes on disabling AWR data purging Also see my notes on SYSAUX tablespace growth tips. Also see my notes on purging from scheduler$_event_log and  scheduler$_job_run_details.

In order to collect long-term statistics in AWR, it is necessary to periodically purge details that you not longer need, and SQL statement details do indeed comprise the majority of the data space used within AWR.  You can also adjust the number of SQL statements collected in an AWR snapshot by adjusting dbms_workload_repository topnsql.

These tables contain SQL that is rarely useful after a month.  Note:  You must be connected as SYSDBA to truncate these tables.

  • wrh$_sqlstat contains a history for SQL execution statistics and stores snapshots of v$sql view.

  • wrh$_sqltext stores actual text for SQL statements captured from v$sql.

  • wrh$_sql_plan stores execution plans for SQL statements available in dba_hist_sqlstat.

connect sys/manager as sysdba;

truncate table wrh$_sqlstat;
truncate table wrh$_sqltext;
truncate table wrh$_sql_plan;

You can schedule this periodic truncate of the SQL tables using either dbms_scheduler or with a crontab job.

By issuing a truncate table monthly, I can keep the past weeks SQL details, while freeing-up space in the AWR tablespace (SYSAUX).

Partial purge of AWR data

For long term capacity planning, it is always a good idea to run an AWR report that shows the relative amount of data consumed by each AWR table.  If you purge data that is no longer required, then you are going to have a compact set of historical data.  Let's start by getting the Oracle table size information:

col c1 heading 'table|name' format a30
col c2 heading 'table size|meg'format 999,999,999


select
   segment_name c1,
   sum(bytes)/(1024*1024) c2
from
   dba_extents
where
   segment_type='TABLE'
and
   segment_name like 'WR%'
group by
   segment_name
order by
   c2 desc;

table                          table size
name                           meg
------------------------------ ----------
wrh$_sql_plan                     3
wrh$_sqltext                      1

Now we can simply issue a truncate command to purge all SQL data:

truncate table wrh$_sql_plan;

truncate table wrh$_sqltext;

If you want to get fancy, you would arrange to delete the old SQL tables before a particular data.

delete
from
   dba_hist_sql_plan
where
   sql_id =
      (select
           sql_id
       from
           dba_hist_snapshot
       where
    begin_interval_time < sysdate - 90);

Here is another example of purging highly populated SQL tables in order to free-up enough space for longer AWR retention periods.

delete
from
   dba_hist_sqltext
where
   sql_id =
    (select
         sql_id
      from
         dba_hist_snapshot
      where
          begin_interval_time < sysdate - 90);

 

 

 
Get the Complete
Oracle SQL Tuning Information 

The landmark book "Advanced Oracle SQL Tuning  The Definitive Reference"  is filled with valuable information on Oracle SQL Tuning. This book includes scripts and tools to hypercharge Oracle 11g performance and you can buy it for 30% off directly from the publisher.

 

 

Burleson is the American Team

Note: This Oracle documentation was created as a support and Oracle training reference for use by our DBA performance tuning consulting professionals.  Feel free to ask questions on our Oracle forum.

Verify experience! Anyone considering using the services of an Oracle support expert should independently investigate their credentials and experience, and not rely on advertisements and self-proclaimed expertise. All legitimate Oracle experts publish their Oracle qualifications.

Errata?  Oracle technology is changing and we strive to update our BC Oracle support information.  If you find an error or have a suggestion for improving our content, we would appreciate your feedback.  Just  e-mail:  

and include the URL for the page.


                    









Burleson Consulting

The Oracle of Database Support

Oracle Performance Tuning

Remote DBA Services


 

Copyright © 1996 -  2020

All rights reserved by Burleson

Oracle ® is the registered trademark of Oracle Corporation.

 

 

��  
 
 
Oracle Training at Sea
 
 
 
 
oracle dba poster
 

 
Follow us on Twitter 
 
Oracle performance tuning software 
 
Oracle Linux poster