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

Similar Messages

  • 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?

  • 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

  • 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.

  • 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?

  • Gather Schema Statistics - GATHER AUTO option failing to gather stats

    Hi ,
    We recently upgraded to 10g DB and 11.5.10 version of Oracle EBS. I want to employ GATHER AUTO option while running Gather Schema Statistics.
    To test the working, I created a test table with 1 million rows. Then, stats were gathered for this table alone by using Gather Table Stats. Now, I deleted ~12% of rows & issued commit. The table all_tab_statistics shows that the table has stale statistics (stale stats column = YES). After that I ran Gather Schema Stats for that particular schema. But the request did not pick the test table to be gathered.
    What is the criterion on which Oracle chooses which all tables to be gather statistics for under Gather Auto option? I am aware of the 10% change in data, but how is this 10% calculated? Is it only based on (insert + update + delete)?
    Also, what is the difference between Gather Auto and Gather Stale ?
    Any help is appreciated.
    Thanks,
    Jithin

    Randalf,
    FYI.. this is what happens inside the concurrent progarm call.. there are a few additional parameters for output/ error msgs:
    procedure GATHER_SCHEMA_STATS(errbuf out varchar2,
    retcode out varchar2,
    schemaname in varchar2,
    estimate_percent in number,
    degree in number ,
    internal_flag in varchar2,
    request_id in number,
    hmode in varchar2 default 'LASTRUN',
    options in varchar2 default 'GATHER',
    modpercent in number default 10,
    invalidate in varchar2 default 'Y'
    is
    exist_insufficient exception;
    bad_input exception;
    pragma exception_init(exist_insufficient,-20000);
    pragma exception_init(bad_input,-20001);
    l_message varchar2(1000);
    Error_counter number := 0;
    Errors Error_Out;
    -- num_request_id number(15);
    conc_request_id number(15);
    degree_parallel number(2);
    begin
    -- Set the package body variable.
    stathist := hmode;
    -- check first if degree is null
    if degree is null then
    degree_parallel:=def_degree;
    else
    degree_parallel := degree;
    end if;
    l_message := 'In GATHER_SCHEMA_STATS , schema_name= '|| schemaname
    || ' percent= '|| to_char(estimate_percent) || ' degree = '
    || to_char(degree_parallel) || ' internal_flag= '|| internal_flag ;
    FND_FILE.put_line(FND_FILE.log,l_message);
    BEGIN
    FND_STATS.GATHER_SCHEMA_STATS(schemaname, estimate_percent,
    degree_parallel, internal_flag, Errors, request_id,stathist,
    options,modpercent,invalidate);
    exception
    when exist_insufficient then
    errbuf := sqlerrm ;
    retcode := '2';
    l_message := errbuf;
    FND_FILE.put_line(FND_FILE.log,l_message);
    raise;
    when bad_input then
    errbuf := sqlerrm ;
    retcode := '2';
    l_message := errbuf;
    FND_FILE.put_line(FND_FILE.log,l_message);
    raise;
    when others then
    errbuf := sqlerrm ;
    retcode := '2';
    l_message := errbuf;
    FND_FILE.put_line(FND_FILE.log,l_message);
    raise;
    END;
    FOR i in 0..MAX_ERRORS_PRINTED LOOP
    exit when Errors(i) is null;
    Error_counter:=i+1;
    FND_FILE.put_line(FND_FILE.log,'Error #'||Error_counter||
    ': '||Errors(i));
    -- added to send back status to concurrent program manager bug 2625022
    errbuf := sqlerrm ;
    retcode := '2';
    END LOOP;
    end;

  • Gather Schema Statistics improve the performance of the R12 application?

    Hi All,
    If we run “Gather Schema Statistics” program, it will improve the performance of the R12 application?
    Platform Linux and DB version 10.2.0.4.
    Thanks & Regards,
    Tharun

    Hi Tharun,
    If we ruer n “Gather Schema Statistics” program, it will improve the performance of the R12 application?
    Yes, it will speed up as it ensures to have an up to date statistics.
    Please refer notes:
    Concurrent Processing - How To Gather Statistics On Oracle Applications Release 11i and/or Release 12 - Concurrent Process,Temp Tables, Manually [ID 419728.1]
    How Often Should Gather Schema Statistics Program be Run? [ID 168136.1]
    Why Stats Gather?
    Stats gathering must be set as a routine job and is recommended to be scheduled. Even though this program is available from the fronted in the form of submitting a concurrent program basically it performs a DB level enhancement and ensures that you have an up to date optimizer statistics.Because the objects in a database can be constantly changing, statistics must be regularly updated so that they accurately describe these database objects.
    For indepth understand as to why it should be run, please refer doc:
    Managing Optimizer Statistics
    Thanks &
    Best Regards,

Maybe you are looking for

  • Error message on download attempt

    I started this issue back on the Motion board (when it was a Motion-specific issue) but this has become an AppStore issue, so: After purchasing Motion from the AppStore I could not launch the app at all so I trashed it and redownloaded it once and, u

  • How to write two triggers on same table how it works?

    Hello sir.. I have to write two triggers on same table for auditing different columns of different pages (may be different modules). I will have an audit table in which i will insert data such as (user_id,module_id,column_name,old_col_val,new_col_ va

  • Blackberry stolen - how to I delete my app world account

    Hi, some time ago I had my blackberry stolen. I reported to carrier and they blocked etc so no issue there. however, how do I now cancel my blackberry Id - I was also subscribed to blackberry music and I'm still being charged the monthly fee but don'

  • I can't get Photoshop Elements 9 to open... after 3 years of working perfectly.

    Can anyone help me?  Bob

  • Spry Menu bar file

    Hi, While running link checker on my site, I discovered the SpryMenuBar.js file is shown as a broken link (and probably why when i view my site in a browser, none of the drop down menus work). I searched my hard drive and the file is nowhere to be fo