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

 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
 Oracle Support

 SQL Tuning

 Oracle UNIX
 Oracle Linux
 Remote s
 Remote plans
 Application Server

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

 Remote S


 Consulting Staff
 Consulting Prices
 Help Wanted!


 Oracle Posters
 Oracle Books

 Oracle Scripts

Don Burleson Blog 







Purging AWR statistics from Oracle

Oracle Database Tips by Donald BurlesonJanuary 10, 2015

Question: I'm looking for a way to extract the full text of a SQL statement from a table into a flat file so that I can tune the SQL.  How do I extract a SQL statement?

Answer.  It is easy to purge un-used data from AWR.  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.

This script below will show you the total amount of space in the SYSAUX tablespace used by AWR.  To purge ALL of the statistics for a specific date backwards, you can invoke the following:

-- Set retention period to 90 days
exec dbms_stats.alter_stats_history_retention(90);

-- Display retention period:
select dbms_stats.get_stats_history_retention from dual;

-- Manually purge after x days and before
exec dbms_stats_purge_stats(SYSDATE-30);

However, the data portion of the AWR tables is heavily skewed and more than 80% of the historical data is kept within the AWR tables.  By periodically removing the SQL table rows, we keep the information that is important to forecasting and capacity planning while removing old SQL statements that will never be needed.

Let's take a closer look at how to purge the AWR SQL table data rows.

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

   segment_name c1,
   sum(bytes)/(1024*1024) c2
   segment_name like 'WR%'
group by
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.

   sql_id =
    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.

   sql_id =
          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