Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Analyzing tables in a schema?

Posted on 2006-12-01
5
Medium Priority
?
1,247 Views
Last Modified: 2013-12-11
I want to analyze some tables in a schema that have not been analyzed in a few days. What is the quickest non time consuming method or command to analyze tables in a schema without consuming alot time waiting on this analyze procedure to finish?
0
Comment
Question by:Omega002
5 Comments
 

Author Comment

by:Omega002
ID: 18053991
FYI Oracle database for this situation is Oracle 9i.
0
 
LVL 28

Expert Comment

by:Naveen Kumar
ID: 18055342
you can analyze all the tables in a schema by using dbms_stats package. Use the procedure/function which is appropriate for you.

But in case there are only 3 tables/indexes ( assuming total objects can be 100 in your schema including your indexes as well ) in the last 2 days which are not analyzed, then doing it manually will be the fast way.

Thanks

0
 
LVL 27

Accepted Solution

by:
sujith80 earned 750 total points
ID: 18068614
"quickest non time consuming method "
I dont think that you can save the time for analyzing a table using any method. Oracle will take the time it needs to analyze the table.

-- You can go for estimating the statistics rather than computing the statistics. Which will take a sample of data and arrive at the statistics. The syntax goes like "analyze table x estimate statistics" (You should be aware of this as you have a periodic routine to analyze tables.) But this statistics wont be as accurate as "analyze table x compute statistics".

-- if your tables are partitioned, analyze only the partition that contains the recent data. like:
analyze table x partition(px) compute statistics
0
 
LVL 18

Expert Comment

by:rbrooker
ID: 18071564
Hi,

sujith80's answer is right, but "analyze table..." is not as recommended as using the dbms_stats package.

you can try :
dbms_stats.gather_schema_stats('SCHEMA_NAME',
    estimate_percent=>10,  -- analyze based on 10% of table
    block_sample=>TRUE,  -- use block sampling, not row sampling
    CASCADE=>TRUE,   -- include indexes
    method_opt=> 'FOR ALL COLUMNS SIZE AUTO',  -- can specify which columns to analyze, do all of them
    options=> 'GATHER EMPTY');  -- empty stats only

dbms_stats.gather_schema_stats('SCHEMA_NAME',
    estimate_percent=>10,
    block_sample=>TRUE,
    CASCADE=>TRUE,
    method_opt=> 'FOR ALL COLUMNS SIZE AUTO',
    options=> 'GATHER STALE');  -- stale stats only

this will gather stats for tables that do not have any, and for tables which have had over 10% of changes since the last time the stats were gathered...

good luck :)
0
 
LVL 7

Expert Comment

by:Stephen Lappin
ID: 18075949
You can write an Oracle job to gather stats (in the background). This example analyses all tables overnight on Sunday.


DECLARE
  X NUMBER;
BEGIN
  SYS.DBMS_JOB.SUBMIT
    ( job       => X
     ,what      => 'DBMS_STATS.GATHER_SCHEMA_STATS (ownname => ''SCHEMA_NAME'', estimate_percent =>100,granularity=>''ALL'',cascade=>TRUE);'
     ,next_date => to_date('10/12/2006 00:00:00','dd/mm/yyyy hh24:mi:ss')
     ,interval  => 'NEXT_DAY(TRUNC(SYSDATE), ''SUNDAY'')'
     ,no_parse  => TRUE
    );
  SYS.DBMS_OUTPUT.PUT_LINE('Job Number is: ' || to_char(x));
END;
/

commit;
0

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
Shell script to create broker configuration file using current broker Configuration, solely for purpose of backup on Linux. Script may need to be modified depending on OS-installation. Please deploy and verify the script in a test environment.
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
Via a live example, show how to take different types of Oracle backups using RMAN.
Suggested Courses

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question