Solved

Analyzing tables in a schema?

Posted on 2006-12-01
5
1,237 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 250 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Wrong number of values in the INTO list of a FETCH statement 16 89
Oracle - SQL Parse String 5 47
Problem with duplicate records in Oracle query 16 40
Oracle Insert not working 10 32
This article started out as an Experts-Exchange question, which then grew into a quick tip to go along with an IOUG presentation for the Collaborate confernce and then later grew again into a full blown article with expanded functionality and legacy…
Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

820 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