ORACLE¼Æ»®(schedule)Ïê½â
´´½¨job
jobÊÇʲôÄØ? ¼òµ¥µÄ˵¾ÍÊǼƻ®(schedule)¼ÓÉÏÈÎÎñ˵Ã÷. ÁíÍ⻹ÓÐһЩ±ØÐëµÄ²ÎÊý.
ÕâÀïÌáµ½µÄ"ÈÎÎñ"¿ÉÒÔÊÇÊý¾Ý¿âÄÚ²¿µÄ´æ´¢¹ý³Ì,ÄäÃûµÄPL/SQL¿é,Ò²¿ÉÒÔÊDzÙ×÷ϵͳ¼¶±ðµÄ½Å±¾.
¿ÉÒÔÓÐÁ½ÖÖ·½Ê½À´¶¨Òå"¼Æ»®":
1) ʹÓÃDBMS_SCHDULER.CREATE_SCHEDULE ¶¨ÒåÒ»¸ö¼Æ»®;
2) µ÷ÓÃDBMS_SCHDULER.CREATE_JOBE¹ý³ÌÖ±½ÓÖ¸¶¨ (ÏÂÃæ»áÏêϸ˵Ã÷)
ÔÚ´´½¨Ò»¸ö¼Æ»®Ê±£¬ÄãÖÁÉÙÐèÒªÖ¸¶¨ÏÂÃæµÄÊôÐÔ£¬ËüÃÇÊÇjobÔËÐÐËù±ØÐëµÄ:
¿ªÊ¼Ê±¼ä (start_time);
Öظ´ÆµÂÊ (repeat_interval);
½áÊøʱ¼ä (end_time)
ÁíÍ⣬¶ÔÓÚÒ»¸öjob¶øÑÔ£¬»¹ÓкܶàµÄ¸½¼Ó²ÎÊý:
job_class
job_priority
auto_drop
restartable
max_runs
max_failures
schedule_limit
logging_level
ÏÂÃ棬ÎÒÒÔÎÊ´ðµÄÐÎʽÀ´¾ßÌå½âÊÍ.
Q1:Ôõô´ÓÊý¾Ý¿âÖвéѯjobµÄÊôÐÔ ?
A1: ÓÐÁ½ÖÖ·½·¨:
1) ²éѯ(DBA|ALL|USER)_SCHEDULER_JOBS ÊÓͼ
(Ìáʾ: ¸ù¾ÝÓû§È¨Ï޵IJ»Í¬£¬Ñ¡ÔñÐԵIJéѯ DBA|ALL|USERÊÓͼ)
2) µ÷ÓÃDBMS_SCHEDULER°üÖеÄGET_ATTRIBUTE ¹ý³Ì
Q2: ÔõôÉèÖÃÕâЩÊôÐÔÄØ?
A2: Ò²ÊÇÓÐÁ½ÖÖ·½·¨
1) ÔÚ´´½¨jobʱֱ½ÓÖ¸¶¨
2) µ÷ÓÃDBMS_SCHEDULER°üÖеÄSET_ATTRIBUTE ¹ý³Ì
Q3: "ÎÒÐèҪʲôȨÏÞ²ÅÄÜ´´½¨job" ?
A3: ÄãÖÁÉÙÐèÒªcreate_jobÕâ¸öϵͳȨÏÞ¡£Èç¹ûÓû§ÓµÓÐcreate any jobÕâ¸öȨÏÞ£¬
Ëü¿ÉÒÔ´´½¨ÊôÖ÷ΪÈκÎÓû§(SYSÓû§³ýÍâ)µÄjob.
ȱʡÇé¿öÏÂ,job»á±»´´½¨ÔÚµ±Ç°µÄschemaÏ£¬²¢ÇÒÊÇûÓ줻îµÄ; Èç¹ûҪʹjobÒ»´´½¨
¾Í×Ô¶¯¼¤»î£¬ÐèÒªÏÔʽµÄÉèÖÃenabled ÊôÐÔΪtrue, À´¿´Ò»¸öÀý×Ó:
begin
dbms_scheduler.create_job
(
job_name => 'ARC_MOVE',
schedule_name => 'EVERY_60_MINS',
job_type => 'EXECUTABLE',
job_action => '/home/dbtools/move_arcs.sh',
enabled => true,
comments => 'Move Archived Logs to a Different Directory'
);
end;
/
Q4: Äܲ»ÄÜÏêϸµØ½²ÊöÒ»ÏÂÉÏÃæÕâ¸ö¹ý³ÌÓõ½µÄ¸÷¸ö²ÎÊý?
A4:
job_name: ¹ËÃû˼Òå,ÿ¸öjob¶¼±ØÐëÓÐÒ»¸öµÄÃû³Æ
schedule_name: Èç¹û¶¨ÒåÁ˼ƻ®£¬ÔÚÕâÀïÖ¸¶¨¼Æ»®µÄÃû³Æ
job_type: Ä¿Ç°Ö§³ÖÈýÖÖÀàÐÍ:
PL/SQL¿é: PLSQL_BLOCK,
´æ´¢¹ý³Ì: STORED_PROCEDURE
Íⲿ³ÌÐò: EXECUTABLE (Íⲿ³ÌÐò¿ÉÒÔÊÇÒ»¸öshell½Å±¾,Ò²¿ÉÒÔÊDzÙ×÷ϵͳ¼¶±ðµÄÖ¸Áî).
job_action: ¸ù¾Ýjob_typeµÄ²»Í¬£¬job_actionÓв»Í¬µÄº¬Òå.
Èç¹ûjob_typeÖ¸¶¨µÄÊÇ´æ´¢¹ý³Ì£¬¾ÍÐèÒªÖ¸¶¨´æ´¢¹ý³ÌµÄÃû×Ö;
Èç¹ûjob_typeÖ¸¶¨µÄÊÇPL/SQL¿é£¬¾ÍÐèÒªÊäÈë
Ïà¹ØÎĵµ£º
ÒÔsystemµÇ¼½øÈ¥Ö®ºó£¬Ö´ÐÐÏÂÃæµÄÃüÁ
SQL> alter user scott account unlock; £¨Íê³É½âËøµÄ²Ù×÷£©
Óû§ÒѸü¸Ä¡£
SQL> alter user scott identified by tiger; £¨ÖØиøscottÕâ¸öÓû§É趨ÃÜÂ룩
Óû§ÒѸü¸Ä¡£
SQL> conn scott/tiger
ÒÑÁ¬½Ó¡£ ......
ÆÀ¹ÀÊý¾Ý¸ßËÙ»º´æЧÂʵÄÖ¸±êÊÇÃüÖÐÂÊ¡£¸ÃÃüÖÐÂÊͨ¹ý²éѯV$SYSSTAT ºÍ$BUFFER_POOL_STATISTICSÊÓͼ¿ÉÒԵõ½¡£Õâ¸öÊÓͼ¿ÉÒÔ
²éѯÿ¸ö»º´æ³Ø¸÷×ÔµÄÃüÖÐÂÊ¡£»º´æ³ØµÄÃüÖÐÂʵļÆËã²ÉÓÃÏÂÃæµÄ¹«Ê½:
1-(physical_reads/(db_block_gets+consistent_gets))
ÏÂÃæµÄSQLÓï¾ä³£ÓÃÀ´²éѯµ±Ç°¸÷¸ö»º´æ³ØµÄÃüÖ ......
ÕâƪÂÛ̳ÎÄÕ£¨ÈüµÏÍø¼¼ÊõÉçÇø£©Õë¶ÔDBMS_SCHEDULERµÄʹÓ÷½·¨½øÐÐÁËÏ꾡µÄ½éÉÜ£¬¸ü¶àÄÚÈÝÇë²Î¿¼ÏÂÎÄ£º
DBMS_SCHEDULERÊÇOracle 10GÖÐÐÂÔöµÄÒ»¸ö°ü£¬ÓëÀÏ°æ±¾µÄdbms_job°üÏà±È£¬dbms_schedulerÓкܶàÐÂÌØÐÔ£¬ÎÒ½«Í¨¹ýһϵÁеÄÎÄÕÂÀ´½éÉÜÒ»ÏÂÈçºÎʹÓÃÕâ¸ö°ü.
1. ´´½¨job
job ......
Ëùν³öÓÚjob¶øʤÓÚjob£¬ËµµÄ¾ÍÊÇOracle 10gºóµÄÐÂÌØÐÔSchedulerÀ²¡£ÔÚ10g»·¾³ÖУ¬ORACLE½¨ÒéʹÓÃSchedulerÌæ»»ÆÕͨµÄjob£¬À´¹ÜÀíÈÎÎñµÄÖ´ÐС£Æäʵ£¬½«SchedulerÃèÊö³É¹ÜÀíjobµÄ¹¤¾ßÒѾ̫¹ýƬÃæÁË£¬10G°æ±¾ÖÐÐÂÔöµÄScheduler¾ø²»½ö½öÊÇ´´½¨ÈÎÎñÕâô¼òµ¥¡£¡£¡£¡£
Ìáʾ£ºORACLEÖйÜÀíSchedulerÊÇͨ¹ýDBMS_SCHEDULER°ü£¬±¾ÕÂÒ ......
¶þ¡¢Ê¹ÓÃPrograms
¡¡¡¡ÔÚÂÛ̳ÖÐż¶û¼û¹ýÓÐÈËÌÖÂÛÈçºÎÔÚORACLEÖÐÖ´ÐвÙ×÷ϵͳÃüÁ»òÊÇORACLEÊý¾Ý¿âÍâµÄÓ¦Óá£Ó¦¸Ã˵ÔÚ9i¼°Ö®Ç°µÄ°æ±¾ÖУ¬ËäȻ˵²¢·ÇÍêÈ«ÎÞ·¨ÊµÏÖ£¨Æäʵ»¹ÊÇÓжàÖÖ·½Ê½Äܹ»±äÏàʵÏֵģ©£¬²»¹ý¸´ÔÓµÄʵÏÖ·½Ê½ÈÃDBAʹ¾¢ÁËÁ¦£¬ÉË͸ÁËÐÄ£¬·Ñ¾¢ÁËʶù¡£
¡¡¡¡½øÈë10g°æ±¾Ö®ºó£¬¾ÍÍêÈ«²»±ØÈç´Ë·ÑÉñ£¬ÒòΪÓÐÁËDBMS ......