Académique Documents
Professionnel Documents
Culture Documents
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:
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 /
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.
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 /
STATUS
------------------------------
FAILED
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.
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.
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.
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> begin
2 dbms_scheduler.drop_job('dev.MYJOB2');
3 end;
4 /
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.