Auto sample gather stats procedure

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

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

END compute_statistics;

set serveroutput on
set linesize 10000
variable x number;
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.
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
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.
taazAuthor Commented:
Thanks It worked.

Sorry for the late response.
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.
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.