P. 1
Collect Stats DBMS job

Collect Stats DBMS job

|Views: 124|Likes:
Published by pat985946

More info:

Published by: pat985946 on Dec 29, 2010
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

08/27/2012

pdf

text

original

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

SQL> SELECT JOB_NAME FROM DBA_SCHEDULER_JOBS . then I queried ADDITIONAL_INFO column of the same table which contains additional information that basically included ORA errors.FGR$AUTOPURGE_JOB PURGE_LOG RLM$SCHDNEGACTION RLM$EVTCLEANUP MYJOB1 7 rows selected. ADDITIONAL_INFO ------------------------------------------------------------------------------ORA-20000: ORA-20000: Unable to gather system statistics: insufficient privileges ORA-06512: at "SYS. line 15822 ORA-06512: at line 1 The job ‘myjob1’ could not be executed from DEV schema because of insufficient privileges. Since the job had been disabled.enable('dev. STATUS -----------------------------FAILED After querying the STATUS column of DBA_SCHEDULER_JOB_RUN_DETAILS table I got to know that the job had failed. end.MYJOB1'). 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. I had to enable the job which was done as follows.DBMS_STATS". SQL> select status from dba_SCHEDULER_JOB_RUN_DETAILS 2 where job_name='MYJOB1'. We have identified the reason above. SQL> select ADDITIONAL_INFO 2 from dba_SCHEDULER_JOB_RUN_DETAILS 3 where job_name='MYJOB1'. SQL> 2 3 4 begin dbms_scheduler. / Now I viewed DBA_SCHEDULER_JOB_RUN_DETAILS table to see whether the job had been successfully executed. .

SQL> SELECT JOB_NAME FROM DBA_SCHEDULER_JOBS .'. 5 job_action => 'BEGIN DBMS_STATS.I again created another job myjob2 . SQL> 2 3 4 select status. 9 end. 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. END. 6 repeat_interval => 'FREQ=DAILY'.myjob2'.create_job ( 3 job_name => 'dev.33. 4 job_type => 'PLSQL_BLOCK'.disable('dev. 10 / Again I queried DBA_SCHEDULER_JOBS to find the job ‘myjob2’ that been created. 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.GATHER_SYSTEM_STATS(interval=>10). additional_info from dba_SCHEDULER_JOB_RUN_DETAILS where job_name = 'MYJOB2'. the job had started and it had no errors. / . ACTUAL_START_DATE . STATUS -----------------------------ACTUAL_START_DATE -------------------------------------------------------------------------ADDITIONAL_INFO ------------------------------------------------------------------------------SUCCEEDED 11-JAN-08 10. This time the job would be executed daily and it would be enabled after it had been created. 8 comments => 'Gather System Level Statistics'). SQL> begin 2 dbms_scheduler. SQL> 2 3 4 begin dbms_scheduler.03.901012 AM +05:00 I came to know that ‘myjob2’ had successfully executed. end. 7 enabled => TRUE. Although start_time and end_time were not been specified which means it will executed as soon as it is created.myjob2'). The column additional_info of dba_SCHEDULER_JOB_RUN_DETAILS was empty and there were no errors.

MYJOB2').drop_job('dev.102/b14231/scheduse.oracle.102/b14258/d_sched.oracle.102/b14237/statviews_2048. SQL> select job_name.oracle.com/docs/cd/B19306_01/server.htm#sthr ef3770 http://download.102/b14237/statviews_4085. SQL> 2 3 4 begin dbms_scheduler.com/docs/cd/B19306_01/server.102/b14237/statviews_2049. not of Oracle Corporation.htm# REFRN23348 http://download.htm# i1587156 http://download.102/b14237/statviews_2048. .com/docs/cd/B19306_01/server.htm#i10215 22 http://download. Reference: http://download.com/docs/cd/B19306_01/appdev. materials. enabled. materials.com/docs/cd/B19306_01/server.PL/SQL procedure successfully completed.htm# i1587306 http://download.oracle.--------------MYJOB2 FALSE DISABLED Finally I removed the job completely as follows. JOB_NAME ENABL STATE -----------------------------.htm#sthr ef3822 DISCLAIMER: The information in this article is the opinion of the author. Oracle shall have no responsibility for any damage to your computer system or loss of data that results from the download of any content. state from DBA_SCHEDULER_JOBS 2 where job_name = 'MYJOB2'. I also verified with the help of DBA_SCHEDULER_JOBS table to see that job myjob2 had been disabled.com/docs/cd/B19306_01/server. Any content.htm# i1587156 http://download. end.102/b14231/schedadmin. information or software. / PL/SQL procedure successfully completed.oracle.com/docs/cd/B19306_01/server.com/docs/cd/B19306_01/server.oracle. information or software downloaded or otherwise obtained through the use of the site is done at your own discretion and risk.oracle.htm#CIHD JEEB http://download.----.102/b14231/schedadmin.oracle.

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->