Vous êtes sur la page 1sur 4

How I used DBMS Scheduler to collect system statistics

for an Oracle 10g Database 10g Release 2

Introduction:

There was a need to collect system statistics on an Oracle 10g Database Release 2
(10.2.0.2.0). The job was to suppose collect system statistics after intervals of time.
Although the operating system was AIX but I decided to use DBMS Scheduler. The job
was in a PLSQL Block and it would execute the dbms_stats.gather_system_stats
procedure.

Audience:

Database Administrators

Environment:

Oracle Database: Oracle 10g Database Release 10.2.0.2.0


Operating System: AIX 5.3

Solution:

First I created a job named myjob1; it was created in DEV schema. It would execute after
the interval of 10 minutes and would gather system level statistics. I also did not mention
enabled argument. This argument has two values TRUE (enabled job) or FALSE
(disabled job) after the job is created. FALSE is the default. Lastly I did not mention the
start_time and end_time therefore the job would immediately executed after it was
created. But ‘myjob1’ job would not execute after it was created since it would be
disabled.

SQL> begin
2 dbms_scheduler.create_job (
3 job_name => 'dev.myjob1',
4 job_type => 'PLSQL_BLOCK',
5 job_action => 'BEGIN DBMS_STATS.GATHER_SYSTEM_STATS(interval=>10);
END;',
6 comments => 'Gather System Level Statistics');
7 end;
8 /

PL/SQL procedure successfully completed.

After the job had been created I viewed DBA_SCHEDULER_JOBS table to see that the
myjob1 has been enlisted among other default database jobs.

SQL> SELECT JOB_NAME FROM DBA_SCHEDULER_JOBS ;

JOB_NAME
------------------------------
AUTO_SPACE_ADVISOR_JOB
GATHER_STATS_JOB
FGR$AUTOPURGE_JOB
PURGE_LOG
RLM$SCHDNEGACTION
RLM$EVTCLEANUP
MYJOB1

7 rows selected.

Since the job had been disabled, I had to enable the job which was done as follows;

SQL> begin
2 dbms_scheduler.enable('dev.MYJOB1');
3 end;
4 /

Now I viewed DBA_SCHEDULER_JOB_RUN_DETAILS table to see whether the job


had been successfully executed.

SQL> select status from dba_SCHEDULER_JOB_RUN_DETAILS


2 where job_name='MYJOB1';

STATUS
------------------------------
FAILED

After querying the STATUS column of DBA_SCHEDULER_JOB_RUN_DETAILS


table I got to know that the job had failed, then I queried ADDITIONAL_INFO column
of the same table which contains additional information that basically included ORA
errors.

SQL> select ADDITIONAL_INFO


2 from dba_SCHEDULER_JOB_RUN_DETAILS
3 where job_name='MYJOB1';

ADDITIONAL_INFO
------------------------------------------------------------------------
--------
ORA-20000: ORA-20000: Unable to gather system statistics: insufficient
privileges
ORA-06512: at "SYS.DBMS_STATS", line 15822
ORA-06512: at line 1

The job ‘myjob1’ could not be executed from DEV schema because of insufficient
privileges.

SQL> SELECT JOB_NAME FROM DBA_SCHEDULER_JOBS ;

JOB_NAME
------------------------------
AUTO_SPACE_ADVISOR_JOB
GATHER_STATS_JOB
FGR$AUTOPURGE_JOB
PURGE_LOG
RLM$SCHDNEGACTION
RLM$EVTCLEANUP

The job ‘myjob1’ was dropped automatically although it was not successful. We have
identified the reason above.
I again created another job myjob2 . This time the job would be executed daily and it
would be enabled after it had been created. Although start_time and end_time were not
been specified which means it will executed as soon as it is created.

SQL> begin
2 dbms_scheduler.create_job (
3 job_name => 'dev.myjob2',
4 job_type => 'PLSQL_BLOCK',
5 job_action => 'BEGIN DBMS_STATS.GATHER_SYSTEM_STATS(interval=>10);
END;',
6 repeat_interval => 'FREQ=DAILY',
7 enabled => TRUE,
8 comments => 'Gather System Level Statistics');
9 end;
10 /

Again I queried DBA_SCHEDULER_JOBS to find the job ‘myjob2’ that been created.

SQL> SELECT JOB_NAME FROM DBA_SCHEDULER_JOBS ;

JOB_NAME
------------------------------
MYJOB2
AUTO_SPACE_ADVISOR_JOB
GATHER_STATS_JOB
FGR$AUTOPURGE_JOB
PURGE_LOG
RLM$SCHDNEGACTION
RLM$EVTCLEANUP

Now again I looked at the status, the job had started and it had no errors.

SQL> select status, ACTUAL_START_DATE


2 , additional_info
3 from dba_SCHEDULER_JOB_RUN_DETAILS
4 where job_name = 'MYJOB2';

STATUS
------------------------------
ACTUAL_START_DATE
------------------------------------------------------------------------
---
ADDITIONAL_INFO
------------------------------------------------------------------------
--------
SUCCEEDED
11-JAN-08 10.33.03.901012 AM +05:00

I came to know that ‘myjob2’ had successfully executed. The column additional_info of
dba_SCHEDULER_JOB_RUN_DETAILS was empty and there were no errors.

Once the testing was complete after a few days I disabled the job since I did not wanted
to execute the job any more and it was done as follows;

SQL> begin
2 dbms_scheduler.disable('dev.myjob2');
3 end;
4 /
PL/SQL procedure successfully completed.

I also verified with the help of DBA_SCHEDULER_JOBS table to see that job myjob2
had been disabled.

SQL> select job_name, enabled, state from DBA_SCHEDULER_JOBS


2 where job_name = 'MYJOB2';

JOB_NAME ENABL STATE


------------------------------ ----- ---------------
MYJOB2 FALSE DISABLED

Finally I removed the job completely as follows;

SQL> begin
2 dbms_scheduler.drop_job('dev.MYJOB2');
3 end;
4 /

PL/SQL procedure successfully completed.

Reference:

http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_sched.htm#CIHD
JEEB
http://download.oracle.com/docs/cd/B19306_01/server.102/b14231/scheduse.htm#i10215
22
http://download.oracle.com/docs/cd/B19306_01/server.102/b14237/statviews_2048.htm#
i1587156
http://download.oracle.com/docs/cd/B19306_01/server.102/b14237/statviews_2048.htm#
i1587156
http://download.oracle.com/docs/cd/B19306_01/server.102/b14237/statviews_2049.htm#
i1587306
http://download.oracle.com/docs/cd/B19306_01/server.102/b14237/statviews_4085.htm#
REFRN23348
http://download.oracle.com/docs/cd/B19306_01/server.102/b14231/schedadmin.htm#sthr
ef3770
http://download.oracle.com/docs/cd/B19306_01/server.102/b14231/schedadmin.htm#sthr
ef3822

DISCLAIMER:
The information in this article is the opinion of the author, not of Oracle Corporation. Any content,
materials, information or software downloaded or otherwise obtained through the use of the site is done at
your own discretion and risk. Oracle shall have no responsibility for any damage to your computer system
or loss of data that results from the download of any content, materials, information or software.

Vous aimerez peut-être aussi