Auto sample gather stats procedure

Hi,
can some one explain the  Oracle's auto sample gather stats procedure and how to run it.

Thanks
taazAsked:
Who is Participating?
 
schwertnerConnect With a Mentor Commented:
I use the following code to compute statistics:

/*
** To run automatically statistics computing on
** middnight today and every week after that also on middnight
** run in SQL*Plus as user SYS the following script
** Write down the number returned by the script.
** It should be used to point the queued job
** for operations like delete, reschedule, etc.
** when using the DBMS_JOB package
*/


CREATE OR REPLACE PROCEDURE compute_statistics IS
BEGIN
   dbms_stats.gather_database_stats(cascade=>true);
END compute_statistics;
/


set serveroutput on
set linesize 10000
variable x number;
begin
   DBMS_OUTPUT.enable(100000);  
   dbms_job.submit(:x,'compute_statistics;',trunc(sysdate),'trunc(sysdate+7)');
   commit;
   dbms_output.put_line(TO_char(:x));
end;
0
 
sdstuberCommented:
it doesn't exist in 9i, you have to invoke dbms_stats yourself.  You can schedule it to run automatically yourself via dbms_job if you want.

it does exist in 10g and you don't have to do anything because it runs automatically via dbms_scheduler.
What the procedure does is count the rows in your tables and indexes, or at least sampling them if they are very large.  It also gathers some statistical information to describe the data in each table such as min and max value, number of nulls, distribution of values into histograms and count of associated index values.  It will also gather some system statistics so the optimizer will know how fast your cpu is, how fast the io, etc.
0
 
Naveen KumarProduction Manager / Application Support ManagerCommented:
in 10g database, you can use the below queries to see what the job calls and when the job runs etc....

select * from dba_scheduler_jobs
where owner ='SYS'
and job_name = 'GATHER_STATS_JOB'

select * from dba_scheduler_programs
where owner ='SYS'
and program_name ='GATHER_STATS_PROG'

select * from dba_scheduler_schedules
where owner ='SYS'

select * from dba_scheduler_window_groups;

also to check the log,  use the below :

select * from dba_scheduler_job_run_details
where owner ='SYS'
and job_name ='GATHER_STATS_JOB'
order by 1 desc

select * from dba_scheduler_job_log
where owner ='SYS'
and job_name ='GATHER_STATS_JOB'
order by 1 desc
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
taazAuthor Commented:
Thanks Sdstuber and  Mav Kum V I really appreciate you.
I will let you know once I run these queries.
0
 
taazAuthor Commented:
Thanks It worked.

Sorry for the late response.
0
 
sdstuberCommented:
hmmm, odd answer to accept.

the first two posts actually answered your question about the 10g automatic gathering of statistics.

the answer you accepted is the exact opposite, it shows how to do it manually.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.