Gather statistics or analyze table
What is the difference between gather statistics for table and analyze table?
Regards
Arpit
Analyzing a table is gathering statistics (whether you're using the old ANALYZE statement or the preferred dbms_stats package).
Similar Messages
-
How to reduce time for gather statistics for a table.
I have a table size 520 gb
Its one of the partition size is 38 gb
and total indexes of related table is 412 gb.
Server/instance details.
==========
56 cpu -> Hyper threading enable
280 gb ram
35 gb sga
27 gb buffer cache
4.5 gb shared pool size
25 gb pga
undo size 90gb
temp size 150 gb
Details :
exec dbms_stats.gather_table_stats('OWNER','TAB_NAME',PARTNAME=>'PART_NAME',CASCADE=>FALSE,ESTIMATE_PERCENT=>10,DEGREE=>30,NO_INVALIDATE=>TRUE);
when i am firing this in an ideal time when there is no load that time also is is taking 28 mins to complete.
Can anybody please reply me how can we reduce the stats gather time.
Thanks in advance,
Tapas Karmakar
Oracle DBA.Enable tracing to see where the time is going.
parallel 30 seems optimistic - unless you have a large number of discs to support the I/O ?
you haven't limited histogram collection, and most of the time spent of histograms may be wasted time - what histograms do you really need, and how many does Oracle analyse for and then discard ?
Using a block sample may help slightly
You haven't limited the granularity of the stats collection to the partition - the default is partition plus table, so I think you're also doing a massive sample on the table after completing the partition. Is this what you want to do, or do you have an alternative strategy for generating table-level stats.
Regards
Jonathan Lewis -
exec dbms_stats.gather_schema_stats( -
ownname => 'PROD1, -
options => 'GATHER AUTO', -
estimate_percent => dbms_stats.auto_sample_size, -
method_opt => 'for all columns size repeat', -
degree => 25 -
I have 400 tables in PROD1 schema, but I want to gather statistics for 120 tables only
How to gathere statistics for 120 tables ?
For specifying degree, what is the minimum and maximum? Will this affect any performanceuser8934564 wrote:
exec dbms_stats.gather_schema_stats( -
ownname => 'PROD1, -
options => 'GATHER AUTO', -
estimate_percent => dbms_stats.auto_sample_size, -
method_opt => 'for all columns size repeat', -
degree => 25 -
I have 400 tables in PROD1 schema, but I want to gather statistics for 120 tables only
How to gathere statistics for 120 tables ?
For specifying degree, what is the minimum and maximum? Will this affect any performanceFrom Oracle Docs:
Degree is Degree of parallelism. The default for degree is NULL. The default value can be changed using the SET_PARAM Procedure. NULL means use the table default value specified by the DEGREE clause in the CREATE TABLE or ALTER TABLE statement. Use the constant DBMS_STATS.DEFAULT_DEGREE to specify the default value based on the initialization parameters. The AUTO_DEGREE value determines the degree of parallelism automatically. This is either 1 (serial execution) or DEFAULT_DEGREE (the system default value based on number of CPUs and initialization parameters) according to size of the object.To be able to gather stats for 120 tables:
1) You can create a temporary table, enter the names of these tables, create a PL/SQL procedure, loop for the table names and call GATHER_TABLE_STATS for each table.
2) You can lock other table's stats, and call GATHER_SCHEMA_STATS.
Regards
Gokhan -
Statistics on a table to be collected daily.
Hi,
I have a scenario where a table gets truncated every day at 10 PM before being populated by a billion a two number of records. At 12 AM, the table will be used by warehousing system. How do we gather statistics for this table on a daily basis to see that Oracle accesses this table in the best possible way.
I know that a job something like this...
DECLARE
JOB USER_JOBS.JOB%TYPE;
BEGIN
DBMS_JOB.SUBMIT (JOB, 'BEGIN DBMS_STATS.GATHER_TABLE_STATS ('TABLE_NAME')', to_date ('24/11/2009 23:00', 'dd/mm/yyyy hh24:mi'), sysdate+1);
END;will get the statistics for me,
Is there any other approach??
Thanks,
Aswin.PROCEDURE GATHER_TABLE_STATS
Argument Name Type In/Out Default?
OWNNAME VARCHAR2 IN
TABNAME VARCHAR2 IN
PARTNAME VARCHAR2 IN DEFAULT
ESTIMATE_PERCENT NUMBER IN DEFAULT
BLOCK_SAMPLE BOOLEAN IN DEFAULT
METHOD_OPT VARCHAR2 IN DEFAULT
DEGREE NUMBER IN DEFAULT
GRANULARITY VARCHAR2 IN DEFAULT
CASCADE BOOLEAN IN DEFAULT
STATTAB VARCHAR2 IN DEFAULT
STATID VARCHAR2 IN DEFAULT
STATOWN VARCHAR2 IN DEFAULT
NO_INVALIDATE BOOLEAN IN DEFAULT
STATTYPE VARCHAR2 IN DEFAULT
FORCE BOOLEAN IN DEFAULTYour post contains error.
Provide all mandatory arguments -
About gather statistics - ANALYZE on Oracle views
Oracle® Database Reference
11g Release 1 (11.1)
Part Number B28320-01
ALL_TABLES describes the relational tables accessible to the current user. To gather statistics for this view, use the ANALYZE SQL statement.
Columns marked with an asterisk (*) are populated only if you collect statistics on the table with the ANALYZE statement or the DBMS_STATS package
I thought ANALYZE command shouldn't be used to gather stats, as it explained as well on the ANALYZE command description.
Furthermore, explanations on how the columns should be populated are not clear enough. Maybe my english level is too low, but it seems we have to run any thing on the view itself.
Same for ALL_INDEXES.
Nicolas.Hi Nicolas. You're right that we recommend using DBMS_STATS for most statistics-gathering purposes. I'll pass this along to the writer who manages the Database Reference, to see that it gets updated. I'll also ask him to check the clarity of the column descriptions.
Regards,
Diana -
How to Gather Statistics of Tables and Indexes
Hi all,
Plz help me in Gathering Statistics of Tables and Indexes.
Thanksfor tables
exec dbms_stats.gather_table_stats('SCOTT', 'EMPLOYEES');
for indexes
exec dbms_stats.gather_index_stats('SCOTT', 'EMPLOYEES_PK');
check this link for detail
http://nimishgarg.blogspot.com/2010/04/oracle-dbmsstats-gather-statistics-of.html -
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.
AlexWhat 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 -
How to disable automatic statistics collections on tables
Hi
I am using Oracle 10g and we have few tables which are frequently truncated and news rows added to it. Oracle automatically analyzes the table by some means which collects statistics of the table but at the wrong time(when the table is empty). This makes my query to do a full table scan rather using indexes since the statistics was collected when the table was empty.Could any one please let me know how to disable the automatic statistics collection feature of Oracle?
Cheers
Anantha PVHi
I am using Oracle 10g and we have few tables which
are frequently truncated and news rows added to it.
Oracle automatically analyzes the table by some means
which collects statistics of the table but at the
wrong time(when the table is empty). This makes my
query to do a full table scan rather using indexes
since the statistics was collected when the table was
empty.Could any one please let me know how to disable
the automatic statistics collection feature of
Oracle?
First of all I think it's important that you understand why Oracle collects statistics on these tables: Because it considers the statistics of the object to be missing or stale. So if you just disable the statistics gathering on these tables then you won't have statistics at all or outdated statistics.
So as said by the previous posts you should gather the statistics manually yourself anyway. If you do so right after loading the data into the truncated table, you don't need to disable the automatic statistics gathering as it only processes objects that are stale or don't have statistics at all.
If you still think that you need to disable it there are several ways to accomplish it:
As already mentioned, for particular objects you can lock the statistics using DBMS_STATS.LOCK_TABLE_STATS, or for a complete schema using DBMS_STATS.LOCK_SCHEMA_STATS. Then these statistics won't be touched by the automatic gathering job. You still can gather statistics using the FORCE=>true option of the GATHER__STATS procedures.
If you want to change the automatic gathering job that it only gathers statistics on objects owned by Oracle (data dictionary, AWR etc.), then you can do so by calling DBMS_STATS.SET_PARAM('AUTOSTATS_TARGET', 'ORACLE'). This is the recommended method.
If you disable the schedule job as mentioned in the documentation by calling DBMS_SCHEDULER.DISABLE('GATHER_STATS_JOB') then no statistics at all will be gathered automatically, causing your data dictionary statistics to be become stale over time, which could lead to suboptimal performance of queries on the data dictionary.
All this applies to Oracle 10.2, some of the features mentioned might not be available in Oracle 10.1 (as you haven't mentioned your version of 10g).
Regards,
Randolf
Oracle related stuff blog:
http://oracle-randolf.blogspot.com/
SQLTools++ for Oracle:
http://www.sqltools-plusplus.org:7676/
http://sourceforge.net/projects/sqlt-pp/ -
Dear all,
What are the advantages if we do
analyze table <table name> compute statisticsWhen ever i run this it is computing huge CPU utilization and taking long time........
if we do this as far as i know
1)it will analyze the table and count number of rows in a table properly.......
Is there any advantage for INDEX if we do this operation.
Regards,
VamsiHey,
Actually this command is old. I think it is 9i and below; It is still there for backwards compatibility.
Since you are computing the statitics, oracle is going over all the records to get the stats. You can do estimate statics instead.
OR, even better, you can use the new DBMS_Stats Package:
EXEC DBMS_STATS.GATHER_TABLE_STATS (ownname=>'SCHEMA_NAME', tabname => 'TABLE_NAME', estimate_percent=>dbms_stats.auto_sample_size, degree=>2);
This uses DBMS stats package, to estimate the statistics via a sample size automatically set through oracle.
You can also use a similar command to estimate the stats of the whole schema
EXEC DBMS_STATS.GATHER_SCHEMA_STATS (ownname=> 'SCHEMA_NAME', estimate_percent=>dbms_stats.auto_sample_size, degree=>2);
From previous experience, creating an index is not enough, you have to gather the stats on the related table, so that the execution plan gets optimized.
This command get table stats, histogram, uniqueness.. etc -
Best Practice - Analyze table with very large partitions
We have a table that contains 100 partitions with about 20m rows in each. Right now the analyze is taking about 1 hour per partition. The table is used for reporting and will have a nightly load of the previous days data.
What would be the best way to analyze this table? Besides using a low value for ESTIMATE and using low GRANULARITY.
Thank You.Are you suggesting that the table is so big, its not feasible to analyze anymore?I'm suggesting it's not necessary. I think it's highly unlikely that a nightly load is going to change the stats in any meaningful way, unless you are loading millions of rows. the law of diminishing returns has kicked in.
Remember, the standard advice from Oracle is to gather statistics once and then only bother refreshing those stats when we need to. From Metalink note #44961.1:
"Given the 'best' plan is unlikely to change, frequent gathering statistics has no benefit. It does incur costs though."
What you might find useful is to export the stats from your last run before you do the new run (you should do this anyway). Then after the next stats refresh import both sets of stats into dummy schemas and compare them. If the difference is significant then you ought to keep analysing (especially if yours is a DSS or warehousing database). But if they are broadly the same then maybe it's time to stop.
Cheers, APC -
ORA-04092 trying to analyze table
Hi,
I was trying to analyze some tables issuing:
analyze table owner.table_name compute statistics;
Immediately raises the ora-04092, as far as I seen, read, and googled, this ORA error occurs only when someone try to commit inside a trigger, but clearly this is not the case.
And even in some web applications this error appears.
This error started to occur after session limit exceeded, doesn't sound related to me, but maybe it can be interesting information.
Any suggestions please, I'm comfused.
RegardsHere more information:
SQL> select * from v$version;
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Prod
PL/SQL Release 10.2.0.4.0 - Production
CORE 10.2.0.4.0 Production
TNS for Linux: Version 10.2.0.4.0 - Production
NLSRTL Version 10.2.0.4.0 - Production
SO: RHELAS 5
And according recomendation, I tryed to use DBMS_STAT, with same results:
SQL> conn system/*******@siin
Connected.
SQL> conn mailedu/*******@siin
ERROR:
ORA-04092: cannot COMMIT in a trigger
ERROR:
ORA-24315: illegal attribute type
Warning: You are no longer connected to ORACLE.
SQL> conn mailedu/********@siin
ERROR:
ORA-24315: illegal attribute type
SQL> conn system/********@siin
ERROR:
ORA-24315: illegal attribute type
Once I restart sqlplusw, and I could connect (just the first connect is successfull) I tryed with dbms_stats:
SQL> exec dbms_stats.gather_schema_stats ( -
ownname => 'MAILEDU', -
options => 'GATHER' );BEGIN dbms_stats.gather_schema_stats ( ownname => 'MAILEDU', options => 'GATHER' ); END;
ERROR at line 1:
ORA-04092: cannot COMMIT in a trigger
ORA-06512: at "SYS.DBMS_STATS", line 14002
ORA-06512: at "SYS.DBMS_STATS", line 13974
ORA-06512: at line 1
Looking further inside the forum I found this thread:
stupid ora-04092 error message
In the conversation it is mentioned that according document Link:[7886990|https://metalink.oracle.com/CSP/ui/flash.html#tab=KBHome(page=KBHome&id=()),(page=KBNavigator&id=(bmDocDsrc=Bug&bmDocTitle=AFTER%20OCCURRING%20ORA-18,%20ORACLE%20THROWS%20ORA-4092%20CONTINOUSLY&bmDocID=7886990&viewingMode=1143&from=BOOKMARK&bmDocType=BUG))]
it can occur after ORA-00018 maximum number of sessions exceeded
this one is my scenario,
And...
Bug No: 6977167
Filed 16-APR-2008 Updated 19-AUG-2009
Product Oracle Server - Enterprise Edition Product Version 10.2.0.2
Platform Linux x86-64 Platform Version rel4
Database Version 10.2.0.2 Affects Platforms Generic
Severity Severe Loss of Service Status Development to Q/A
Base Bug N/A Fixed in Product Version 11.2
So I would like to mark this as a known bug, but I don't know how to proeced.
Regards -
Hi,
DB: 10.2.0.4 RAC ASM
OS: AIX 5.3L 64-bit
I want to do analyze tables for all users.Please give me the steps for table and schema level.
Thanks & Regards,
SunandCJ,
dbms_utility.analyze_schema has been deprecated since 9i- you should be using dbms_stats.
Sunand, by default there will be a gather stats job running on your database picking up any 'stale' statistics, have you disabled it?
If you want/need to run it manually, dbms_stats.gather_database_stats is what you need. Documentation is here http://download.oracle.com/docs/cd/B19306_01/server.102/b14211/stats.htm#i41448
Carl -
Hi,
Can any one tell me what are the advantages of schema stats or table stats over analyzing the table.
Regards,
UmairHi,
Following are the advantages of using the DBMS_STATS to gather either table or schema or d/b stats
A. ANALYZE always runs serially. DBMS_STATS can run in serial or parallel.
Whenever possible, DBMS_STATS calls a parallel query to gather statistics with
the specified degree of parallelism; otherwise, it calls a serial query or the
ANALYZE statement. Index statistics are not gathered in parallel.
B. ANALYZE calculates global statistics for partitioned tables and indexes
instead of gathering them directly. This can lead to inaccuracies for some
statistics, such as the number of distinct values.
C. For partitioned tables and indexes, ANALYZE gathers statistics for the
individual partitions and then calculates the global statistics from the
partition statistics. DBMS_STATS can gather separate statistics for each
partition as well as global statistics for the entire table or index. Depending
on the SQL statement being optimized, the optimizer may choose to use either
the partition (or subpartition) statistics or the global statistics.
D. For composite partitioning, ANALYZE gathers statistics for the subpartitions
and then calculates the partition statistics and global statistics from the
subpartition statistics. DBMS_STATS can gather separate statistics for
subpartitions, partitions, and the entire table or index. Depending on the SQL
statement being optimized, the optimizer may choose to use either the partition
(or subpartition) statistics or the global statistics.
E. ANALYZE cannot overwrite or delete some of the values of statistics that were
gathered by DBMS_STATS.
F. ANALYZE can gather additional information that is not used by the optimizer,
such as information about chained rows and the structural integrity of indexes,
tables, and clusters. DBMS_STATS does not gather this information. DBMS_STATS
gathers statistics only for cost-based optimization; it does not gather other
statistics. For example, the table statistics gathered by DBMS_STATS include
the number of rows, number of blocks currently containing data, and average row
length but not the number of chained rows, average free space, or number of
unused data blocks.
G. DBMS_STATS does not call statistics collection methods associated with
individual columns. Use the ANALYZE statement to gather such information. -
Analyze tables using procedure .
Hello Friends,
I my schema , I had to analyze all the tables ( gather statistics ) before I start the loading process to target tables.
I have created a procedure -
create or replace procedure proc_analyze_tables as
table_count number :=0;
sqlstatement varchar2(4000);
begin
for i in ( select TNAME from TAB where TABTYPE='TABLE' AND TNAME ='ABC') loop
sqlstatement := 'ANALYZE TABLE ' || i.TNAME || 'ESTIMATE STATISTICS ';
EXECUTE IMMEDIATE sqlstatement ;
dbms_output.put_line ( 'table name is ' || i.TNAME );
end loop;
end proc_analyze_tables;
is it appropiate to use the folllowing statment.
exec dbms_stats.gather_schema_stats(ownname=>'myschema_name', options=>'GATHER AUTO');
When I execute the procedure , I am getting invalid analyze command .
How I can use the procedure or is their any command that can be executed by execute immediate statement !!
thanks/kumarkumar73 wrote:
Hello Friends,
I my schema , I had to analyze all the tables ( gather statistics ) before I start the loading process to target tables.
I have created a procedure -
create or replace procedure proc_analyze_tables as
table_count number :=0;
sqlstatement varchar2(4000);
begin
for i in ( select TNAME from TAB where TABTYPE='TABLE' AND TNAME ='ABC') loop
sqlstatement := 'ANALYZE TABLE ' || i.TNAME || 'ESTIMATE STATISTICS ';
EXECUTE IMMEDIATE sqlstatement ;
dbms_output.put_line ( 'table name is ' || i.TNAME );
end loop;
end proc_analyze_tables;
When I execute the procedure , I am getting invalid analyze command .
How I can use the procedure or is their any command that can be executed by execute immediate statement !!
thanks/kumarANALYZE TABLE is obsoleted & deprecated.
use DBMS_STATS instead
The standard advice when (ab)using EXECUTE IMMEDIATE is to compose the SQL statement in a single VARCHAR2 variable
Then print the variable before passing it to EXECUTE IMMEDIATE.
COPY the statement & PASTE into sqlplus to validate its correctness. -
Gather statistic or analyze???
How can I know if an index or a table has been analyzed with gather statistic o analyze method???? And How can I know if it was calculated with compute or estimate statistics????
Thanks!analyze is deprecated in 10g. you cannot figure out if analyze has been used. You cannot know if the compute keyword has been used, because oracle may decide to compute statistics even if you say estimate (for small tables for example)
but watch user_tables
SQL> select TABLE_NAME, num_rows, SAMPLE_SIZE, LAST_ANALYZED from user_tables where table_name like 'T_1';
TABLE NUM_ROWS SAMPLE_SIZE LAST_ANALYZED
T41
T31 36018 1 18.05.2005 12:00:17
T21 38333 38333 18.05.2005 12:00:27
Maybe you are looking for
-
Unable to View Data in OOTB OBIEE11g Dashboards/Reports
Hi, We have installed OBIEE 11.1.1.6.0. BIAPPS, Informatica and DAC for the implementation of Oracle Business Intelligence Application 7.9.6.3 in Windows 2008 Server. Also completed the basic configuration of Oracle BI Repository Connections, Informa
-
Final cut pro quit unexpectedly while using the CUDA plug-in?
Hello, FCP 7 quits on Quicktime conversion export every single time. Just to give some information as to how this issue started, we recently had to send our Mac early 2009 OSX 10.8.5 to get repaired because of permissions issues with the star
-
Hello I activated inspection type 01 (good receipt for purchase order). that is When we are doing a stock transfer using 101 movement inspection lot is created. the problem is : I asked that only third (1/3) of the movements will generate inspection
-
Hi Experts, I had a few issues and i wanted to look at the xml that went back and forth. However, it appears that yesterdayu2019s some successfulXMLs have been deleted from the system. Is there any way we can get them back, and can it be changed so t
-
Try to open multipul photos in Camera raw
When I try to open multipul raw photos from cs6 mini bridge, after selecting them, none open up. If I do one it works fine. I also tried the review mode and only one opens...