Gather Statistics
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 performance
user8934564 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
Similar Messages
-
Hi folks!
I gathered statistcs in one schema with folowing options:
exec dbms_stats.gather_schema_stats(user,method_opt=>'FOR ALL COLUMNS SIZE 1',estimate_percent=>null,gather_temp=>false,cascade=>true,degree=>dbms_stats.auto_degree);Then:
exec dbms_stats.gather_schema_stats(user,method_opt=>'FOR ALL COLUMNS SIZE SKEWONLY',estimate_percent=>null,gather_temp=>false,cascade=>true,degree=>dbms_stats.auto_degree);Now, I turn on table monitoring and suggest to gather statistics (per day) with that parameters:
dbms_stats.gather_schema_stats(ownname =>user, options=>'GATHER STALE', gather_temp => false, cascade => true, estimate_percent => 100, degree => dbms_stats.auto_degree);Default method_opt is FOR ALL COLUMNS SIZE AUTO.
Now I got better perfomance. How often I need to gather statstics?
Thanks in advance.
Best regards, Pavel.Thanks, I also think so.
Little test-case:
SQL>exec dbms_stats.gather_table_stats(user,'TABLE1',estimate_percent=>null);
Elapsed: 00:00:01.03
SQL> select column_name,num_distinct,sample_size from user_tab_col_statistics where table_name='TABLE1;
COLUMN_NAME NUM_DISTINCT SAMPLE_SIZE
DISGRP 7944 33204
DISMBR 18948 33204
TYPE 4 33204
Elapsed: 00:00:00.03
SQL> exec dbms_stats.gather_table_stats(user,'TABLE1',estimate_percent=>10);
PL/SQL procedure successfully completed.
Elapsed: 00:00:01.78
SQL> select column_name,num_distinct,sample_size from user_tab_col_statistics where table_name='TABLE1';
COLUMN_NAME NUM_DISTINCT SAMPLE_SIZE
DISGRP 3836 3269
DISMBR 13686 3269
TYPE 4 3269
Elapsed: 00:00:00.00
SQL> exec dbms_stats.gather_table_stats(user,'TABLE1',estimate_percent=>100);
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.52
SQL> select column_name,num_distinct,sample_size from user_tab_col_statistics where table_name='TABLE1';
COLUMN_NAME NUM_DISTINCT SAMPLE_SIZE
DISGRP 7944 33204
DISMBR 18948 33204
TYPE 4 33204
Elapsed: 00:00:00.01
SQL> exec dbms_stats.gather_table_stats(user,'TABLE1',estimate_percent=>dbms_stats.auto_sample_size);
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.53
SQL> select column_name,num_distinct,sample_size from user_tab_col_statistics where table_name='TABLE1';
COLUMN_NAME NUM_DISTINCT SAMPLE_SIZE
DISGRP 8448 5568
DISMBR 18948 33204
TYPE 4 5568
Elapsed: 00:00:00.00
SQL> select count(distinct disgrp) from TABLE1;
COUNT(DISTINCTDISGRP)
7944
Elapsed: 00:00:00.02
SQL> select count(distinct dismbr) from TABLE1;
COUNT(DISTINCTDISMBR)
18948
Elapsed: 00:00:00.03
SQL> select count(distinct type) from TABLE1;
COUNT(DISTINCTTYPE)
4
Elapsed: 00:00:00.01
SQL> select column_name,num_distinct,sample_size from user_tab_col_statistics where table_name='TABLE2';
COLUMN_NAME NUM_DISTINCT SAMPLE_SIZE
ID 219120 219120
UNIT 114762 219120
LOC 61 219120
TIS 1230 219120
RTYP 3 219120
Elapsed: 00:00:00.02
SQL> exec dbms_stats.gather_table_stats(user,'TABLE2',estimate_percent=>null);
PL/SQL procedure successfully completed.
Elapsed: 00:00:07.61
SQL> select column_name,num_distinct,sample_size from user_tab_col_statistics where table_name='TABLE2';
COLUMN_NAME NUM_DISTINCT SAMPLE_SIZE
ID 219120 219120
UNIT 114762 219120
LOC 61 219120
TIS 1230 219120
RTYP 3 219120
Elapsed: 00:00:00.00
SQL> exec dbms_stats.gather_table_stats(user,'TABLE2',estimate_percent=>10);
PL/SQL procedure successfully completed.
Elapsed: 00:00:02.90
SQL> select column_name,num_distinct,sample_size from user_tab_col_statistics where table_name='TABLE2';
COLUMN_NAME NUM_DISTINCT SAMPLE_SIZE
ID 219950 21995
UNIT 70812 21995
LOC 43 21995
TIS 496 21995
RTYP 3 21995
Elapsed: 00:00:00.00
SQL> exec dbms_stats.gather_table_stats(user,'TABLE2',estimate_percent=>50);
PL/SQL procedure successfully completed.
Elapsed: 00:00:03.70
SQL> select column_name,num_distinct,sample_size from user_tab_col_statistics where table_name='TABLE2';
COLUMN_NAME NUM_DISTINCT SAMPLE_SIZE
ID 218716 109358
UNIT 92338 109426
LOC 61 109455
TIS 994 109567
RTYP 3 109422
Elapsed: 00:00:00.00
SQL> exec dbms_stats.gather_table_stats(user,'COMPS',estimate_percent=>100);
PL/SQL procedure successfully completed.
Elapsed: 00:00:04.37
SQL> select column_name,num_distinct,sample_size from user_tab_col_statistics where table_name='TABLE2';
COLUMN_NAME NUM_DISTINCT SAMPLE_SIZE
ID 219120 219120
UNIT 114762 219120
LOC 61 219120
TIS 1230 219120
RTYP 3 219120
Elapsed: 00:00:00.00
SQL> exec dbms_stats.gather_table_stats(user,'COMPS',estimate_percent=>dbms_stats.auto_sample_size);
PL/SQL procedure successfully completed.
Elapsed: 00:00:03.81
SQL> select column_name,num_distinct,sample_size from user_tab_col_statistics where table_name='TABLE2';
COLUMN_NAME NUM_DISTINCT SAMPLE_SIZE
ID 217968 54492
UNIT 122237 54492
LOC 31 5495
TIS 240 5495
RTYP 3 5495
Elapsed: 00:00:00.01
SQL> select count(distinct id) from TABLE2;
COUNT(DISTINCTID)
219120
Elapsed: 00:00:00.27
SQL> select count(distinct unit) from TABLE2;
COUNT(DISTINCTUNIT)
114762
Elapsed: 00:00:00.30
SQL> select count(distinct loc) from TABLE2;
COUNT(DISTINCTLOC)
61
Elapsed: 00:00:00.06
SQL> select count(distinct tis) from TABLE2;
COUNT(DISTINCTTIS)
1230
Elapsed: 00:00:00.09In that situation, auto_sample_size not bad? But estimate_percent=>100 - exact.
Best regards, Pavel. -
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 -
Exclude Schema from Gather Statistics Job
I am using 11.1.0,7. I would like to know if we can exclude some schemas While Oracle automatically gathers the statistics.
Reason I want this is that, I have one database that supports multiple applications but as per one application's demand we should not be gathering stats on it's schema. So, in totality I have 20 Schemas but while this jobs run, I want to exclude 2 schemas that this application supports.
Locking the Stats for these schemas is not an option.
Thanks!Have you enquired from the vendor exactly why they do not want you to gather statistics on it's schema?
Is there other options they are willing to consider like baselining the explain plan or perhaps not publishing the statistics to the tables...using the pending statistics feature?
Exec dbms_stats.set_table_prefs('SH', 'CUSTOMERS', 'PUBLISH', 'false');
Regards
Tim Boles
Edited by: Tim Boles on Aug 4, 2010 11:11 AM -
Hi,
I launched a job to gather statistics on just one schema on my DATABASE in OEM. How can I identify it's session ? Many thanks before.You can try below query:
select s.username, s.sid,s.serial#, sql.sql_Text
from v$session s, v$sqlarea sql
where s.sql_address = sql.address and s.sql_hash_value = sql.hash_value and
s.username = '&username' and lower(sql.sql_text) like '%dbms_stats%'
Best Regards
Krystian Zieja / mob -
Autom. Gather Statistics Job
Hello,
i am facing following problem with the automatic gather statistics job which is running every night.
The jobs starts when the weeknight/weekend_maintenance_windows opens, runs approx. 30 minutes and rebuilds statistics for around 270 objects. But when we check the status of objects next morning or immediate after jobrun, we still find hundrets of objects with stale statistics. We are not facing any heavy performance problems, but i want to know why we found stale statistics. The job uses 30 minutes of the 480 minutes window, so in my opinion there is plenty of time for all objects to create new statistics.
Is this normal behaviour?
Can't find anything in metalink.
Systeminfo:
Host: HP-UX 11.31
DB: 10.2.0.4
Regards
UlliUlli,
uwaldt wrote:
Hello Randolf,
we check if column stale_stats contains a 'YES'. The column 'last_analyzed' is filled with a date.OK, and the date corresponds to the latest run of the automatic statistics gathering job or is it outdated? What is the content of the corresponding TABMODIFICATIONS view in that case?
After we check sthe SQL-script with the 'original' check via dbms_stats.gather_schema_stats, we see that there is a difference between all_tab/ind_statistics and the real value in tabmodifications.Apologies, but I'm not able to follow: What is the "difference between all_tab/ind_statistics and the real value in *_tab_modifications"? You mean to say that the list of objects marked as "STALE_STATS = YES" column differs from the output of the "LIST STALE" call?
But what shows grid-control if we check there for stale stats?Good question, I can't answer since I seldom use the GUI tools.
The next is, the developers in house argue with the all_tab/ind_statistics and blame the DBA's to do their housekeeping, especially if the users complain bad performance. I knew that the gather_job do his work, but we can't show it probable to the developers.This all sounds a bit odd. Two comments:
1. It is possible in 10g to lock the statistics of tables, so that the automatic statistics collection job doesn't touch them. It's quite unlikely since you have to invoke it manually/explicitly using DBMS_STATS.LOCK_TABLE/SCHEMA_STATS, but may be you want to check the column STATTYPE_LOCKED in the TABSTATISTICS views for those objects in question, just to make sure.
2. All the monitoring related information (*TABMODIFICATIONS/STALE_STATS column etc.) is usually only updated every three hours or if a call to DBMS_STATS.GATHER_STATS is performed. If you want to manually invoke the flush of the monitoring info, you can call DBMSSTATS.FLUSH_DATABASE_MONITORING_INFO to make sure that you look at the latest monitoring information available.
Above point might explain that you can spot differences/inconsistencies before/after calling DBMS_STATS.GATHER_SCHEMA_STATS to list the stale objects.
Regards,
Randolf
Oracle related stuff blog:
http://oracle-randolf.blogspot.com/
SQLTools++ for Oracle (Open source Oracle GUI for Windows):
http://www.sqltools-plusplus.org:7676/
http://sourceforge.net/projects/sqlt-pp/ -
Gather Statistics taking very long time
Hi,
In one of our critical Databases gather statistics is taking a very long time.
How do I go about debugging this bad performance?
Regards,
NarayanStart with
- What is the exact command used to gather statistics (and what are all the global settings that are used for any arguments you're not providing)?
- What does "very long time" mean in numbers? Are we talking about 20 minutes? 4 hours? 4 days?
- How much data are we talking about? What fraction of the tables and indexes are you gathering statistics on?
- Have you done anything to look at, say, v$session_longops (or trace the session or watch the SQL being exectued, etc) to see what the job is doing?
Justin -
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 I gather statistics via OEM db control?
Hi,
According to the documentation,
I may setup a job to automatically
gather statistics for all the segments in my database
via EM database control.
I cant find any documentation on how to do this.
I did find a link in EM which will allow me
to gather statistics ad hoc but I want it automated.
Thanks,
-moiThere should be a stats gathering program scheduled
by default. Check under Database > Administration >
Scheduler > Jobs in Database Control. The job is called
SYS.GATHER_STATS_JOB. You will need to login as SYS to
see the job. The job runs the
DBMS_STATS.GATHER_DATABASE_STATS_JOB_PROC procedure.
You can, of course, schedule any other
DBMS_STATS.GATHER_* procedures if you prefer.
Hope this helps.
Kailash. -
Gather statistics or analyze table
What is the difference between gather statistics for table and analyze table?
Regards
ArpitAnalyzing a table is gathering statistics (whether you're using the old ANALYZE statement or the preferred dbms_stats package).
-
Gather statistics im OWB repozitory
Hi all
Is possibility to look for in some OWB repozitory tables which target tables have enabled gather statistics? I mean , I wont to run some sql to db (owb tables)
OWB 10.1Hi all
Is possibility to look for in some OWB repozitory tables which target tables have enabled gather statistics? I mean , I wont to run some sql to db (owb tables)
OWB 10.1 -
Gather statistics about classloader
I can gather statistics like
1.No of classes loaded.
2.Memory used by the JVM.
3.Threads created about the JVM (default ClassLoader of the JVM).
I need to do the same for any generic ClassLoader.
The code I use to gather information for the JVM's ClassLoader is as follows:
import java.io.IOException;
import java.lang.management.ClassLoadingMXBean;
import java.lang.management.ManagementFactory;
import java.lang.management.OperatingSystemMXBean;
import java.net.MalformedURLException;
import javax.management.MBeanServer;
import javax.management.MBeanServerConnection;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXConnectorServer;
import javax.management.remote.JMXConnectorServerFactory;
import javax.management.remote.JMXServiceURL;
public class ClassLoading {
public static void main(String args[]) throws MalformedURLException, IOException
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
JMXServiceURL url = new JMXServiceURL("rmi", null, 0);
JMXConnectorServer cs = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
cs.start();
JMXServiceURL url1 = cs.getAddress();
JMXConnector jmxc = JMXConnectorFactory.connect(url1, null);
MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
final ClassLoadingMXBean clmb = ManagementFactory.newPlatformMXBeanProxy(mbsc, ManagementFactory.CLASS_LOADING_MXBEAN_NAME, ClassLoadingMXBean.class);
System.out.println("Loaded class count"+clmb.getLoadedClassCount());
final OperatingSystemMXBean osmxb = ManagementFactory.newPlatformMXBeanProxy(mbsc, ManagementFactory.OPERATING_SYSTEM_MXBEAN_NAME, OperatingSystemMXBean.class);
System.out.println("Name"+osmxb.getName());
}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 -
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
SatishThe 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". -
Gather statistics on table slow down after partitioning + 10.2.0.4
Hi All,
Oracle 10.2.0.4
OS: Sun solaris
We have a table with 36 indexes on that and the number of columns on the table is 60. total number of rows on the table is 19 million.
The issue now is we used to collect statistics after a bulk load (insert) on the table,it will take maximum 3hrs for completing the statistics collection.
Recently we partitioned (range partition) the table based on the year column like below,
PARTITION BY RANGE (year)
(PARTITION A_2006 VALUES LESS THAN ('2007'),
PARTITION A_2007 VALUES LESS THAN ('2008'),
PARTITION A_2008 VALUES LESS THAN ('2009'),
PARTITION A_2009 VALUES LESS THAN ('2010'),
PARTITION A_MAX VALUES LESS THAN (MAXVALUE)
All the indexes are local indexes now.
Now if we collect the statistics it takes more than 6hrs to complete. Please find the gather stats code below
exec dbms_stats.gather_table_stats( 'SCHEMANAME','TABLENAME',method_opt=> 'for all indexed columns', cascade => true );
Please advice on solving the issue....
TIA,ORCLDB wrote:
Hi All,
Any help...I won't be able to give you any valid suggestion as I have not come across many such cases.
If you don't mind, here are a few pointers
1) You may want to check (from a different session) to identify what is the stats collection routine spending time on
2) You may want to collect stats on each partition separately (and the collect global stats) to see if any particular partition is the culprit
3) You may want to collect stats on table and on its indexes separately (i.e. not use cascade=>true) to see which one is taking time. -
Gather Statistics recommendations
Hi
How to find the recommendations from gather schema statistics job?
Thanks998932 wrote:
Sometimes when a Gather Schema stats job is scheduled(parameters:APPLSYS, 30, , NOBACKUP, , LASTRUN, GATHER, , Y), it will get executed in 25 minutes and sometimes 60 minutes.
a) What could be the possible reasons?This is normal and it depends to how busy your system is.
b) How can I reduce the execution time?How big is your database and how long it takes to gather stats for all schemes?
What if you change 30 to 10, does it make a difference?
c) What If I increase the estimate percent and give the Degree values?
PROD CPU's are 12, cores are 6 and RAM is 72 GBYou need to try it yourself and see how long it takes. Increasing the estimate percent will take longer but with different degree value this might make it different. You should tweak your parameters to find the best values and your concern should be about your system performance after running gather schematic stats instead of how long the program takes to run.
Thanks,
Hussein
Maybe you are looking for
-
HT4847 can't open preferences because iCloud window won't close
hi , im new to macs , very new , and im trying to open my preferences but when i do , i get a window with icloud , that wont close , it just shows the orange light , no green , no red , just orange . and when i do press the orange option it just puts
-
Firefox PDF links - Trying to Open in Pages
Hi all, I have a bit of a hiccup in that every time I attempt to click on a PDF link in Firefox 3.6.3 to open the file in Preview, the system attempts to open it with pages and I receive the following error message: The document "PhotoVideo_Solicitat
-
Photos tweaked but what size do I save them?
I have been using PE7 for a few weeks now and am very pleased but realising that I can't keep on saving pictures at full size every time. So what should I do when re-sizing to keep at a sensible file size but retaining a lot of the goodness. Is is t
-
Accessing a JSP file via context URL
Hi experts , i have a requirement to access a jsp file via context url i.e. /irj/... abc.jsp , can any one please suggest how to access this , i have a jsp dynpage component in the pagelet folder i have a jsp page, that im not able to access via the
-
SRM5 Help on Inbox (Approval)
Hi Approval Inbox both new and old style. Approver cannot change shopping carts, role has W/F security set to not defined. Approver can add approvers or reviewers. Approver adds a reviewer, saves. Screen shows various data columns, but the entries to