How to adjust the threshold for statistics to become stale in Oracle 11g

I was asked recently in one of my seminars if it is possible to adjust the threshold value for optimizer statistics to be considered being stale in Oracle database 10g. 

oracle_10g_database.jpg As you all know there is an auto task job which is automatically created with every Oracle 10g database called gather_stats_job which automatically collects statistics every night and on the weekend by default for all object for which more of 10% of the values have changed. This behaviour is enabled by default in 10g and is implemented by TABLE MONITORING which is enabled for all tables by default.

In Oracle 10g the 10% threshold is a hard coded value and cannot be adjusted. This is a particularly painful with columns with skewed data in large tables.  Here you would have to lock the statistics and gather them manually when needed with an adjusted sample size of probably more than 10%, because otherwise you would get terrible execution plans possibly. 

oracle_11g_database.jpg In Oracle database 11g there is a new procedure in the DBMS_STATS package we can use to even set individual thresholds on segment level.
Here is  how it works:

lutz@ora11gBETA5 _SQL > exec dbms_stats.set_table_prefs(’HR’, EMPS’, ‘STALE_PERCENT’, ‘15′)

The previous statement adjusts the threshold for the table EMPS owned by HR to 15%.  

All togehter there are three new parameters in DBMS_STATS:
- STALE_PERCENT which overwrites the default threshold of 10%
- INCREMENTAL for statistics on partitions incrementally gathered
- PUBLISH in order to populate the data dictionary with the newly gathered statistics or not, whcih can conme in handy if you want to test with the new statistics on another system before really making them effective on production.

I think that this is exactely what a lot of people have been waiting for since a long time

3 Responses to “How to adjust the threshold for statistics to become stale in Oracle 11g”

  1. Barney Watson Says:

    What exactly is meant by 10% of the values have changed? Is it (number of inserts + number of deletes + number of updates) / (origional number of rows) ?

  2. Lutz Hartmann Says:

    Hi Barney,
    you are absolutely right, I was not precise enough:
    it is definitely 10% of the rows have changed, not the values.
    BR,
    =;-)
    Lutz

  3. Nasir Says:

    In oracle 10g,How can we find out how much percentage of Data has changed in the table during 1 day? And also how does oracle track those changes.

Leave a Reply