Different Ways To Gather Table Statistics

Can anyone tell me the difference(s), if any, between these two ways to refresh table stats:
1. Execute this procedure which includes everything owned by the specified user
EXEC DBMS_STATS.gather_schema_stats (ownname => 'USERNAME', degree => dbms_stats.auto_degree);
2. Execute this statement for each table owned by the specifed user
analyze table USERNAME.TABLENAME compute statistics;
Generally speaking, is one way better than the other? Do they act differently and how?

In Oracle's automatic stats collection, not all object are included in stats collection.
Only those tables, which has stale stats are taken for stats collection. I don't remember on top of my head, but its either 10% or 20% i.e. the tables where more than 10% (or 20%) data has changed are maked as stale. And only those stale objects will be considered for stats collection.
Do you really think, each and every object/table has to be analyzed every day? How long does it take when you gather stats for all objects?

Similar Messages

  • Gather Table Statistics (Stats) Crashing Application

    Hello
    Just started a new place of work which has a 9i database with a VB Front End App.
    Noticed in the Database no stats had been gathered for any objects (ever).
    I decided to run a gather stats procedure on a particular heavily-used table but it caused the application to crash/freeze?
    begin
    dbms_stats.gather_table_stats(OWNNAME=>     , TABNAME=>     ,
    ESTIMATE_PERCENT=> dbms_stats.auto_sample_size,
    METHOD_OPT=> 'FOR ALL COLUMNS SIZE 1', CASCADE=>TRUE);
    end;
    I decided to use auto sample size and decided to also gather stats on indexes (and without CASCADE=FALSE) but appeared to crash the application. The job itself worked fine.
    Anyone ever encountered such issue? Could there be any reason for this (i.e. no stats ever gathered)?
    Thanks
    Edited by: user636420 on Jan 22, 2010 9:22 AM

    I have found something interesting..........
    Prior to Oracle 10g, Oracle's default optimizer mode was called “choose.” In the choose optimizer mode, Oracle will execute the rule-based optimizer if there are no statistics present for the table; it will execute the cost-based optimizer if statistics are present. The danger with using the choose optimizer mode is that problems can occur in cases where one Oracle table in a complex query has statistics and the other tables do not.
    This probably explains the fact that I am gathering statistics for 1 table and not the others.
    Just checked the explain plan for a particular SQL query and it's using CHOOSE optimizer mode.
    Edited by: user636420 on Jan 22, 2010 9:35 AM

  • Gather table Statistics

    i need collect the statistics for few tables from a schema. i am doing the following:
    i am creating a table to save the statistics.
    begin
    dbms_stats.create_stat_table(ownname =>'TEST',
    statab =>'TEST_ORD',);
    end;
    and then i am gathering the table stats for a particular table as follows:
    exec dbms_stats.gather_table_stats(
    ownname => 'BNS',
    estimate_percent =>'10,
    statown =>'TEST',
    tabname =>'ORDERS',
    stattab =>'TEST_ORD',
    statid =>'CR');
    my question is how can do for multiple tables ? the reason is i have to create a Job to run this script automatically daily.
    can i put this into a procedure? or any other ideas?
    Appreciate all your help!

    In many environments the default job does a pretty good job of generating statistics, but I have to agree that there are environments where the default job does not produce very good statistics which is why I mentioned the ability to lock statistics. For anyone who has not had to deal with statistics much you can generate a workable set of statistics manually and then lock them in place so the provided automatich statistics generation task does not re-generate a specific set of statistics.
    Also by default the 10g task collects histograms. If histograms were not in use in 9i then removing the histograms often 'fixes' most of the query performance issues encounted upon upgrading to 10g in these cases. 11g adds the ability set dbms_stats parameters at the table level and have those settings retained for use with future stats collection.
    Yes cron assumes a UNIX (or Linux) platform but Windows also has a job scheduler available. I am not sure what difference RAC would make. We use cron tasks against RAC all the time. We do normally just run the tasks against the local instance.
    Nicely organized script/code library.
    HTH -- Mark D Powell --

  • Best Way to gather statistics in 10g

    Hi All,
    What is the best way to gather optimizer statistics in 10g databases? We are currently following the default automatic statistics gathering feature of 10g. But we feel it has got some shortcomings. For many of the tables the stats are not up to date. Also we have hit one bug in 10g which can cause "cursor: pin S wait on X " during stats gathering (As given in metalink note).
    So what do you experts feel about the issue. What would be the best way to gather stats=> manual or auto?
    Regards
    Satish

    The right reply to your question is "it depends". It depends on your application systems,
    the amount of change that your data suffers during time and your queries. You can choose what statistics to gather and when. You have to know your data and your application, though. There is no simple answer, right for everyone, which could be dispensed and set as a "golden
    rule". The great site with many useful articles about statistics is Wolfgang Breitling's site:
    www.centrexcc.com. That is for starters. Your question is far from trivial and is not easily answered. The best reply you can get is "it depends".

  • How often we need to run gather schema statistics etc.. ??

    HI,
    Am on 11.5.10.2
    RDBMS 9.2.0.6
    How often we need to run the following requests in Production...
    1.Gather schema statistics
    2.Gather Column statistics
    3.Gather Table statistics
    4.Gather All Column statisitics
    Thanks

    Hi;
    We discussed here before about same issue. Please check below thread which could be helpful about your issue:
    How often we need to run gather schema statistics
    Re: Gather schema stats run
    How we can collect custom schema information wiht gather statistics
    gather schema stats for EBS 11.5.10
    gather schema stats conc. program taking too long time
    Re: gather schema stats conc. program taking too long time
    How it runs
    Gather Schema Statistics
    http://oracle-apps-dba.blogspot.com/2007/07/gather-statistics-for-oracle.html
    gather statistict collect which informations
    Gather Schema Statistics...
    Regard
    Helios

  • Gather Schema Statistics issue?

    Hi
    Actually, we have a custom schema in our EBS R12.0.6 instance database. But i have observed that, 'Gather Schema Statistics' program is not picking-up this schema. why? May be something wrong with database schema registration but since 1 & half year the interface associated with this schema is running fine. I do not know,how to resolve this issue?
    I can manually run 'Gather Table Statistics' program against all tables.
    Regards

    Hi;
    Actually, we have a custom schema in our EBS R12.0.6 instance database. But i have observed that, 'Gather Schema Statistics' program is not picking-up this schema. why? May be something wrong with database schema registration but since 1 & half year the interface associated with this schema is running fine. I do not know,how to resolve this issue?For can run hather stat for custom schema please check
    gather schema stats for EBS 11.5.10
    gather schema stats for EBS 11.5.10
    I can manually run 'Gather Table Statistics' program against all tables. Please see:
    How To Gather Statistics On Oracle Applications 11.5.10(and above) - Concurrent Process,Temp Tables, Manually [ID 419728.1]
    Also see:
    How to work Gather stat
    Gather Schema Statistics
    http://oracle-apps-dba.blogspot.com/2007/07/gather-statistics-for-oracle.html
    Regard
    Helios

  • Table statistics delete

    Hi
    Is there any command to delete gathered statistics of a table
    suppose : I have gather table statistics as under
    exec dbms_stats.gather_table_stats('TEST1','EMP');
    now I want to delete the statistics from the above table EMP
    Regards
    Jewel

    The package dbms_stats is fully documented in the Oracle supplied package and type reference manual for your unknown version of Oracle.
    It has a call to delete statistics.
    As per forums etiquette, please do the obvious first and consult documentation.
    Sybrand Bakker
    Senior Oracle DBA

  • Temp table, and gather table stats

    One of my developers is generating a report from Oracle. He loads a subset of the data he needs into a temp table, then creates an index on the temp table, and then runs his report from the temp table (which is a lot smaller than the original table).
    My question is: Is it necessary to gather table statistics for the temp table, and the index on the temp table, before querying it ?

    It depends yesterday I have very bad experience with stats one of my table has NUM_ROWS 300 and count(*)-7million and database version is 9206(bad every with optimizer bugs) so queries starts breaking and lot of buffer busy and latch free it took while to figure out but I have deleted the stats and every thing came under control - my mean to say statistics are good and bad. Once you start collecting you should keep an eye.
    Thanks.

  • How to gather table stats for tables in a different schema

    Hi All,
    I have a table present in one schema and I want to gather stats for the table in a different schema.
    I gave GRANT ALL ON SCHEMA1.T1 TO SCHEMA2;
    And when I tried to execute the command to gather stats using
    DBMS_STATS.GATHER_TABLE_STATS (OWNNAME=>'SCHMEA1',TABNAME=>'T1');
    The function is failing.
    Is there any way we can gather table stats for tables in one schema in an another schema.
    Thanks,
    MK.

    You need to grant analyze any to schema2.
    SY.

  • Can I gather object statistics on large tables at the same time?

    We have large partitioned tables to the tune of 3-4 billion rows, and they have no object statistics. Can I gather object statistics for them at the same time? For example, 4-5 large tables at the same time. I need to gather them in multiple tables because we have several of those large tables and I have to schedule the gathering carefully. So, I want to start at 4 tables. I'm wondering if gathering statistics on the above tables will be intrusive or will impact the performance while it is running.
    Alex

    What version are you running? If you are running 11g they are automatically gathered via the autotask job DBMS_STATS.GATHER_DATABASE_STATS_JOB_PROC which, depending on your window, will normally run daily at 10 pm. Im very surpised that no stats have been gathered as this collects stats on all new tables or if more than 10% of rows have been changed.
    See the following links:
    http://www.oracle-base.com/articles/11g/automated-database-maintenance-task-management-11gr1.php
    http://docs.oracle.com/cd/B28359_01/server.111/b28274/stats.htm

  • FNDGSCST module: Gather Schema Statistics - ERROR: While GATHER_TABLE_STATS

    Hi
    I ran gather schema Statistics
    In GATHER_SCHEMA_STATS , schema_name= ALL percent= 10 degree = 4 internal_flag= NOBACKUP
    the error are:
    stats on table AQ$_WF_CONTROL_P is locked
    stats on table FND_CP_GSM_IPC_AQTBL is locked
    Error #1: ERROR: While GATHER_TABLE_STATS:
    object_name=AP.JE_FR_DAS_010***ORA-20001: invalid column name or duplicate columns/column groups/expressions in method_opt***
    Error #2: ERROR: While GATHER_TABLE_STATS:
    object_name=AP.JE_FR_DAS_010_NEW***ORA-20001: invalid column name or duplicate columns/column groups/expressions in method_opt***
    Error #3: ERROR: While GATHER_TABLE_STATS:
    object_name=AP.JG_ZZ_SYS_FORMATS_ALL_B***ORA-20001: invalid column name or duplicate columns/column groups/expressions in method_opt***
    I ran this while ago.
    anyone can help me to fix it
    Thanks

    Please see old threads which discuss the same issue -- http://forums.oracle.com/forums/search.jspa?threadID=&q=Gather+AND+Schema+AND+Statistics+AND+ORA-20001&objID=c3&dateRange=all&userID=&numResults=15&rankBy=10001
    Thanks,
    Hussein

  • Import Table Statistics to another table

    Hi,
    Just like to know if I can use dbms_stats.import_table_stats to import table statistics to another table?
    Scenario:
    I exported the table statistics of the table (T1) using the command below.
    exec dbms_stats.export_table_stats('<user>','T1',NULL,'<stat table>');
    PL/SQL procedure successfully completed.
    And then, I have another table named T2, T1 and T2 are identical tables. T2 does not have statistics (I intentionally did not run gather statistics). I am wondering
    if I can import table statistics from T1 to T2 using dbms_stats package?.
    For what I understand, statistics can be imported back at the same table which is T1 but not for another table using dbms_stat package. If I am wrong, anyone can correct me.
    Thanks

    hi
    just try ;-) you lose nothing probably,
    check afterwards last_analyzed value for that table in user_tables
    if something is wrong, run regular stats

  • Gather Schema Statistics

    Hi All,
              When I run gather schema statistics, it is completing status normal .  But it took only 45 min.
              EBS - 12.1.3
                 DB - 11.2.0.3
                 OS - RHEL  64
              As per my understanding , it will take 2-3 hrs. After DB upgraded to 11.2.0.3, got an completd with error and followd the note: Gather Schema Statistics fails with Ora-20001 errors after 11G database upgrade [ID 781813.1]
              After that it completd with normal. But it took time only 45 min max in every run. with percentage 10 and 40. My DB size is 90 GB
    Request Log file:
    Start of log messages from FND_FILE
    +---------------------------------------------------------------------------+
    In GATHER_SCHEMA_STATS , schema_name= ALL percent= 40 degree = 8 internal_flag= NOBACKUP
    stats on table FND_CP_GSM_IPC_AQTBL is locked
    stats on table FND_SOA_JMS_IN is locked
    stats on table FND_SOA_JMS_OUT is locked
    +---------------------------------------------------------------------------+
    End of log messages from FND_FILE
    +---------------------------------------------------------------------------+
    Start of log messages from FND_FILE
    +---------------------------------------------------------------------------+
    In GATHER_SCHEMA_STATS , schema_name= ALL percent= 10 degree = 8 internal_flag= NOBACKUP
    stats on table FND_CP_GSM_IPC_AQTBL is locked
    stats on table FND_SOA_JMS_IN is locked
    stats on table FND_SOA_JMS_OUT is locked
    +---------------------------------------------------------------------------+
    End of log messages from FND_FILE
    +---------------------------------------------------------------------------+
    Now I querey the below :
    SQL> select column_name, nvl(hsize,254) hsize from FND_HISTOGRAM_COLS where table_name = 'JE_BE_LINE_TYPE_MAP' order by column_name;
    COLUMN_NAME                         HSIZE
    SOURCE                                254
    a)   Is this an expected behavior ?
    b)   If not, please suggest, to fix
    Thanks
    SAL

    Did the concurrent program fail? -- Gather Schema Statistics Fails With Error For APPLSYS Schema (Doc ID 1393184.1)
    Please check the LAST_ANALYZED column of DBA_TABLES and DBA_INDEXES views (Note: 166346.1 - How to Determine When a Table Was Last Analyzed By the Gather Schema Statistics Program).
    Thanks,
    Hussein

  • Gather system statistics

    Hi Friends,
    I want to gather system statistics in my Oracle 9.2.07 (windows) environment...
    created one statistics table...
    execute DBMS_STATS.CREATE_STAT_TABLE ('SYS','MY_STATS');
    (2) Gathering SYSTEM Statistics Script during office hours ( 8 hours) (8am to 4pm)
    begin
    execute dbms_stats.gather_system_stats(
    gathering_mode=> 'interval',
    interval => 480,
    stattab=> 'MY_STATS',
    STATID=> 'OLTP');
    END;
    REM
    REM
    REM END of Script
    REM===================================================
    (3) Import the Collected System Statistics
    Import the statistics daily around 8AM...because..users starts entering the transactions....
    variable jobno number;
    begin
    dbms_job.submit(:jobno,'dbms_stats.import_system_stats(''IMAL_STATS'',''OLTP'');',
    SYSDATE,'SYSDATE+1');
    COMMIT;
    END;
    ========================================================
    OLAP..also i will collect during night time....
    gathering system statiscs will end after 4pm....so..it takes system statistics during 8 hours interval time...and i am going to import them next day 8am..
    is this the correct method????.please sched some light on this...

    Hi,
    Oracle recommends to gather system statistics from oracle 9i onwards....this the line from Oracle 9i R2 document...
    Oracle9i Database Performance Tuning Guide and Reference
    Release 2 (9.2)
    Gathering System Statistics
    System statistics enable the optimizer to consider a system's I/O and CPU performance and utilization. For each plan candidate, the optimizer computes estimates for I/O and CPU costs. It is important to know the system characteristics to pick the most efficient plan with optimal proportion between I/O and CPU cost.
    System I/O characteristics depend on many factors and do not stay constant all the time. Using system statistics management routines, database administrators can capture statistics in the interval of time when the system has the most common workload. For example, database applications can process OLTP transactions during the day and run OLAP reports at night. Administrators can gather statistics for both states and activate appropriate OLTP or OLAP statistics when needed. This enables the optimizer to generate relevant costs with respect to available system resource plans.
    When Oracle generates system statistics, it analyzes system activity in a specified period of time. Unlike table, index, or column statistics, Oracle does not invalidate already parsed SQL statements when system statistics get updated. All new SQL statements are parsed using new statistics. Oracle Corporation highly recommends that you gather system statistics.The DBMS_STATS.GATHER_SYSTEM_STATS routine collects system statistics in a user-defined timeframe. You can also set system statistics values explicitly using DBMS_STATS.SET_SYSTEM_STATS. Use DBMS_STATS.GET_SYSTEM_STATS to verify system statistics.
    So better performanace, as per above document, we need system statistics.
    if not needed.why it is not need...can u please describe this...
    Message was edited by:
    bsubbu

  • Table statistics

    Greetings All,
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
    Windows 2008 R2I had 18 unexplained columns appear on a table in one of the schemas. The column names are like SYS_000080$, SYS_000079$, ...
    Anybody know if gathering statistics on the table will add columns to the table being analyzed, then dropped when stats have been collected?
    I'm thinking (read as HOPE) that the gathering of statistics on this table was interrupted, hence leaving the extra columns.
    Below is the SQL used to gather the stats.
           dbms_stats.gather_schema_stats (
                                    ownname => 'schema_name_here',
                         estimate_percent => DBMS_STATS.AUTO_SAMPLE_SIZE,
                                method_opt => 'FOR ALL COLUMNS SIZE AUTO',
                                      cascade => TRUE,
                                       options => 'GATHER',
                                       degree => 6);Can anyone confirm my suspicion please?
    Thanks for your time,
    Bob

    Snyds wrote:
    I posted the SQL used to gather the statistics. Not sure what else you expect for post sql.
    The results:
    There are 18 (new/additional) columns that have been appended to the end of the table. All of these new columns begin with "SYS_000" and end with 2 more digits and the dollar sign (i.e. SYS_00070$, SYS_00079$, SYS_00078$, and so on). These new columns are not consecutive, in that SYS_00079$ may not be the column after the column called SYS_00078$. There are gaps in the numeric protion on nthe new column names. These new columns, that begin with SYS_0000, do not belong on the table.
    I don't know what other results you expect to see.
    Bobwhat exactly is the SQL that displays SYS_00070$, SYS_00079$, SYS_00078$?
    Do you understand that Oracle will generate object names for things like INDEX or CONSTRAINT?

Maybe you are looking for

  • My Ipod touch 5th Gen wont turn on or charge...

    My week old Ipod touch 5th gen. wont turn on or charge. When it is connected to the computer or a charger it shows the dead battery symbol and never charges even if left connected for over and hour.

  • Only starts up in Windows Vista does not start in Tiger

    I've got a Macbook Black running on Tiger and I've also got Windows Vista running thru boot camp. Last night I was running Tiger fine. I did get a msg telling me my startup disk was almost full. I didn't have the time to delete some files to make spa

  • How to install software to Linksys linux router?

    My WRT160NL says it runs Linux on a box, but there is no manual about using Linux on it. I would like to install a torrent program so my router could download torrent to the disk connected to it. How could I do this? Message Edited by Original on 08-

  • Labview project organization and management

    I am looking for advice/resources for organizing and managing moderate to large applications in labview. I have created an application with over 100 vi's and want to ensure the easiest management and maintenance of the code for the future. Does anyon

  • Application Server Form Template

    I am looking to install Oracle Application server 10G and also Oracle Database 10G in a development environment. I have installed Oracle 10G database before without any problems but don't have any development experience on the Application server .e.g