DBMS_STAT

Dear All,
When i should gather statistics on table or schema using DBMS_STAT
Thanks
Regards

You can check the dictionary views and see if they match the table contents,
SQL> create table test as select * from scott.emp;
Table created.
SQL> select count(*) from test;
  COUNT(*)
        14
SQL> select num_rows from user_tables where table_name='TEST';
  NUM_ROWS
SQL> exec dbms_stats.gather_table_stats(user,'TEST');
PL/SQL procedure successfully completed.
SQL>  select num_rows from user_tables where table_name='TEST';
  NUM_ROWS
        14Else you can check the last_analyzed column and see if the date is older. Also, read the below link,
http://download.oracle.com/docs/cd/E11882_01/server.112/e16638/stats.htm#PFGRF94738
HTH
Aman....

Similar Messages

  • COMPUTE INDEX vs. SYS.DBMS_STATS.GATHER_INDEX_STATS

    Hi,
    I've got an Oracle 9 database.
    I am creating an index. I had created this index using the following syntax:
    CREATE INDEX index1. . . . . . COMPUTE STATISTICS;
    One of my colleagues tells me that I should scrap 'COMPUTE STATISTICS' and instead make this a two step process:
    (1) CREATE INDEX index1. . . . .
    (2) SYS.DBMS_STATS.GATHER_INDEX_STATS
    OwnName => 'schema'
    ,IndName => 'index_name'
    ,Estimate_Percent => 10
    ,Degree => 4
    ,No_Invalidate => FALSE);
    Is there any advantage to using SYS.DBMS_STATS.GATHER_INDEX_STATS instead of 'COMPUTE STATISTICS'?
    Thanks,
    Tom

    9i references<br>
    In particular...<br>
    Deprecated at 10<br>

  • Error while using DBMS_STATS.GATHER_schema_STATS

    Hi All,
    My database just got upgraded from Oracle 9i to Oracle 11g.
    While everything else is working fine post upgrade Oracle, the DBMS_STATS.GATHER_schema_STATS with METHOD_OPT => 'FOR COLUMNS SIZE ALL' , which was working fine in Oracle 9i is throwing error after upgarde.
    Below is the error I received:
    SQL> execute DBMS_STATS.GATHER_schema_STATS ('cins_dm', METHOD_OPT => 'FOR COLUMNS SIZE AUTO');
    BEGIN DBMS_STATS.GATHER_schema_STATS ('cins_dm', METHOD_OPT => 'FOR COLUMNS SIZE AUTO'); END;
    ERROR at line 1:
    ORA-20001: method_opt should follow the syntax "[FOR ALL [INDEXED|HIDDEN] COLUMNS [size_caluse]]" when gathering statistics on a group of tables
    ORA-06512: at "SYS.DBMS_STATS", line 9641
    ORA-06512: at "SYS.DBMS_STATS", line 9716
    ORA-06512: at "SYS.DBMS_STATS", line 10048
    ORA-06512: at "SYS.DBMS_STATS", line 18939
    ORA-06512: at "SYS.DBMS_STATS", line 19132
    ORA-06512: at "SYS.DBMS_STATS", line 19088
    ORA-06512: at line 1
    OS Details:
    Has this option got obsolete in Oracle 11g?
    What is the alternative to this?
    OS and Databse Details*
    OS:
    scrbbiddkbry002:sas# uname -a
    SunOS scrbbiddkbry002 5.9 Generic_122300-51 sun4u sparc SUNW,Sun-Fire-V240
    Oracle Client:
    SQL*Plus: Release 9.2.0.1.0 - Production
    Oracle Server:
    SQL> select * from v$version;
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
    PL/SQL Release 11.1.0.7.0 - Production
    CORE 11.1.0.7.0 Production
    TNS for Solaris: Version 11.1.0.7.0 - Production
    NLSRTL Version 11.1.0.7.0 - Production
    Edited by: user13071592 on Aug 3, 2010 2:38 AM

    Hi,
    While going through the link, it seems that METHOD_OPT => 'FOR COLUMNS SIZE AUTO' is obsolete in Oracle 11g and I will have to use METHOD_OPT => 'FOR ALL COLUMNS SIZE AUTO' instead of that. But the option METHOD_OPT => 'FOR COLUMNS SIZE AUTO' used to take just 5 minutes to complete while METHOD_OPT => 'FOR ALL COLUMNS SIZE AUTO' is taking 1 hour.
    I want it to take time (5-6 minutes) which the original METHOD_OPT => 'FOR COLUMNS SIZE AUTO' was taking.

  • Error while trying to run DBMS_STAT.GATHER_TABLE_STATS

    Hi Gurus,
    I am trying to run DBMS_STAT.GATHER_TABLE_STATS from a procedure from a DBA role granted user I am getting the folowing error:
    ORA-20000: Unable to analyze TABLE "<SCHEMA_NAME>"."<TABLE_NAME>", insufficient privileges or does not exist
    ORA-06512: at "SYS.DBMS_STATS", line 13046
    ORA-06512: at "SYS.DBMS_STATS", line 13076
    ORA-06512: at line 2
    Is I am missing something?
    Please help...
    //saby

    It's a quite common problem...
    Privileges granted through roles doesn't work inside stored procedures. So the DBA role it's not working inside procedure.
    See Metalink Note 168168.1.
    If you want to run dbms_stats.gather_table_stats from inside procedure,
    you need to grant "ANALYZE ANY" directly to this user.
    Thanks
    Tomasz K.

  • Dbms_stats.gather_table_stats; What are the parameters you gurus use?

    DB Version :10.2.0.1.0
    Sometimes i want to collect the stats of just few tables. I use the following script to gather individual table stats. Are these parameters OK?
    begin
    dbms_stats.gather_table_stats(user, upper('table_name'), estimate_percent=>100,
        no_invalidate=>false);
    end;
    /

    Hi,
    Check this links
    [GATHER_TABLE_STATS Procedure|http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_stats.htm#i1036461]
    [Using the DBMS_STATS-package|http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:735625536552]
    [Analyze and DBMS_STATS|http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:4347359891525]
    Regards,

  • Error when running DBMS_STATS package

    Hi all.
    Oracle9i Enterprise Edition Release 9.2.0.4.0 - 64bit Production
    PL/SQL Release 9.2.0.4.0 - Production
    CORE 9.2.0.3.0 Production
    TNS for Solaris: Version 9.2.0.4.0 - Production
    NLSRTL Version 9.2.0.4.0 - Production
    I am trying to gather schema stats using dbms_stats package and I see the following:
    SQL> BEGIN DBMS_STATS.gather_schema_stats('SYSADM');
    2 END;
    3 /
    ERROR at line 1:
    ORA-29913: error in executing ODCIEXTTABLEOPEN callout
    ORA-29400: data cartridge error
    KUP-04040: file G534513-1004.txt in EXT_WINDIR not found
    ORA-06512: at "SYS.DBMS_STATS", line 9375
    ORA-06512: at "SYS.DBMS_STATS", line 9857
    ORA-06512: at "SYS.DBMS_STATS", line 10041
    ORA-06512: at "SYS.DBMS_STATS", line 10095
    ORA-06512: at "SYS.DBMS_STATS", line 10072
    ORA-06512: at line 1
    The directory exists but the file is long gone. How can I get around this error?
    Thanks

    See if this helps,
    ERROR WITH EXTERNAL TABLE
    HTH
    Aman....

  • Questions in dbms_stats parameter

    Hello, I am using oracle9i.
    I have couple of questions when i read this help...
    http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_stats.htm#i1036461
    I would appreciate if any one could answers my questions.
    Question1
    =======
    Method_opt parameter.
    - AUTO : Oracle determines the columns to collect histograms based on data distribution and the workload of the columns.
    - SKEWONLY : Oracle determines the columns to collect histograms based on the data distribution of the columns.
    I understand about SKEWONLY. In AUTO determine the column based on data distribution and workload of the columns... What is workload of the column? Is this based on how many queries run based on that column? How does oracle track this?
    Question2
    ======
    Method_opt Parameter.
    SIZE integer
    My understanding is, when we specify size 1, then it creates only one bucket. Even though, we have more then one distinct value in the column.
    Let us say, we have 10 distinct values in a column, if we specify SIZE 5, then it creates only 5 bucket. But we have 10 distinct values... How does this work in this scenario?
    Let us say, we have 5 distinct values in a column, if we specify SIZE 10, then it creates 10 bucket. But we have 5 distinct values... How does this work in this scenario?

    There is a table called col_usage$ that stores information about column usage. The dbms_stats package uses this to determine whether on not a histogram will be gathered on a given column. How it determines whether or not to gather histograms from the given data I don't know exactly.
    size 1 means that there is no histogram as all values are in a single bucket.
    10 Distinct values and only 5 buckets, means you get height balanced histograms and you will evenly spread sampled values through the buckets.
    You will have a max and min values. The optimizer uses a formula which estimates selectivity by a range of factors such as min max value in a bucket, size of the bucket, number of values per bucket, and how popular a given value is(number of buckets value appears in)
    5 Distinct values and 10 buckets, give you a frequency histograms. You will only have 5 buckets each with 1 value. There is no point in having an empty bucket. Frequency histograms are more accurate as the exact number of occurrences of a given value are known. They calculate selectivity based on the number of occurrences of a value per bucket over the total number of occurrences of all values.

  • How to set dbms_stats parameters for a single table

    Hi,
    I see that dbms_stats has the following procedure:
    PROCEDURE SET_PARAM
    Argument Name Type In/Out Default?
    PNAME VARCHAR2 IN
    PVAL VARCHAR2 IN
    Is there a way to change the parameters only for a single table?
    I need to set METHOD_OPT=>'FOR ALL COLUMNS SIZE 1' only for a specific table...

    I'm sorry, mate. It looks like setting individual table preferences was introduced in 11g (and doesn't seem to work all that well).
    You can still:
    1. Explicitly specify any of the supported parameters by using DBMS_STATS.GATHER_TABLE_STATS() for the individual table and run it along.
    2. Write a PL/SQL wrapper for let's say DBMS_STATS.GATHER_SCHEMA_STATS/GATHER_DTABASE_STATS that would gather the stats for the whole schema but ignore this particular table. Then gather the stats for the table with the METHOD_OPT parameter of your choice that could be different from the one used for the rest of the schema.
    This could be achieved by locking particular table stats with DBMS_STATS.LOCK_TABLE_STATS, running GATHER_SCHEMA_STATS with force=>FALSE (which is the default). That parameter will make the procedure ignore any tables with locked stats. As the last step of the wrapper you can execute DBMS_STATS.GATHER_TABLE_STATS for the table in question with the desired METHOD_OPT and force=>TRUE.
    It's a little more work, but may solve your problem.
    Max
    Edited by: Max Seleznev on Nov 28, 2012 6:21 PM
    Edited by: Max Seleznev on Nov 28, 2012 6:22 PM

  • Link with examples of using dbms_stats package

    Please,
    Should Someone let me know when I could find a link or some example on using the new DBMS_STATS package to gather data statisitcs?
    Thanks

    All, made in Oracle:
    http://download-west.oracle.com/docs/cd/B19306_01/server.102/b14231/general.htm#sthref1861
    http://download-west.oracle.com/docs/cd/B19306_01/server.102/b14211/stats.htm#PFGRF30102
    http://download-west.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_stats.htm#sthref7887
    http://download-west.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_stats.htm#sthref7903
    http://download-west.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_stats.htm#ARPLS059

  • Error using dbms_stats.drop_extended_stats

    Hi!
    I have the following problem:
    I want to drop extended stats and i get the following error:
    SQL> begin
    2 dbms_stats.drop_extended_stats (
    3 ownname => 'ORAP'
    4 ,tabname => 'TDORGEH'
    5 ,extension => '(O2_KOE||''*'')'
    6 );
    7 end;
    8 /
    begin
    FEHLER in Zeile 1:
    ORA-00001: Unique Constraint (SYS.I_WRI$_OPTSTAT_HH_OBJ_ICOL_ST) verletzt
    ORA-06512: in "SYS.DBMS_STATS", Zeile 8443
    ORA-06512: in "SYS.DBMS_STATS", Zeile 8497
    ORA-06512: in "SYS.DBMS_STATS", Zeile 31747
    ORA-06512: in Zeile 2
    SQL> SELECT extension_name, extension
    2 FROM dba_stat_extensions
    3 WHERE table_name = 'TDORGEH';
    EXTENSION_NAME EXTENSION
    SYS_STUU82KTNIFD_P94KDKJ9#0$08 ("O2_KOE"||'*')
    SYS_STUH6U9E_VV_9BVM9I3NNRX#8S ("O3_KOE"||'*')
    SYS_STUCUZFT$CCNA7ZD6R08R3T660 ("O4_KOE"||'*')
    SYS_STUCSINP1TWGAB#R_V3$XR72E7 ("O5_KOE"||'*')
    SYS_STUFD58RVB7F0J1IOL2Q#Z$_VB ("O6_KOE"||'*')
    SYS_STU#84ID#J#21ML9$7ZN#HQ7$Q ("O7_KOE"||'*')
    SYS_STUCMDCY97QZOEH7TEIAB43GUX ("O8_KOE"||'*')
    SYS_STUL3EYD$4V756XR5TCCV7KP94 ("O9_KOE"||'*')
    SYS_STUWBXP9BM7ZXAR$JL9C6XVT7B ("O10_KOE"||'*')
    9 Zeilen ausgewõhlt.
    What is the problem?

    Hi,
    While going through the link, it seems that METHOD_OPT => 'FOR COLUMNS SIZE AUTO' is obsolete in Oracle 11g and I will have to use METHOD_OPT => 'FOR ALL COLUMNS SIZE AUTO' instead of that. But the option METHOD_OPT => 'FOR COLUMNS SIZE AUTO' used to take just 5 minutes to complete while METHOD_OPT => 'FOR ALL COLUMNS SIZE AUTO' is taking 1 hour.
    I want it to take time (5-6 minutes) which the original METHOD_OPT => 'FOR COLUMNS SIZE AUTO' was taking.

  • Confusion using dbms_stat package

    Hi,
    I am using oracle 10G. I am quite confusied between analyze comman and dbms_stat package. In 9i we can use the analyze command to generate the execution plan if the optimizer select the CHOOSE base. But in oracle 10G this is obsolete, instead of that we can use the three parameter values viz, ALL_ROWS, FIRST_ROWS and FIRTS_N_ROWS. In oracle documentation it is written that whenever we user the value ALL_ROWS then the oracle server automatically selects the COST based optimizer.
    So My question is that what is the use of using dbms_stat package if the plan is automatically generated by setting the value ALL_ROWS in the parameter OPTIMIZER_MODE.
    Please reply ASAP.
    Thanks
    SS

    > I am quite confusied
    It would seem so. This is the wrong forum for your subject matter. What makes you think that DBMS_STATS have anything to do with object orientated programming, object relational design and advance (user) defined data types in Oracle?
    > Please reply ASAP.
    We are volunteers doing answers for free here.
    Urgent asap answers are supplied by Oracle Support when you file a Service Request with them. So try http://metalink.oracle.com for your asap answer.

  • DBMS_Stats package body is missing on unix install

    I ran dbmsstats.sql again after I got the following error message
    ORA-04068: existing state of packages has been discarded
    ORA-04067: not executed, package body "SYS.DBMS_STATS" does not exist
    ORA-06508: PL/SQL: could not find program unit being called
    ORA-06512: at line 1
    exec SYS.dbms_stats.gather_schema_stats('MYSCHEMA',CASCADE=>TRUE)
    does anyone know where the package body for this resides? Is it perhaps wrapped java that I need to load or something?
    I appreciate whatever help y'all can give me.
    thanks

    As SYS user, run catproc.sql located in $ORACLE_HOME/rdbms/admin .
    it will help create dbms_stats package for you.
    SQL> @catproc.sql
    or you can just run the below scripts (which is a part of catproc.sql)
    SQL> @prvtstas.plb
    SQL> @prvtstat.plb
    Hope it helps,
    Babu Ranagsamy

  • DBMS_STATS package body creation

    How do the procedures in the DBMS_STATS package get created? I ran the dbmsstat.sql procedure, but the gather_schema_stats procedure didn't work, so I read the entire dbmsstat.sql procedure, and all it creates is the package, not the package body. What script do I have to run in order to create the package body?
    I'm running 8i on Solaris 2.6, if that matters.
    Thanks,
    Rich

    When I try to execute dbms_stats.gather_schema_stats, I get:
    ERROR at line 1:
    ORA-04068: existing state of packages has been discarded
    ORA-04067: not executed, package body "SYS.DBMS_STATS" does not exist
    ORA-06508: PL/SQL: could not find program unit being called
    ORA-06512: at line 1
    I just queried dba_source and found the dbms_stats package, but not the package body. If it was there before, maybe I wiped it out by running dbmsstats.sql again (when you create or replace a package, is the package body discarded?).
    Thanks for the tip on prvtstat.plb. I'll try running it and see what happens.
    Rich

  • DBMS_STATS package error message

    Hi,
    I have Oracle DBA II class and when I do my homework assignment, I encountered this error when exec the DBMS_STATS package......(unsupported construct or internal error). What did I do wrong? Can anyone help? Thanks. - katie
    ===============================================
    SQL> exec dbms_advisor.set_default_task_parameter('ADDM','DB_ACTIVITY_MIN',30);
    PL/SQL procedure successfully completed.
    SQL> create table addm(id number, name varchar2(2000));
    Table created.
    SQL> exec DBMS_STATS.GATHER_TABLE_STATS(-ownname=>'ADDM', tabname=>'ADDM',-estimate_percent=>DBMS_ST
    ATS.AUTO_SAMPLE_SIZE);
    BEGIN DBMS_STATS.GATHER_TABLE_STATS(-ownname=>'ADDM', tabname=>'ADDM',-estimate_percent=>DBMS_STATS.
    ERROR at line 1:
    ORA-06550: line 1, column 37:
    PLS-00707: unsupported construct or internal error [2603]
    ORA-06550: line 1, column 7:
    PL/SQL: Statement ignored

    Thank you so much. It works! I removed the dash (-) sign in front of the variable name. Thanks again.
    SQL> exec DBMS_STATS.GATHER_TABLE_STATS(ownname=>'ADDM', tabname=>'ADDM',estimate_percent=>DBMS_STAT
    S.AUTO_SAMPLE_SIZE);
    PL/SQL procedure successfully completed.

  • Error while running: SYS.DBMS_STATS Package.

    when i am trying to execute the DBMS_STATS Package inside a procedure, getting the error.
    ORA-12805: parallel query server died unexpectedly
    ORA-06512: at "SYS.DBMS_STATS", line 9643
    ORA-06512: at "SYS.DBMS_STATS", line 10137
    ORA-06512: at "SYS.DBMS_STATS", line 10324
    ORA-06512: at "SYS.DBMS_STATS", line 10378
    ORA-06512: at "SYS.DBMS_STATS", line 10355
    ORA-06512: at line 2
    Can anyone help me out.I dont know much of the DBA stuff.

    Hi,
    Try setting the following parameters in init.ora:
    dbhandles_cached = 0
    hash_join_enabled=false
    timed_statistics = false
    If the problem still reproduces then try increasing your SORT_AREA_SIZE of your session to a larger value.
    When a ORA-12805 occurs in most cases it is accompanied with a ORA-600 or a ORA-7445. Hence please check your alert.log if such errors are reported there.
    Verify the files of the temporary tablespace of type TEMPORARY are in a full file system ( no free space available).
    Nicolas.

  • When Running DBMS_STATS inside a Proecure it Fails

    Hello.
    I need to schedule a job to compute stats.
    I decide to create a Procedure GATHERTABLESTATSGTS2 and schedule a job as described below :
    CREATE OR REPLACE PROCEDURE GATHERTABLESTATSGTS2
    as
    BEGIN
    FOR i IN
    select distinct owner,table_name from dba_tables
    where owner in ('GTS2','GTS2_BW')
    and table_name not in ('EXTRACT_ALLOCATIONS_TEU','EXTRACT_TARIFFS_IT')
    LOOP
    BEGIN
    dbms_stats.gather_table_stats
    ( ownname => i.owner      
    , tabname => i.table_name
                   , degree => 4
         , cascade => TRUE);
    EXCEPTION
    WHEN OTHERS THEN
    NULL;
    END;
    END LOOP;
    END GATHERTABLESTATSGTS2;
    VARIABLE jobno number;
    BEGIN
    DBMS_JOB.SUBMIT(:jobno,'GATHERTABLESTATSGTS2;',SYSDATE+2/24, 'SYSDATE+240/1440');
    COMMIT;
    END;
    The Procedure COMPILES WITHOUR ERRORS.
    The job is well scheduled.
    But when I run manually the procedure GATHERTABLESTATSGTS2 I get
    14:17:59 dodbw01.ctr.globedev.ddc> exec sys.GATHERTABLESTATSGTS2;
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:00.93 >>>>>>>>>> executed in less the 1 Seconde !!!!!!!!!!!
    14:18:06 dodbw01.ctr.globedev.ddc>
    And when I check in DBA_TAB_COL_STATISTICS
    select * from DBA_TAB_COL_STATISTICS
    where owner in ( 'GTS2','GTS2_BW')
    order by owner,table_name;
    I don't have any stats , I mean statsitics have not been updated.
    Does someone alredy face this issue before?

    Did you not try what I suggested in your Re: DBMS_STATS Gather_Table_Stats Fails when Called inside a Procedure in the SQL and PL/SQL forum?

Maybe you are looking for

  • Best practices for ARM - please help!!!

    Hi all, Can you please help with any pointers / links to documents describing best practices for "who should be creating" the GRC request in below workflow of ARM in GRC 10.0?? Create GRC request -> role approver -> risk manager -> security team opti

  • Disaster Recovery in Windows 2003/Cluster, SQL 2000 and R3

    Hi, Can someone share experience/knowledge of disaster recovery scenarios in MSCS/SQL Server/SAP. One of our customer has R3/SQL Server2000/Win 2003 (Cluster). We would like to evaluate best possible options for the Disaster Recovery which are suppor

  • OAB not updating on Mailbox Server 2010

    I have searched the forums and have not found a solution. Statistics: Two Mailbox servers with Exchange 2010 SP3 RU6. One CAS/HT with Exchange 2010 RU6. OAB last date modified on the generating Mailbox server is August 28 and today is September 8. Se

  • HT1386 itunes does not list ipod touch as a device

    itunes does not list ipid touch as a device

  • Incorrect JFrame icon display with custom theme

    I created a JFrame with custom icon and theme. The problem is the transparent color of icon doesnt not display correctly. Can anyone help?