After we have verified that STATSPACK is installed and working, we can
schedule automatic data collection. By using the statsauto.sql script
we can automatically schedule an hourly data collection for STATSPACK.
The statsauto.sql script contains the following directive:
SQL> execute dbms_job.submit(:jobno, 'statspack.snap;',
trunc(sysdate+1/24,'HH'), 'trunc(SYSDATE+1/24,''HH'')', TRUE, :instno);
The important thing to note in this call to dbms_job.submit is the
execution interval. The SYSDATE+1/24 is the interval that is stored in
the dba_jobs view to produce hourly snapshots. You can change this as
follows for different sample times. There are 1,440 minutes in a day,
and you can use this figure to adjust the execution times.
SQL> execute dbms_job.submit(:jobno, 'statspack.snap;',
trunc(sysdate+1/144,'MI'), 'trunc(SYSDATE+1/144,''MI'')', TRUE, :instno);
In the real world, you may have times where you want to sample the
database over short time intervals. For example, if you have noticed
that a performance problem happens every day between 4:00 P.M. and
5:00 P.M., you can request more frequent snapshots during this period.
For normal use, you probably want to accept the hourly default and
execute a snapshot every hour. Below is the standard output from
running the statsauto.sql script:
SQL> connect perfstat/perfstat;
Connected.
SQL> @statsauto
PL/SQL procedure successfully completed.
Job number for automated statistics collection for this instance
Note that this job number is needed when modifying or removing
the job:
JOBNO
----------
1
Job queue process
Below is the current setting of the job_queue_processes init.ora
parameter - the value for this parameter must be greater
than 0 to use automatic statistics gathering:
NAME TYPE VALUE
------------------------------------ -------
-----------------------------
job_queue_processes integer 1
Next scheduled run
~~~~~~~~~~~~~~~~~~
The next scheduled run for this job is:
JOB NEXT_DATE NEXT_SEC
---------- --------- --------
1 12-MAY-02 16:00:00
We can now see that a STATSPACK snapshot will automatically be
executed every hour. We see that this is scheduled as job number 1,
and we can use this job number to cancel this collection at any time
using the dbms_job.remove procedure: