Oracle 11gR2 table analyze

Posted on 2011-04-21
Last Modified: 2012-05-11
We upgraded Oracle from 9i to 11gR last December. A procedure is running slower and slower: from 5 minutes to several hours. I manually analyzed the related tables. It then run fast again. We used to analyze all our tables weekly, we stopped doing that because we were told that we don't need to analyze table anymore in 11gR2 because Oracle will do it automatically. But the result indicated that we still need to manually analyze our tables. I am confused. Do we need to manually analyze our tables or not in 11gR2?

Question by:luchuanc
    LVL 76

    Expert Comment

    by:slightwv (䄆 Netminder)
    Didn't we just address this in your previous question?

    Yes: tables need to be analyzed on a regular basis.  How often depends on how often major changes happen that could affect execution plans.

    If the tables are not analyzed as part of a maintenance window, then you need to do it somehow.
    LVL 14

    Expert Comment

    LVL 76

    Expert Comment

    by:slightwv (䄆 Netminder)
    Should also add that you can check important tables and indexes LAST_ANALYZED column in user_tables and user_indexes (or the ALL_/DBA_ level views)
    LVL 76

    Expert Comment

    by:slightwv (䄆 Netminder)

    That link is the 10g gather_stats_job not 11g.  Keep Googling...

    In 11g, there is no GATHER_STATS_JOB. It has been now incorporated into DBMS_AUTO_TASK_ADMIN job along with Automatic segment advisor and Automatic tuning advisor. All these 3 run in all maintenance windows. New maintenance windows introduced with 11g are
    LVL 14

    Assisted Solution

    Infact the link says it too...

    These 3 maintainance tasks are clubbed in to DBMS_AUTO_TASK_ADMIN  job, that should be enabled and can be done by:

        client_name => 'auto optimizer stats collection',
        operation => NULL,
        window_name => NULL);
    LVL 76

    Expert Comment

    by:slightwv (䄆 Netminder)
    Agreed.  As long as they are in an active maintenance window.

    Please review the askers previous question.  I covered all this there.
    LVL 76

    Expert Comment

    by:slightwv (䄆 Netminder)
    Here is the reference from the other question:
    11g has a pre-configured maintenance window that 'should' automatically do this.  Maybe something in your environment turned it off.

    Check out:  automatic optimizer statistics collection

    Author Comment

    Hi slightwv/ajexpert:,
    The auto analyze seems partially working. The following sql result shows that only a small portiion of tables are auto analyzed every day.  How to control/see which tables to be auto analyzed? How to make all tables to be auto analyzed?

    Thanks a lot,
      1  SELECT trunc(last_analyzed), count(*)
      2    FROM all_tab_statistics WHERE owner = 'AXIUM'
      3*   group by trunc(last_analyzed) order by 1 desc
    SQL> /

    --------- ----------
    21-APR-11         25
    20-APR-11         10
    19-APR-11          3
    16-APR-11          3
    15-APR-11          4
    14-APR-11          5
    13-APR-11          6
    12-APR-11          5
    09-APR-11          6
    08-APR-11          5
    07-APR-11          2
    06-APR-11          4
    05-APR-11          3
    03-APR-11          2
    02-APR-11          2
    01-APR-11          4
    31-MAR-11          3
    30-MAR-11          3
    26-MAR-11          3
    24-MAR-11          2
    23-MAR-11          4
    22-MAR-11          1
    18-MAR-11          3
    17-MAR-11          2
    16-MAR-11          2
    15-MAR-11          1
    12-MAR-11          1
    10-MAR-11          1
    09-MAR-11          3
    08-MAR-11          1
    04-MAR-11          2
    03-MAR-11          4
    02-MAR-11          1
    01-MAR-11          2
    26-FEB-11          3
    25-FEB-11          1
    17-FEB-11          1
    16-FEB-11          1
    12-FEB-11          2
    11-FEB-11          1
    10-FEB-11          2
    09-FEB-11          1
    02-FEB-11          1
    29-JAN-11          1
    28-JAN-11          1
    26-JAN-11          1
    25-JAN-11          1
    05-JAN-11          2
    24-DEC-10          1
    23-DEC-10          1
    17-DEC-10          2
    11-DEC-10        360

    53 rows selected.

    LVL 76

    Expert Comment

    by:slightwv (䄆 Netminder)
    Everything you need to know is in the doc link I provided.

    >>How to make all tables to be auto analyzed?

    Are you sure you want to do this?  

    If you review the link I provided in the docs, Oracle looks to see what tables 'need' their stats updated.

    Excerpt from link:
    "prioritizes database objects that require statistics, so that objects that most need updated statistics are processed first, before the maintenance window closes."

    Also check out the section:  When to Use Manual Statistics

    If you still wish to manually generate them, check out the section:
    Gathering Statistics Manually


    Author Comment

    Hi slightwv:
    That document seems no details on how oracle determine the objects that most need updated statistics. We need a few tables to be analyzed weekly. How to tell oracle to analyze certain tables weekly?

    Thanks a lot,
    LVL 76

    Accepted Solution

    What makes you think you MUST perform this on a few tables?

    Same doc:

    Automatic optimizer statistics collection should be sufficient for most database objects being modified at a moderate speed. However, in some cases the collection may not be adequate. Because the collection runs during maintenance windows, the statistics on tables that are significantly modified throughout the day may become stale. There are typically two types of such objects:

        *      Volatile tables that are deleted or truncated and rebuilt during the course of the day.
        *      Objects that are the target of large bulk loads which add 10% or more to the object's total size.

    If you still want to physically do a few tables, I would create my own job and physically call:  DBMS_STATS.GATHER_TABLE_STATS

    This will allow you personally tweak the settings for the individual tables.  For example, you might want to change sample sizes across the tables or even do a full compute.

    Author Closing Comment

    Hi slightwv/ajexpert,
    This is good for me now.
    Thanks a lot for your help.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Suggested Solutions

    Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
    Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
    This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
    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.

    794 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

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now