oracle database 11g managing resources and task automation

Upload: yelena-bytenskaya

Post on 02-Jun-2018

225 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/10/2019 Oracle Database 11g Managing Resources and Task Automation

    1/68

    | Print | Contents | Close |

    Resource Plans and Groups

    Learning objective

    After completing this topic, you should be able to identify the steps for accessing andcreating resource plans and consumer groups using the Database Resource Manager.

    1. Using the Database Resource Manager

    Disclaimer

    Although certain aspects of the Oracle 11g Database are case and spacing insensitive, acommon coding convention has been used throughout all aspects of this course.

    This convention uses lowercase characters for schema, role, user, and constraint names,and for permissions, synonyms, and table names (with the e ception of the D!A" table#."owercase characters are also used for column names and user$defined procedure,function, and variable names shown in code.

    !ppercase characters are used for Oracle %eywords and functions, for view, table,schema, and column names shown in te t, for column aliases that are not shown in&uotes, for pac%ages, and for data dictionary views.

    The spacing convention re&uires one space after a comma and one space before and

    after operators that are not Oracle$specific, such as ', $, , and ). There should be nospace between an Oracle$specific %eyword or operator and an opening brac%et, betweena closing brac%et and a comma, between the last part of a statement and the closingsemicolon, or before a statement.

    *tring literals in single &uotes are an e ception to all of the convention rules providedhere. +lease use this convention for all interactive parts of this course.

    End o Disclaimer

    y using the Database -esource anager / also called the -esource anager / you

    have more control over the allocation of machine resources than is normally possiblethrough operating system resource management alone.

    0f resource management decisions are made by the operating system, it can lead toproblems such as

    e cessive overhead resulting from operating system conte t switching of Oracle database serverprocesses when the number of server processes is high

    http://%20window.print%28%29/http://%20window.print%28%29/http://library.skillport.com/courseware/cbtlib/257108/257110/eng/thin/transcript.html#contentshttp://%20parent.window.close%28%29/http://%20parent.window.close%28%29/http://library.skillport.com/courseware/cbtlib/257108/257110/eng/thin/transcript.html#contentshttp://%20parent.window.close%28%29/http://%20window.print%28%29/
  • 8/10/2019 Oracle Database 11g Managing Resources and Task Automation

    2/68

    suspension of a database server process that is holding a latch

    une&ual distribution of resources among all Oracle database processes, and an inability toprioriti e one tas% over another

    inability to manage database$specific resources, such as parallel e ecution servers and activesessions

    The Database -esource anager controls the distribution of resources among varioussessions by controlling the e ecution schedule inside the database. y controlling whichsessions run and for how long, the Database -esource anager can ensure thatresource distribution matches the plan directive and, therefore, the business ob2ectives.

    3ith the Database -esource anager, you can guarantee groups of users a minimumamount of processing resources regardless of the load on the system and the number ofusers.

    Administering systems by using the Database -esource anager involves the use of

    resource consumer groups resource plans

    resource plan directives resource allocation methods

    resource consumer groups

    A resource consumer group defines a set of users or sessions that have similarre&uirements for using system and database resources.

    resource plans

    A resource plan specifies how the resources are distributed among various resourceconsumer groups. The Database -esource anager also allows for creation of planswithin plans, called subplans.

    resource plan directives

    -esource plan directives specify how a particular resource is shared among consumergroups or subplans. 4ou associate resource consumer groups and subplans with aparticular resource plan through plan directives.

    resource allocation methods

    -esource allocation methods determine what policy to use when allocating for anyparticular resource. -esource allocation methods are used by resource plans and resourceconsumer groups.

    The Database -esource anager provides several means of allocating resources5

    6+! ethod Degree of +arallelism "imit

  • 8/10/2019 Oracle Database 11g Managing Resources and Task Automation

    3/68

    Active *ession +ool with 7ueuing

    !ndo +ool 8 ecution Time "imit

    0dle Time "imit

    6onsumer 9roup *witchingCPU Method

    6+! ethod enables you to specify how 6+! resources are allocated among consumergroups and subplans.

    Degree o Parallelism Limit

    Degree of +arallelism "imit enables you to control the ma imum degree of parallelism forany operation within a consumer group.

    !ctive "ession Pool #ith $ueuing

    Active *ession +ool with 7ueuing enables you to limit the number of concurrent activesessions for a consumer group or subplan. 0f a group e ceeds the ma imum allowednumber of sessions, new sessions are placed in a &ueue where they wait for an activesession to complete. 4ou can also specify a time limit on how long a session will waitbefore e iting with an error.

    Undo Pool

    !ndo +ool enables you to control the total amount of undo that can be generated by aconsumer group or subplan.

    E%ecution &ime Limit

    8 ecution Time "imit enables you to specify a ma imum e ecution time allowed for an

    operation.

    'dle &ime Limit

    0dle Time "imit enables you to specify an amount of time for which a session can be idle,after which it will be terminated / MAX_IDLE_TIME . 4ou can further restrict the -esource

    anager to terminate only those sessions that are bloc%ing other sessions /MAX_IDLE_TIME_BLOCKER .

    Consumer Group "#itching

    3ith 6onsumer 9roup *witching, the initial consumer group is the group that a sessionwould be in had it 2ust logged in. The top call is defined as treating an entire +" *7" bloc%

    as one call or, similarly, treating *7" statements that are issued separately by the client asseparate calls.

    3henever the total undo space e ceeds the amount specified by UNDO_POOL, no furtherINSERT , UPDATE, or DELETE commands are allowed until undo space is freed byanother session in the same group or the undo pool is increased for the consumer group.

    0f the consumer group:s &uota is e ceeded during the e ecution of a data manipulation

  • 8/10/2019 Oracle Database 11g Managing Resources and Task Automation

    4/68

    language (D "# statement, the operation aborts and returns an error. 7ueries are stillallowed, even if a consumer group has e ceeded its undo threshold.

    0f you use 8 ecution Time "imit, the Oracle database uses cost$based optimi er statisticsto estimate how long an operation will ta%e. 0f it is longer than the ma imum time allowed

    /MAX_EST_EXEC_TIME

    / the operation returns an error and is not started.

    0f a resource consumer group has more than one plan directive withMAX_EST_EXEC_TIME specified, the -esource anager chooses the most restrictive ofall incoming values.

    The functionality of 6onsumer 9roup *witching is mostly beneficial for three$tierapplications where the middle$tier server implements session pooling. 0n this case, themiddle tier tends to do one call for an end user and then use the same session for a callfor a different end user. Therefore, the boundaries of wor% are really calls, and the actionsof a prior end user should not affect the ne t end user.

    4ou can create a plan directive, so that the -esource anager automatically switches theuser bac% to the initial consumer group at the end of the top call.

    (ote

    You cannot specify both the SWITCH_TIME_IN_CALL and SWITCH_TIME parameters within the same directive. The SWITCH_TIME parameter is primarilyintended for client/server applications, while the SWITCH_TIME_IN_CALL

    parameter is for three tier applications.

    8nterprise anager Database 6ontrol provides an easy$to$use graphical interface forconfiguring resource plans, consumer groups, and so on.

    To access 8nterprise anager Database 6ontrol, you clic% the "erver tab in 8nterpriseanager. Then you select the item you want to wor% with.

    The DBMS_RESOURCE_MANAGER +" *7" pac%age comprises many procedures,including

    CREATE_PLAN , which names a resource plan and specifies its allocation methods UPDATE_PLAN, which updates a resource plan:s comment DELETE_PLAN , which deletes a resource plan and its directives

    The automated maintenance tas%s rely on the -esource anager being enabled duringthe maintenance windows. 3hen a maintenance window opens, theDEFAULT_MAINTENANCE_PLAN resource manager plan is automatically set to controlthe amount of 6+! used by automated maintenance tas%s.

  • 8/10/2019 Oracle Database 11g Managing Resources and Task Automation

    5/68

    To be able to give different priorities to each possible tas% during a maintenance window,various consumer groups are assigned to DEFAULT_MAINTENANCE_PLAN.

    ;or high priority tas%s, the

    Optimi er *tatistics 9athering automatic tas% is assigned to the ORA$AUTOTASK_STATS_GROUP consumer group

    *egment Advisor automatic tas% is assigned to the ORA$AUTOTASK_SPACE_GROUP consumergroup

    Automatic *7" Tuning automatic tas% is assigned to the ORA$AUTOTASK_SQL_GROUP consumergroup

    (ote

    If need be, you can manually change the percentage of CPU resources allocatedto the various automated maintenance tas consumer groups insideORA$AUTOTASK_HIGH_SUB_PLAN .

    The DEFAULT_PLAN resource plan is one of the default plans provided. 0t containsdirectives for four consumer groups5

    SYS_GROUP OTHER_GROUPS ORA$AUTOTASK_SUB_PLAN ORA$DIAGNOSTICS

    SYS_GROUP The SYS_GROUP group is the initial consumer group for the SYS and SYSTEM users.

    OTHER_GROUPS

    The OTHER_GROUPS group is used for all sessions that belong to consumer groups thatare not part of the active resource plan. There must be a plan directive for OTHER_GROUPSin any active plan.

    ORA$AUTOTASK_SUB_PLAN

    The ORA$AUTOTASK_SUB_PLAN group has a lower priority than SYS_GROUP andOTHER_GROUPS in this plan.

    ORA$DIAGNOSTICS

    The ORA$DIAGNOSTICS group has the same priority as the ORA$AUTOTASK_SUB_PLAN.The low priority of the ORA$ groups prevents any automated maintenance wor% fromconsuming e cessive amounts of system resources.

    The initial consumer group of a user is the consumer group to which any session createdby that user initially belongs. 0f you have not set the initial consumer group for a user, the

  • 8/10/2019 Oracle Database 11g Managing Resources and Task Automation

    6/68

    user:s initial consumer group will automatically be DEFAULT_CONSUMER_GROUP.

    The DEFAULT_PLAN and associated resource consumer groups can be used or not. 0tcan be a template for new resource plans, it can be modified, or it can be deleted. 4oucan use it as appropriate for your environment.

    To create a new resource plan, you need to configure several -esource anager ob2ects.

    4ou first clic% the "erver tab in 8nterprise anager. Then you clic% Plans .

  • 8/10/2019 Oracle Database 11g Managing Resources and Task Automation

    7/68

  • 8/10/2019 Oracle Database 11g Managing Resources and Task Automation

    8/68

  • 8/10/2019 Oracle Database 11g Managing Resources and Task Automation

    9/68

    3hat should you do to correctly allocate these resources=

    Options5

    1. Assign all users to the SYS_GROUP

    >. Assign only a few users to each consumer group at one time?. 6reate a resource plan

    @. 6reate only the necessary consumer groups

    !ns#er

    4ou should create a resource plan to correctly allocate resources to consumergroups.

    !ption " is incorrect. The SYS_GROUP is the initial consumer group for the SYS and SYSTEM users. 0ot all users should be assigned to this group.

    !ption % is incorrect. ll users should be assigned to a resource consumer group.The user1s default consumer group is the one to which any session created by that user initially belongs. If it is not set for a user, the user1s initial consumer groupdefaults to DEFAULT_CONSUMER_GROUP.

    !ption & is correct. resource plan contains directives that specify how resourcesare allocated to consumer groups. 2or each consumer group, a directive specifiesthe amount of CPU resources allocated.

    !ption * is incorrect. Consumer groups are user sessions that are grouped

    together based on resource processing re uirements. Creating consumer groupsalone will not allocate resources to them.

    "ummar+

    4ou can use the -esource anager to manage mi ed wor%load and to control systemperformance. Administering systems using the Database -esource anager involvesresource consumer groups, resource plans, resource plan directives, and resourceallocation methods. 4ou can manage 6+! usage, degree of parallelism, number of activesessions, undo generation, operation e ecution time, and idle time. 8nterprise anager

    Database 6ontrol provides an interface for configuring resource plans and consumergroups.

    To manage a resource consumer group, you access the consumer groups section in8nterprise anager. 4ou can create consumer groups or assign users to consumergroups using this section.

    &able o Contents

  • 8/10/2019 Oracle Database 11g Managing Resources and Task Automation

    10/68

    | &op o page |

    | Learning objective |

    | 1. Using the Database Resource Manager |

    | *. Creating consumer groups |

    | "ummar+ |

    6opyright B >CC *%ill*oft. All rights reserved.*%ill*oft and the *%ill*oft logo are trademar%s or registered trademar%s

    of *%ill*oft in the !nited *tates and certain other countries. All other logos or trademar%s are the property of their respective owners.

    | Print | Contents | Close |

    Resource Plan Directives

    Learning objective

    After completing this topic, you should be able to identify the steps for planning andmonitoring resource allocation to consumer groups, using resource plan directives.

    1. Using resource plans

    0f you do not use 8nterprise anager to create the resource plan or resource consumergroups, you must first create a pending area . This is a scratch area that enables you tostage your changes and to validate them before they are made active.

    0n 8nterprise anager, there are several property pages, which you can use forspecifying plan directives5

    9eneral

    +arallelism *ession +ool

    !ndo +ool Threshold

    0dle Time

    General

    On the 9eneral tabbed page, you can associate consumer groups with plans and specifyhow much 6+! each consumer group or subplan gets with the MGMT_MTH value.

    Parallelism

    http://library.skillport.com/courseware/cbtlib/257108/257110/eng/thin/transcript.html#pagetophttp://library.skillport.com/courseware/cbtlib/257108/257110/eng/thin/transcript.html#pagetophttp://library.skillport.com/courseware/cbtlib/257108/257110/eng/thin/transcript.html#objectivehttp://library.skillport.com/courseware/cbtlib/257108/257110/eng/thin/transcript.html#section_1http://library.skillport.com/courseware/cbtlib/257108/257110/eng/thin/transcript.html#section_2http://library.skillport.com/courseware/cbtlib/257108/257110/eng/thin/transcript.html#summaryhttp://%20window.print%28%29/http://%20window.print%28%29/http://library.skillport.com/courseware/cbtlib/257108/257111/eng/thin/transcript.html#contentshttp://%20parent.window.close%28%29/http://%20parent.window.close%28%29/http://library.skillport.com/courseware/cbtlib/257108/257110/eng/thin/transcript.html#pagetophttp://library.skillport.com/courseware/cbtlib/257108/257110/eng/thin/transcript.html#objectivehttp://library.skillport.com/courseware/cbtlib/257108/257110/eng/thin/transcript.html#section_1http://library.skillport.com/courseware/cbtlib/257108/257110/eng/thin/transcript.html#section_2http://library.skillport.com/courseware/cbtlib/257108/257110/eng/thin/transcript.html#summaryhttp://%20window.print%28%29/http://library.skillport.com/courseware/cbtlib/257108/257111/eng/thin/transcript.html#contentshttp://%20parent.window.close%28%29/
  • 8/10/2019 Oracle Database 11g Managing Resources and Task Automation

    11/68

    On the +arallelism tabbed page, you can specify a parallel degree limit to control thema imum degree of parallelism for any operation within a consumer group.

    "ession Pool

    On the *ession +ool tabbed page, you can control the ma imum number of concurrently

    active sessions allowed within a consumer group. An entire parallel e ecution session iscounted as one active session.

    Undo Pool

    On the !ndo +ool tabbed page, you can control the amount of total undo that can begenerated by a consumer group.

    &hreshold

    On the Threshold tabbed page, you can specify threshold values, such as e ecution timelimit in seconds, 0 O limit in , and 0 O re&uest limit in number of re&uests.

    'dle &ime

    On the 0dle Time tabbed page, you can specify an amount of time that a session can beidle, after which it will be terminated. 4ou can further restrict such termination to onlysessions that are bloc%ing other sessions.

    -esource allocation methods determine how the -esource anager allocates a particular resource to a resource consumer group or resource plan.

    4ou specify values for various resource allocation methods when creating the resourceplan5

    MGMT_MTH PARALLEL_DEGREE_LIMIT_MTH ACTI-E_SESS_POOL_MTH QUEUING_MTH

    MGMT_MTH

    There are two ways of specifying the 6+! distribution with the MGMT_MTH parameter.

    EMPHASIS is the default method for single$level plans, and is used for multilevel plans thatuse percentages to specify how 6+! is distributed among consumer groups. And RATIO isfor single$level plans that use ratios to specify how 6+! is distributed.

    PARALLEL_DEGREE_LIMIT_MTH

    The PARALLEL_DEGREE_LIMIT_MTH parameter limits the ma imum degree ofparallelism of any operation. This parameter can be specified only for resource consumergroups, not subplans.

    The PARALLEL_DEGREE_LIMIT_ABSOLUTE method is the only possible value, specifyinghow many processes may be assigned to an operation. 0f there are multiple plan directives

  • 8/10/2019 Oracle Database 11g Managing Resources and Task Automation

    12/68

    referring to the same subplan or consumer group, the minimum of all the possible values isused as the parallel degree limit for that subplan or consumer group.

    ACTIVE_SESS_POOL_MTH

    The ACTI-E_SESS_POOL_MTH parameter limits the number of active sessions. All other

    sessions are inactive and wait in a &ueue to be activated. The only value / or the onlyavailable method / for this parameter is ACTI-E_SESS_POOL_ABSOLUTE , which is itsdefault value.

    QUEUING_MTH

    The QUEUING_MTH parameter controls the order in which &ueued inactive sessionse ecute. FIFO_TIMEOUT is the default and only method available.

    The 6+! allocation method EMPHASIS determines how much emphasis is given tosessions in different consumer groups in a resource plan. 6+! usage is assigned levelsfrom 1 through E, with "evel 1 having the highest priority. +ercentages specify how toallocate 6+! to each consumer group at each level.

    *everal rules apply for the EMPHASIS resource allocation method. 6+! resources aredistributed at a given level on the basis of the specified percentages. The percentage of6+! specified for a resource consumer group is a ma imum for how much that consumer group can use at a given level.

    6onsumer resources that are not used at a given level are made available to consumergroups at the ne t level. ;or e ample, if the consumer groups at "evel 1 use only CF ofthe available resources, the additional @CF is made available to consumer groups at"evel >.

    3hen using the EMPHASIS resource allocation method, the sum of percentages at anygiven level must be less than or e&ual to 1CC.

    Any levels that have no plan directives e plicitly specified / the default null value / have adefault of CF for all subplans or consumer groups.

    The EMPHASIS resource allocation method avoids starvation problems, whereconsumers with lower priorities are not given the opportunity to run.

    The RATIO policy is a single$level 6+! allocation method. 0nstead of percentages, youspecify numbers corresponding to the ratio of 6+! you want to give to the consumergroup.

    ;or e ample, given three consumer groups OLTP_USERS , DSS_USERS , andBATCH_USERS , you can specify the ratios OLTP_USERS1 2 , DSS_USERS1 3 ,BATCH_USERS1 4 , and OTHER1 5 .

    This is similar to saying that O"T+ users should get @CF of the resources, D** users

  • 8/10/2019 Oracle Database 11g Managing Resources and Task Automation

    13/68

    should get ?CF of the resources, AT6G users should get >CF of the resources, and allother consumer groups should get 1CF of the available resources.

    0f there are no consumers in the OTHER or DSS_USERS consumer groups currently using6+! resources, then the OLTP_USERS consumer group would get two$thirds of the

    available resources and the BATCH_USERS consumer group would get the other third.

    (ote

    3hen using RATIO you must use integer values, but there is no limit on the sumof values. The default value is null.

    $uestion

    3hat happens when you set the MGMT_MTH resource allocation method toRATIO =

    Options5

    1. The default value is NULL

    >. The sum of percentages at any given level must be less than or e&ual to 1CC

    ?. The value specifies the ma imum percentage of 6+! resources a consumer groupcan use

    @. 4ou can specify values for only one level

    !ns#er

    3hen setting the MGMT_MTH resource allocation method to RATIO , the defaultvalue is NULL and you can specify values for only one level.

    !ption " is correct. If you do not specify a value, NULL is given as the defaultvalue.

    !ption % is incorrect. You must use integer values, but there is no limit on the sumof values.

    !ption & is incorrect. The value specifies a number that indicates the ratio of CPUresources to be allocated to the consumer group.

    !ption * is correct. The RATIO policy is a single4level CPU allocation method.Instead of percentages, you specify numbers corresponding to the ratio of CPUyou want to give to the consumer group.

    $uestion

  • 8/10/2019 Oracle Database 11g Managing Resources and Task Automation

    14/68

    3hat happens when you set the MGMT_MTH resource allocation method toEMPHASIS =

    Options5

    1. The default value is NULL >. The value specifies the ma imum percentage of 6+! resources a consumer group

    can use

    ?. 4ou can specify values for only one level

    @. 4ou must use integer values, but there is no limit on the sum of values

    !ns#er

    3hen setting the MGMT_MTH resource allocation method to EMPHASIS , the defaultvalue is NULL and the value specifies the ma imum percentage of 6+! resourcesa consumer group can use.

    !ption " is correct. If you do not specify a value, NULL is given as the defaultvalue.

    !ption % is correct. CPU resources are distributed at a given level on the basis ofthe specified percentages. The percentage of CPU specified for a resourceconsumer group is a ma-imum for how much that consumer group can use at agiven level.

    !ption & is incorrect. The CPU allocation method EMPHASIS determines howmuch emphasis is given to sessions in different consumer groups in a resource

    plan. CPU usage is assigned levels from " through 5, with level " having thehighest priority.

    !ption * is incorrect. The sum of percentages at any given level must be less thanor e ual to "66. ny levels that have no plan directives e-plicitly specified have adefault of 67 for all subplans or consumer groups.

    *. "etting the !ctive "ession Pool

    !sing the Active *ession +ool feature, you can control the ma imum number of

    concurrently active sessions per resource consumer group. 3ith this functionality, adatabase administrator (D A# can indirectly control the amount of resources that anyresource consumer group uses because resource consumption is proportional to thenumber of active sessions.

    !sing an active session pool can help to reduce the number of servers ta%ing resourcesin the system, thus avoiding inefficient paging, swapping, and other resource depletion(such as memory# resulting from attempting to run too many 2obs simultaneously.

  • 8/10/2019 Oracle Database 11g Managing Resources and Task Automation

    15/68

    After the Active *ession +ool is filled with active sessions, the -esource anager &ueuesall subse&uent sessions attempting to become active until other active sessions completeor become inactive. An active session is one currently involved in a transaction, &uery, orparallel operation. 0ndividual parallel slaves are not counted as sessions / the entireparallel operation counts as one active session.

    There is only one &ueue per resource consumer group and the &ueuing method is first in,first out (;0;O# with a timeout. The &ueue is implemented as a memory structure andcannot be &ueried directly.

    4ou can easily configure the Active *ession +ool settings for a resource plan by using8nterprise anager. ;or e ample, you can limit the a imum

  • 8/10/2019 Oracle Database 11g Managing Resources and Task Automation

    16/68

    not start and the O-A$CI@ error is issued. This eliminates any e ceptionally large 2obsthat would use too many system resources.

    0f a resource consumer group has more than one plan directive referring to it, it may havemore than one MAX_EST_EXEC_TIME . The Database -esource anager then chooses

    the most restrictive of all incoming values.

    The estimated e ecution time for a given statement is calculated using the statistics fromthe cost$based optimi er. The default value for the MAX_EST_EXEC_TIME parameter isUNLIMITED .

    4ou use the resource plan:s 0dle Time tab to set the ma imum idle timeouts for a resourceplan.

    a 0dle Time (sec# and a 0dle Time if loc%ing Another *ession (sec# are therespective e&uivalents of the NEW_MAX_IDLE_TIME and

    NEW_MAX_IDLE_BLOCKER_TIME resource directives in theDBMS_RESOURCE_MANAGER.UPDATE_PLAN_DIRECTI-E procedure. They are bothspecified in seconds.

    NEW_MAX_IDLE_TIME specifies the time that a session is neither e ecuting nor waitingfor 0 O. 3hen the session e ceeds the specified limit, the PMON process forcibly %ills thesession and cleans up its state.

    0n addition to limiting the ma imum idle time for a session, you can also limit the amountof time that an idle session can bloc% another session. 4ou impose this limit by setting theNEW_MAX_IDLE_BLOCKER_TIME resource directive to the number of seconds to allow a

    session to be idle while bloc%ing another session.

    4ou can also specify a value of UNLIMITED to indicate that no ma imum time has beenset. The default is NULL, which means unlimited. These settings give you a more granular control than profiles, whose single value cannot distinguish between bloc%ing andnonbloc%ing sessions.

    ;or e ample, suppose the PMON process %ills sessions that are idle for longer than CCseconds. The PMON process also %ills sessions that are idle for more than ?CC secondsand are bloc%ing other sessions.

    PMON chec%s these limits once every minute and if it finds a session that has e ceededone of the limits, it forcibly %ills the session and cleans up all its resources.

    4ou can configure the Database -esource anager to automatically assign consumergroups to sessions by providing mappings between session attributes and consumergroups. ;urther, you can prioriti e the mappings so as to indicate which mapping hasprecedence in case of conflicts.

  • 8/10/2019 Oracle Database 11g Managing Resources and Task Automation

    17/68

  • 8/10/2019 Oracle Database 11g Managing Resources and Task Automation

    18/68

    $uestion

    3hich parameter is used to control how the -esource anager allocates 6+!usage to a resource plan=

    Options5

    1. ACTI-E_SESS_POOL_MTH

    >. MGMT_MTH

    ?. PARALLEL_DEGREE_LIMIT_MTH

    @. QUEUING_MTH

    !ns#er

    The MGMT_MTH parameter is used to control how the -esource anager allocates6+! usage to a resource plan.

    !ption " is incorrect. The ACTI-E_SESS_POOL_MTH parameter limits the numberof active sessions, mar ing all other sessions as inactive and placing them in a

    ueue waiting to be activated.

    !ption % is correct. The MGMT_MTH parameter is used to control how the#esource $anager allocates CPU usage. This parameter has two possibleresource allocation methods that can be supplied as values 9 EMPHASIS andRATIO .

    !ption & is incorrect. The PARALLEL_DEGREE_LIMIT_MTH parameter limits thema-imum degree of parallelism of any operation. It is not used to control how the#esource $anager allocates CPU usage.

    !ption * is incorrect. The QUEUING_MTH parameter controls the order in whichueued inactive sessions e-ecute. It is not used to control how the #esource

    $anager allocates CPU usage.

    ,. !ctivating a resource plan

    4ou can use the -esource +lans page of 8nterprise anager to manage resource plans.To activate a plan, you select the plan you want to ma%e active, select !ctivate from the

    Actions drop$down list, and then clic% Go .

    The plan you selected is then made the current top plan for the instance.

    The plan for an instance is defined using the RESOURCE_MANAGER_PLAN databaseinitiali ation parameter. This parameter specifies the top plan to be used for this instance.0f no plan is specified, the -esource anager is not activated for the instance.

  • 8/10/2019 Oracle Database 11g Managing Resources and Task Automation

    19/68

    4ou can activate, deactivate, or change the current top plan by using an ALTER SYSTEM statement. 3hen a resource plan is changed using this command, the change ta%eseffect instantly.

    0f the RESOURCE_MANAGER_PLAN parameter is set in a parameter file, and the planspecified is not defined in the database, then the database cannot be opened with thatparameter file. 0nstead, an error is returned.

    (ote

    This error is as follows:

    !# 46;* %: specified resource manager plan does not e-ist in the data dictionary

    0f this error is encountered, the parameter must be modified to show a correct value

    before the instance can be restarted.

    *everal data dictionary views are available to chec% the resource plans, consumergroups, and plan directives that are declared in the instance.

    4ou can use this *7" &uery to obtain information about resource plans defined in thedatabase.

    SQL" SELECT *8 ' 'u _*8 '_60 e%/09es s/ /us '6 /& 4 FROM 67 _ s %_*8 's,PLAN NUM_PLAN_DIRECTI-ES STATUS MAN

    DEFAULT_PLAN 3 ACTI-E NOINTERNAL_QUIESCE 4 ACTI-E YESINTERNAL_PLAN 5 ACTI-E YESBUGDB_PLAN 2 ACTI-E NOMAILDB_PLAN 3 ACTI-E NOMYDB_PLAN 3 ACTI-E NO

    A status of ACTI-E indicates that the plan has been submitted and can be used, whereasa status of PENDING shows that the plan has been created, but is still in the pendingarea.

    0f the '6 /& column is assigned a value of YES, then the plan cannot be deleted.

    SQL" SELECT *8 ' 'u _*8 '_60 e%/09es s/ /us '6 /& 4 FROM 67 _ s %_*8 's,PLAN NUM_PLAN_DIRECTI-ES STATUS MAN

    DEFAULT_PLAN 3 ACTI-E NO

  • 8/10/2019 Oracle Database 11g Managing Resources and Task Automation

    20/68

    INTERNAL_QUIESCE 4 ACTI-E YESINTERNAL_PLAN 5 ACTI-E YESBUGDB_PLAN 2 ACTI-E NOMAILDB_PLAN 3 ACTI-E NOMYDB_PLAN 3 ACTI-E NO

    -. Monitoring the Resource Manager

    4ou can monitor the functioning of the Database -esource anager at the session level.0t is integrated with Automatic Database Diagnostic onitor (ADD #.

    There are different ways to manage and monitor the -esource anager by using8nterprise anager Database 6ontrol. On the *erver tabbed page, you clic% the"tatistics lin% in the -esource anager section.

    The -esource anager *tatistics page displays a grouping of statistics and charts that

    depict the current state of the active resource plan. 4ou can view the statistics for thecurrently active plan.

    ;or -esource !sage, you can view 6+! 6onsumed, 0 O -e&uests per *econd, andegabytes of 0 O 0ssued per *econd. Another chart displays -esource anager 0nduced

    3aits. Then there are statistics for 7ueued *essions, Automatic -eprioriti ation, and idletime.

    There are at least three different views in the system that can provide you withinformation about the 6+! utili ation inside the Oracle database5

    -$RSRC_CONSUMER_GROUP -$SYSSTAT -$SESSTAT

    V$RSRC_CONSUMER_GROUP

    -$RSRC_CONSUMER_GROUP shows 6+! utili ation statistics on a per consumer groupbasis, if you are running the Oracle Database -esource anager. This view displays datarelated to currently active resource consumer groups.

    V$SYSSTAT

    -$SYSSTAT shows the Oracle database 6+! usage for all sessions. The statistic 6+!used by this session shows the aggregate 6+! used by all sessions.

    V$SESSTAT

    -$SESSTAT shows the Oracle database 6+! usage per session. 4ou can use this view todetermine which particular session is using the most 6+!.

    *ome of the columns in the -$RSRC_CONSUMER_GROUP view include

  • 8/10/2019 Oracle Database 11g Managing Resources and Task Automation

    21/68

    ' e / the name of the consumer group %/09e_sess0&'s / the number of currently active sessions in this consumer group e e%u/0&'_: 0/e s / the number of active sessions waiting for a time slice e ues/s / the cumulative number of re&uests e ecuted in this consumer group

    %*u_: 0/_/0 e / the cumulative amount of time that sessions waited for 6+! %&'su e6_%*u_/0 e / the cumulative amount of 6+! time consumed by all sessions

    There is no view that shows the Active *ession +ool &ueue directly, but you can get someinformation from

    -$SESSION -$RSRC_CONSUMER_GROUP

    V$SESSION

    The es&u %e_%&'su e _) &u* column shows the current group for a session. The%u e'/_ ueue_6u /0&' column shows how long a session has been &ueued, or C( ero# if the session is not currently &ueued.

    V$RSRC_CONSUMER_GROUP

    The ueue_8e')/@ column shows the number of sessions currently &ueued perconsumer group.

    "ummar+

    4ou can use 8nterprise anager:s property pages to specify resource plan directives.

    -esource allocation methods determine how the -esource anager allocates a particular resource to a resource consumer group or resource plan. The parameters includeMGMT_MTH, PARALLEL_DEGREE_LIMIT_MTH , ACTI-E_SESS_POOL_MTH , andQUEUING_MTH.

    4ou can use the Active *ession +ool feature, which can be set in 8nterprise anager, tocontrol the number of active sessions per resource consumer group. 4ou can define thema imum estimated e ecution time an operation can ta%e by setting theMAX_EST_EXEC_TIME parameter. 4ou can also configure the Database -esource

    anager by providing mappings between session attributes and consumer groups.

    4ou can activate resource plans on the -esource +lans page of 8nterprise anager.*everal data dictionary views are available to chec% the resource plans, consumergroups, and plan directives that are declared in the instance.

    4ou can monitor the functioning of the Database -esource anager at the session level.There are different ways to manage and monitor the -esource anager by using8nterprise anager Database 6ontrol.

  • 8/10/2019 Oracle Database 11g Managing Resources and Task Automation

    22/68

    &able o Contents

    | &op o page |

    | Learning objective |

    | 1. Using resource plans |

    | *. "etting the !ctive "ession Pool |

    | ,. !ctivating a resource plan |

    | -. Monitoring the Resource Manager |

    | "ummar+ |

    6opyright B >CC *%ill*oft. All rights reserved.*%ill*oft and the *%ill*oft logo are trademar%s or registered trademar%s

    of *%ill*oft in the !nited *tates and certain other countries. All other logos or trademar%s are the property of their respective owners.

    | Print | Contents | Close |

    Managing Resources

    Learning objective

    After completing this topic, you should be able to use the Database Resource Manager to

    address system resource utilization and control in a given scenario.

    E%ercise overvie#

    4ou want to use the Database -esource anager to improve system resource utili ationand control.

    0n this e ercise, you:re re&uired to balance resources, create a consumer group, assign aconsumer group to a resource plan, map database and O* users to resource groups, andactivate a resource plan.

    This involves the following tas%s5

    managing resources

    mapping users to consumer groups

    mapping an Oracle user

    activating a resource plan

    http://library.skillport.com/courseware/cbtlib/257108/257111/eng/thin/transcript.html#pagetophttp://library.skillport.com/courseware/cbtlib/257108/257111/eng/thin/transcript.html#pagetophttp://library.skillport.com/courseware/cbtlib/257108/257111/eng/thin/transcript.html#objectivehttp://library.skillport.com/courseware/cbtlib/257108/257111/eng/thin/transcript.html#section_1http://library.skillport.com/courseware/cbtlib/257108/257111/eng/thin/transcript.html#section_2http://library.skillport.com/courseware/cbtlib/257108/257111/eng/thin/transcript.html#section_3http://library.skillport.com/courseware/cbtlib/257108/257111/eng/thin/transcript.html#section_3http://library.skillport.com/courseware/cbtlib/257108/257111/eng/thin/transcript.html#section_4http://library.skillport.com/courseware/cbtlib/257108/257111/eng/thin/transcript.html#summaryhttp://%20window.print%28%29/http://%20window.print%28%29/http://library.skillport.com/courseware/cbtlib/257108/257112/eng/softsim/transcript.html#contentshttp://%20parent.window.close%28%29/http://%20parent.window.close%28%29/http://library.skillport.com/courseware/cbtlib/257108/257111/eng/thin/transcript.html#pagetophttp://library.skillport.com/courseware/cbtlib/257108/257111/eng/thin/transcript.html#objectivehttp://library.skillport.com/courseware/cbtlib/257108/257111/eng/thin/transcript.html#section_1http://library.skillport.com/courseware/cbtlib/257108/257111/eng/thin/transcript.html#section_2http://library.skillport.com/courseware/cbtlib/257108/257111/eng/thin/transcript.html#section_3http://library.skillport.com/courseware/cbtlib/257108/257111/eng/thin/transcript.html#section_4http://library.skillport.com/courseware/cbtlib/257108/257111/eng/thin/transcript.html#summaryhttp://%20window.print%28%29/http://library.skillport.com/courseware/cbtlib/257108/257112/eng/softsim/transcript.html#contentshttp://%20parent.window.close%28%29/
  • 8/10/2019 Oracle Database 11g Managing Resources and Task Automation

    23/68

    &as) 1 Managing resources

    6reate a resource group called JA++!*8-J and view the associated *7" statement.-eturn to the *erver tabbed page using the Database 'nstance orcl* hyperlin% and addthe A++!*8- and "O3K9-O!+ consumer groups to the D8;A!"TK+"A< resourceplan. 6hange the level ? 6+! resource allocation percentages to CF for the A++!*8-consumer group and @CF for the "O3K9-O!+ consumer group.

    "teps list

    'nstructions

    1. 6lic% the "erver tab

    >. 6lic% the Consumer Groups hyperlin% in the -esource anager section

    ?. 6lic% Create

    @. Type APPUSER in the 6onsumer 9roup te t bo and clic% "ho# "$L

    . 6lic% Return and then clic% /0

    . 6lic% the Database 'nstance orcl* hyperlin%

    I. 6lic% the Plans hyperlin% in the -esource anager section

    E. *elect DE !UL&2PL!( and clic% Edit

    L. 6lic% Modi + on the 9eneral tabbed page

    1C. *elect !PPU"ER , clic% Move , select L/32GR/UP , clic% Move , and then clic% /0

    11. Type ;< in the "evel ? te t bo for the A++!*8- group, type 2< in the "evel ? te t bo for the "O3K9-O!+group, and clic% !ppl+

    &as) * Mapping users to consumer groups

    6onfigure consumer group mappings so that the G- Oracle user belongs to the A++!*8- consumer group, and the *6OTT user belongs to the OTG8-K9-O!+*consumer group. ;or the *6OTT user, confirm that the Oracle !ser attribute has a higher priority than the 6lient O* !ser attribute.

    "teps list

    'nstructions

    1. 6lic% the "erver tab

    >. 6lic% Consumer Group Mappings in the -esource anager section

    ?. *elect the /racle User radio button and clic% !dd Rule or "elected &+pe

    @. *elect 4R and clic% Move

    . 6lic% /0 and then clic% !ppl+

  • 8/10/2019 Oracle Database 11g Managing Resources and Task Automation

    24/68

    "teps list

    'nstructions

    . 8nsure the /racle User radio button is selected and clic% !dd Rule or "elected &+pe

    I. *elect L/32GR/UP from the *elect 6onsumer 9roup drop$down list

    E. *elect "C/&& , clic% Move , and clic% /0

    L. 6lic% the Priorities tab

    1C. 8nsure that Oracle !ser is listed at a higher priority than the 6lient O* !ser attribute and clic% !ppl+

    &as) , Mapping an /racle user

    Assign the + Oracle user to the A++!*8-, "O3K9-O!+, and *4*K9-O!+consumer groups.

    "teps list'nstructions

    1. 6lic% the "erver tab

    >. 6lic% the Users hyperlin% in the *ecurity section

    ?. *elect the PM radio button user and clic% Edit

    @. 6lic% the Consumer Groups Privileges tab

    . 6lic% Edit List

    . *elect !PPU"ER , clic% Move , select L/32GR/UP , clic% Move , select "5"2GR/UP , and clic% Move

    I. 6lic% /0

    E. 6lic% !ppl+

    &as) - !ctivating a resource plan

    Access the -esource +lans page and activate the D8;A!"TK+"A< resource plan.

    "teps list

    'nstructions

    1. 6lic% the "erver tab

    >. 6lic% the Plans hyperlin% in the -esource anager section

    ?. *elect the DE !UL&2PL!( radio button, ensure !ctivate is selected in the Actions drop$down list and clic% Go

    @. 6lic% 5es

    &able o Contents

  • 8/10/2019 Oracle Database 11g Managing Resources and Task Automation

    25/68

    | &op o page |

    | Learning objective |

    | E%ercise overvie# |

    | &as) 1 Managing resources |

    | &as) * Mapping users to consumer groups |

    | &as) , Mapping an /racle user |

    | &as) - !ctivating a resource plan |

    6opyright B >CCE *%ill*oft. All rights reserved.*%ill*oft and the *%ill*oft logo are trademar%s or registered trademar%s

    of *%ill*oft in the !nited *tates and certain other countries. All other logos or trademar%s are the property of their respective owners.

    | Print | Contents | Close |

    &he &as) "cheduler

    Learning objective

    After completing this topic, you should be able to recognize the steps for using theScheduler to create, schedule and monitor regular and lightweight jobs.

    1. "impli +ing management tas)s

    any tas%s in the Oracle environment need 2ob$scheduling capabilities. -outine databasemaintenance and application logic re&uire 2obs to be scheduled and run periodically.

    usiness$to$business ( > # applications re&uire scheduling for their business events.Database administrators (D As# need to schedule regular maintenance 2obs in specifiedtime windows.

    Tas%s simplified by scheduling might include

    performing a series of month$end tas%s on the last day of each month

    running a de&ueue procedure as soon as a message is en&ueued replicating table data via materiali ed view refreshes running a daily 2ob to bac% up database computing table and inde statistics twice a day starting the batch load as soon as the file arrives on the file system generating an hourly report on invalid server access attempts

    http://library.skillport.com/courseware/cbtlib/257108/257112/eng/softsim/transcript.html#pagetophttp://library.skillport.com/courseware/cbtlib/257108/257112/eng/softsim/transcript.html#pagetophttp://library.skillport.com/courseware/cbtlib/257108/257112/eng/softsim/transcript.html#objectivehttp://library.skillport.com/courseware/cbtlib/257108/257112/eng/softsim/transcript.html#section_1http://library.skillport.com/courseware/cbtlib/257108/257112/eng/softsim/transcript.html#section_1http://library.skillport.com/courseware/cbtlib/257108/257112/eng/softsim/transcript.html#section_2http://library.skillport.com/courseware/cbtlib/257108/257112/eng/softsim/transcript.html#section_2http://library.skillport.com/courseware/cbtlib/257108/257112/eng/softsim/transcript.html#section_3http://library.skillport.com/courseware/cbtlib/257108/257112/eng/softsim/transcript.html#section_4http://library.skillport.com/courseware/cbtlib/257108/257112/eng/softsim/transcript.html#section_5http://library.skillport.com/courseware/cbtlib/257108/257112/eng/softsim/transcript.html#section_5http://%20window.print%28%29/http://%20window.print%28%29/http://library.skillport.com/courseware/cbtlib/257108/257114/eng/thin/transcript.html#contentshttp://%20parent.window.close%28%29/http://%20parent.window.close%28%29/http://library.skillport.com/courseware/cbtlib/257108/257112/eng/softsim/transcript.html#pagetophttp://library.skillport.com/courseware/cbtlib/257108/257112/eng/softsim/transcript.html#objectivehttp://library.skillport.com/courseware/cbtlib/257108/257112/eng/softsim/transcript.html#section_1http://library.skillport.com/courseware/cbtlib/257108/257112/eng/softsim/transcript.html#section_2http://library.skillport.com/courseware/cbtlib/257108/257112/eng/softsim/transcript.html#section_3http://library.skillport.com/courseware/cbtlib/257108/257112/eng/softsim/transcript.html#section_4http://library.skillport.com/courseware/cbtlib/257108/257112/eng/softsim/transcript.html#section_5http://%20window.print%28%29/http://library.skillport.com/courseware/cbtlib/257108/257114/eng/thin/transcript.html#contentshttp://%20parent.window.close%28%29/
  • 8/10/2019 Oracle Database 11g Managing Resources and Task Automation

    26/68

    rebuilding an inde when finished rebuilding the current inde

    The Oracle database provides advanced scheduling capabilities through the database*cheduler. The *cheduler is a collection of functions and procedures in theDBMS_SCHEDULER pac%age. The *cheduler can be invo%ed in any *7" environment, or

    through 8nterprise anager (8 #.

    The *cheduler enables D As and application developers to control when and wherevarious tas%s ta%e place in the database environment. These tas%s can be timeconsuming and complicated. !sing the *cheduler, you can manage and plan these tas%s.

    *cheduler 2obs can be started based on time or when a specified event occurs. And the*cheduler can raise events when a 2ob:s state changes / for e ample, from RUNNING toCOMPLETE.

    4ou can also use a named series of programs that are lin%ed together for a combined

    ob2ective.

    A 2ob has two %ey components5

    action / JwhatJ needs to be done schedule / JwhenJ the action occurs

    The JwhatJ is e pressed in the 6ommand section of the 6reate Mob page.

    A 2ob is also defined by JwhenJ the desired action needs to ta%e place. The JwhenJ ise pressed in a schedule on the *chedule tabbed page. The schedule can be based ontime or events, or be dependent on the outcome of other 2obs.

    The 2ob can also be represented as code.

    The JwhatJ portion is e pressed in the &7_/ *e and &7_ %/0&' parameters.

    BEGINs s.67 s_s%@e6u8e .% e /e_ &7(

    &7_' e !" # HR . CREATE_LOG_TABLE_ OB #&7_/ *e !" #PLSQL_BLOCK# &7_ %/0&' !" #7e)0'

    e e%u/e 0 e60 /e (##% e /e / 78e sess0&'_@0s/& ( s' *_/0 e TIMESTAMP WITH LOCAL TIME ONE 'u _sess0&'s NUMBER+##+, e'6,#s/ /_6 /e !" s s/0 es/ * / /0 e J&'e #A e 0% Ne:_Y& #

    &7_%8 ss !" #DEFAULT_ OB_CLASS#%& e'/s !" #C e /e /@e SESSION_HISTORY / 78e#

    u/&_6 &* !" FALSE e' 78e6 !" TRUE+,END,

  • 8/10/2019 Oracle Database 11g Managing Resources and Task Automation

    27/68

    The JwhenJ portion is e pressed in the s/ /_6 /e * e/e .

    The *cheduler offers a modulari ed approach for managing tas%s within the Oracledatabase. y brea%ing down a tas% into its components, such as time, location, anddatabase ob2ect, the *cheduler offers you an easier way to manage your database

    environment.

    To simplify management tas%s with the *cheduler, you

    create a program

    create and use a schedule create and submit a 2ob

    monitor a 2ob

    The *cheduler uses three basic components5

    2ob

    program schedule

    job

    A 2ob specifies what needs to be e ecuted and when. ;or e ample, the JwhatJ could be a+" *7" procedure, a native binary e ecutable, a Mava application, or a shell script.

    4ou can specify the program (what# and schedule (when# as part of the 2ob definition, oryou can use an e isting program or schedule instead. 4ou can use arguments for a 2ob tocustomi e its run$time behavior.

    program

    A program is a collection of metadata about a particular e ecutable, script, or procedure.

    An automated 2ob e ecutes some tas%. !sing a program enables you to modify the 2obtas%, or the Jwhat,J without modifying the 2ob itself. 4ou can define arguments for aprogram, enabling users to modify the run$time behavior of the tas%.

    schedule

    A schedule specifies when and how many times a 2ob is e ecuted. A schedule can be

    based on time or an event. 4ou can define a schedule for a 2ob by using a series of dates,an event, or a combination of the two, along with additional specifications to denoterepeating intervals.

    4ou can store the schedule for a 2ob separately and then use the same schedule formultiple 2obs.

  • 8/10/2019 Oracle Database 11g Managing Resources and Task Automation

    28/68

    4ou can use the CREATE_PROGRAM procedure to create a program. 6reating a programis an optional part of using the *cheduler. 4ou can also encode the action to beperformed within an anonymous +" *7" bloc% in the CREATE_ OB procedure.

    y creating the program separately, you can define the action once, and then reuse this

    action within multiple 2obs. This enables you to change the schedule for a 2ob withouthaving to re$create the +" *7" bloc%. 4ou can also customi e the 2ob by specifyingargument values.

    BEGINDBMS_SCHEDULER.CREATE_PROGRAM( * &) _' e !" #CALC_STATS4# * &) _ %/0&' !"#HR.UPDATE_HR_SCHEMA_STATS# * &) _/ *e !"#STORED_PROCEDURE# e' 78e6 !" TRUE+,END,

    To create a program in your own schema, you need the CREATE OB privilege. A userwith the CREATE ANY OB privilege can create a program in any schema.

    A program is created in a disabled state by default, unless the e' 78e6 parameter is setto TRUE. A disabled program cannot be e ecuted by a 2ob until it is enabled. 4ou canspecify that a program should be created in the enabled state by specifying a value ofTRUE for enabled.

    The program action is a string specifying a procedure, e ecutable name, or a +" *7"anonymous bloc%, depending on what * &) _/ *e is set to.

    0f you have a procedure called UPDATE_HR_SCHEMA_STATS that collects the statistics for the hr schema, then you can create a program to call this procedure.

    BEGINDBMS_SCHEDULER.CREATE_PROGRAM( * &) _' e !" #CALC_STATS4# * &) _ %/0&' !"

    #HR.UPDATE_HR_SCHEMA_STATS# * &) _/ *e !"#STORED_PROCEDURE# e' 78e6 !" TRUE+,END,

  • 8/10/2019 Oracle Database 11g Managing Resources and Task Automation

    29/68

    To create a program, you clic% Programs in the Oracle *cheduler section of the *erverpage in 8nterprise anager.

    Then you clic% Create on the *cheduler +rograms page.

    The 6reate +rogram page is displayed.

    y using a schedule instead of specifying the e ecution times for a 2ob within the 2obdefinition, you can manage the scheduled e ecution of multiple 2obs without having toupdate multiple 2ob definitions.

    0f a schedule is modified, then each 2ob that uses that schedule automatically uses thenew schedule.

    BEGIN DBMS_SCHEDULER.CREATE_SCHEDULE( s%@e6u8e_' e !" #s/ /s_s%@e6u8e# s/ /_6 /e !" SYSTIMESTAMP e'6_6 /e !" SYSTIMESTAMP 3< e*e /_0'/e 9 8 !" #FREQ!HOURLY,INTER-AL!5# %& e'/s !" #E9e @&u #+,END,

    4ou can use the CREATE_SCHEDULE procedure in the DBMS_SCHEDULER +" *7"pac%age to create a schedule.

    The s/ /_6 /e represents the date on which the schedule becomes active. Theschedule cannot refer to any dates before this date. The schedule is not valid after thee'6_6 /e .

    4ou can schedule repeated e ecutions by supplying a calendaring e pression fore*e /_0'/e 9 8 . This calendaring e pression is used to generate the ne t date of the

    schedule. Dates falling after the e'6_6 /e time are not included in the schedule.

    BEGIN DBMS_SCHEDULER.CREATE_SCHEDULE(

    s%@e6u8e_' e !" #s/ /s_s%@e6u8e# s/ /_6 /e !" SYSTIMESTAMP e'6_6 /e !" SYSTIMESTAMP 3< e*e /_0'/e 9 8 !" #FREQ!HOURLY,INTER-AL!5# %& e'/s !" #E9e @&u #+,END,

  • 8/10/2019 Oracle Database 11g Managing Resources and Task Automation

    30/68

    This code shows the creation of a schedule named STATS_SCHEDULE . The codespecifies a repeat interval of every four hours, starting now, and continuing for ?C days.

    BEGIN DBMS_SCHEDULER.CREATE_SCHEDULE( s%@e6u8e_' e !" #s/ /s_s%@e6u8e# s/ /_6 /e !" SYSTIMESTAMP e'6_6 /e !" SYSTIMESTAMP 3< e*e /_0'/e 9 8 !" #FREQ!HOURLY,INTER-AL!5# %& e'/s !" #E9e @&u #+,END,

    4ou can also use 8nterprise anager to create schedules. To do this, you clic% Create onthe *cheduler *chedules page.

    And you enter the schedule:s name and attributes on the 6reate *chedule page.

    A 2ob is a combination of a schedule and a description of what to do, along with anyadditional arguments that are re&uired by the 2ob.

    The program or command can be either

    a pre$created +" *7" or Mava program an anonymous +" *7" bloc%

    an e ecutable that is run from the operating system:s command line

    The schedule for a 2ob can be a predefined schedule created with theDBMS_SCHDULER.CREATE_SCHEDULE procedure. Or it can be defined as part of the 2obcreation.

    The schedule specifies attributes about when the 2ob is run, such as

    a start time, which defines when the 2ob is pic%ed for e ecution and an end time, which specifiesthe time after which the 2ob is no longer valid and is not scheduled any more

    an e pression specifying a repeating interval for the 2ob

    a comple schedule created by combining e isting schedules a condition or change in state, called an event, that must be met before the 2ob is started

    There are many attributes that you can set for a 2ob. Attributes control how the 2obe ecutes.

    To run a 2ob in 8nterprise anager, you clic% the "erver tab and select 6obs from theOracle *cheduler section.

  • 8/10/2019 Oracle Database 11g Managing Resources and Task Automation

    31/68

    The DBA ALL _SCHEDULER_ OB_RUN_DETAILS views have a row for each 2obinstance. 8ach row contains information about the 2ob e ecution for that instance.

    SELECT &7_' e s/ /us e & u'_6u /0&'FROM USER_SCHEDULER_ OB_RUN_DETAILS,

    OB_NAME STATUS ERROR RUN_DURATION

    GATHER_STATS_ OB SUCCESS <

  • 8/10/2019 Oracle Database 11g Managing Resources and Task Automation

    32/68

    ;urther columns relevant to DBA ALL _SCHEDULER_ OB_RUN_DETAILS viewsinclude5

    ACTUAL_START_DATE RUN_DURATION INSTANCE_ID SESSION_ID SLA-E_PID CPU_USED ADDITIONAL_INFO

    ACTUAL_START_DATE

    ACTUAL_START_DATE indicates the time at which the 2ob was actually started.

    RUN_DURATION

    The duration of e ecution of the 2ob.

    INSTANCE_ID

    INSTANCE_ID identifies the instance upon which the 2ob ran.

    SESSION_ID

    SESSION_ID indicates the session the 2ob ran within.

    SLAVE_PID

    SLA-E_PID denotes the process 0D of the slave process used to perform the 2obe ecution.

    CPU_USED CPU_USED records the amount of 6+! used for the 2ob run.

    ADDITIONAL_INFO

    ADDITIONAL_INFO offers additional information about the 2ob run.

    Mob instances can also be viewed in 8nterprise anager.

    $uestion

    3hich component used by the *cheduler specifies what needs to be e ecuted

    and when=

    Options5

    1. A 2ob

    >. A program

    ?. A schedule

  • 8/10/2019 Oracle Database 11g Managing Resources and Task Automation

    33/68

  • 8/10/2019 Oracle Database 11g Managing Resources and Task Automation

    34/68

    4ou should use SYSTIMESTAMP and specify a time one so that when the time changesbecause of daylight saving time, your 2ob ad2usts its e ecution time automatically.

    BEGIN DBMS_SCHEDULER.CREATE_ OB( &7_' e!"#HR.DO_BACKUP# &7_/ *e !" #EXECUTABLE# &7_ %/0&' !"# @& e us 67 ' '0)@/8 _0'% .s@# s/ /_6 /e!" SYSDATE e*e /_0'/e 9 8!"#FREQ!DAILY,BYHOUR!43# 'e / '0)@/ / 551

  • 8/10/2019 Oracle Database 11g Managing Resources and Task Automation

    35/68

  • 8/10/2019 Oracle Database 11g Managing Resources and Task Automation

    36/68

    s/ /_6 /e!" SYSDATE e*e /_0'/e 9 8!"#FREQ!DAILY,BYHOUR!43# 'e / '0)@/ / 551

  • 8/10/2019 Oracle Database 11g Managing Resources and Task Automation

    37/68

    There are some customers that have a need to create hundreds of 2obs a second. 3ithregular 2obs, each 2ob creates a database ob2ect describing the 2ob, modifying severaltables, and creating redo in the process. The overhead associated with this type of 2obneed is substantial.

    0n the Oracle Database *cheduler, there is a persistent lightweight

  • 8/10/2019 Oracle Database 11g Managing Resources and Task Automation

    38/68

    re8uire the use o a template

    8very lightweight 2ob is created from a 2ob template, which is stored as a program.

    produce a small improvement in e%ecution

    ecause persistent lightweight 2obs write state information to dis% at run time, only a small

    improvement is e pected in the e ecution.

    inherit their privileges rom the parent job templates

    A limitation of persistent lightweight 2obs is that the user cannot set privileges on these 2obs / they inherit their privileges from the parent 2ob template.

    must use a template

    One of the limitations of persistent lightweight 2obs is that the use of a template ismandatory / it is not possible to create a fully self$contained persistent lightweight 2ob.

    provide onl+ certain job attributes

    A limitation of persistent lightweight 2obs is that only certain 2ob attributes are available tobe set, such as OB_ARGUMENTS.

    create a large number o jobs in a ver+ short time

    "ightweight 2obs are most useful when users need to create a large number of 2obs in avery short time / about 1C/1CC 2obs a second. And they have a library of programs / or 2obtemplates / available that they can use.

    The DBMS_SCHEDULER pac%age has updated several pac%ages to allow the lightweight 2obs to be created with a minimum of new code.

    "ightweight 2obs have very few parameters that can be specified / 2ob arguments and

    schedule. The rest of the metadata for the 2ob is inherited from the 2ob template, includingprivileges.

    The template for a lightweight 2ob must be a +" *7" bloc% or a stored procedure."ightweight 2obs must be created through +" *7" using the DBMS_SCHEDULER pac%age

    / the OB_STYLE argument is not available in 8 .

    ;or e ample, MY_PROG can be the 2ob template, and the schedule can be created as partof the CREATE_ OB method.

    BEGINDBMS_SCHEDULER.CREATE_ OB ( &7_' e !" # _80)@/:e0)@/_ &75# * &) _' e !" #MY_PROG# e*e /_0'/e 9 8 !" #FREQ!DAILY,BY_HOUR! # e'6_/0 e !" #3< APR

  • 8/10/2019 Oracle Database 11g Managing Resources and Task Automation

    39/68

    The schedule can also be applied from a named schedule, as in this e ample.

    BEGINDBMS_SCHEDULER.CREATE_ OB ( &7_' e !" # _80)@/:e0)@/_ &74# * &) _' e !" #MY_PROG# s%@e6u8e_' e !" #MY_SCHED# &7_s/ 8e !" #LIGHTWEIGHT#+,END,

    $uestion

    3hat are the advantages and disadvantages of persistent lightweight and regular 2obs=

    Options5

    1. A persistent lightweight 2ob must use a template

    >. A persistent lightweight 2ob offers a user fine$grained control of the privileges

    ?. A regular 2ob is most beneficial when users need to &uic%ly create a large number of 2obs

    @. A regular 2ob offers the ma imum fle ibility in 2ob creation

    !ns#er

    A persistent lightweight 2ob must use a template and a regular 2ob offers the

    ma imum fle ibility in 2ob creation.

    !ption " is correct. 3ith a persistent lightweight

  • 8/10/2019 Oracle Database 11g Managing Resources and Task Automation

    40/68

    The Oracle database *cheduler enables you to manage and plan the tas%s that ta%eplace in the database environment. 4ou use it to simplify management tas%s.

    To create a time$based 2ob, you use the CREATE_ OB procedure of theDBMS_SCHEDULER pac%age. y default, a 2ob is created in the current schema. 4ou can

    create a 2ob in another schema by specifying the name of the schema.

    A lightweight 2ob is used to reduce the overhead and time re&uired to start a 2ob. Tocreate a lightweight 2ob, you use a 2ob template, which is created using theDBMS_SCHEDULER.CREATE_PROGRAM procedures.

    &able o Contents

    | &op o page |

    | Learning objective |

    | 1. "impli +ing management tas)s |

    | *. Creating time7based jobs |

    | ,. Creating light#eight jobs |

    | "ummar+ |

    6opyright B >CC *%ill*oft. All rights reserved.*%ill*oft and the *%ill*oft logo are trademar%s or registered trademar%s

    of *%ill*oft in the !nited *tates and certain other countries.

    All other logos or trademar%s are the property of their respective owners.

    | Print | Contents | Close |

    &ime and Event 9ased 6obs

    Learning objective

    After completing this topic, you should be able to distinguish between time based andevent based schedules for e!ecuting jobs and job chains using the Scheduler.

    1. Creating an event7based schedule

    Mobs can be triggered based on events. An application can notify the *cheduler to start a 2ob by en&ueuing a message onto an Oracle *treams &ueue. A 2ob started in this way isreferred to as an event$based 2ob.

    http://library.skillport.com/courseware/cbtlib/257108/257114/eng/thin/transcript.html#pagetophttp://library.skillport.com/courseware/cbtlib/257108/257114/eng/thin/transcript.html#pagetophttp://library.skillport.com/courseware/cbtlib/257108/257114/eng/thin/transcript.html#objectivehttp://library.skillport.com/courseware/cbtlib/257108/257114/eng/thin/transcript.html#section_1http://library.skillport.com/courseware/cbtlib/257108/257114/eng/thin/transcript.html#section_2http://library.skillport.com/courseware/cbtlib/257108/257114/eng/thin/transcript.html#section_3http://library.skillport.com/courseware/cbtlib/257108/257114/eng/thin/transcript.html#summaryhttp://%20window.print%28%29/http://%20window.print%28%29/http://library.skillport.com/courseware/cbtlib/257108/257115/eng/thin/transcript.html#contentshttp://%20parent.window.close%28%29/http://%20parent.window.close%28%29/http://library.skillport.com/courseware/cbtlib/257108/257114/eng/thin/transcript.html#pagetophttp://library.skillport.com/courseware/cbtlib/257108/257114/eng/thin/transcript.html#objectivehttp://library.skillport.com/courseware/cbtlib/257108/257114/eng/thin/transcript.html#section_1http://library.skillport.com/courseware/cbtlib/257108/257114/eng/thin/transcript.html#section_2http://library.skillport.com/courseware/cbtlib/257108/257114/eng/thin/transcript.html#section_3http://library.skillport.com/courseware/cbtlib/257108/257114/eng/thin/transcript.html#summaryhttp://%20window.print%28%29/http://library.skillport.com/courseware/cbtlib/257108/257115/eng/thin/transcript.html#contentshttp://%20parent.window.close%28%29/
  • 8/10/2019 Oracle Database 11g Managing Resources and Task Automation

    41/68

    To create an event$based 2ob, you must set two additional attributes with theCREATE_ OB procedure5

    ueue_s*e% e9e'/_%&'60/0&'

    queue_s e!

    The ueue_s*e% attribute is a &ueue specification that includes the name of the &ueuewhere your application en&ueues messages to raise 2ob start events, or in the case of asecure &ueue, the ) ueue_' e N, ) )e'/_' e N pair.

    e"e _!% &' '%

    The e9e'/_%&'60/0&' attribute is a conditional e pression based on messageproperties that must evaluate to TRUE for the message to start the 2ob. 4ou can includeuser data properties in the e pression, provided that the message payload is a user$defined ob2ect type, and that you prefi ob2ect attributes in the e pression with

    / 7.use _6 / .

    4ou can either specify ueue_s*e% and e9e'/_%&'60/0&' as in$line 2ob attributes, oryou can create an event$based schedule with these attributes and then create a 2ob thatreferences this schedule.

    The 6reate *chedule page in 8nterprise anager enables you to choose between astandard, time$based schedule and an event$based schedule. 0f you choose an event$based schedule, then the interface changes and you can specify the &ueue name, agentname, and event condition, in addition to the other schedule attributes.

    (ote

    The 8cheduler runs the event4based

  • 8/10/2019 Oracle Database 11g Managing Resources and Task Automation

    42/68

    s/ /_6 /e !" SYSTIMESTAMP e9e'/_%&'60/0&' !" #/ 7.use _6 / .&7 e%/_&:'e ! ##HR## '6 / 7.use _6 / .&7 e%/_' e ! ##DATA.TXT## '6 / 7.use _6 / .e9e'/_/ *e ! ##FILE_ARRI-AL## '6 / 7.use _6 / .e9e'/_/0 es/ * # ueue_s*e% !" #HR.LOAD_ OB_E-ENT_Q#+,END,

    The code e ample uses a user$defined event. Therefore, before this 2ob can be started,when the file arrives on the file system, a program or procedure must en&ueue the eventob2ect type with the proper information into the specified event &ueue.

    The HR.LOAD_ OB_E-ENT_Q &ueue must be of the same type as the event ob2ect typeused for notifying the *cheduler of an event occurrence. That is, theHR.LOAD_ OB_E-ENT_Q &ueue must be a typed &ueue where the type has fourattributes named &7 e%/_&:'e , &7 e%/_' e , e9e'/_/ *e , and

    e9e'/_/0 es/ * .

    BEGIN DBMS_SCHEDULER.CREATE_ OB( &7_' e!"#ADMIN.PERFORM_DATA_LOAD# &7_/ *e !" #EXECUTABLE# &7_ %/0&' !" # @& e us 67 ' e*& /_ 08u e.s@# s/ /_6 /e !" SYSTIMESTAMP e9e'/_%&'60/0&' !" #/ 7.use _6 / .&7 e%/_&:'e ! ##HR## '6 / 7.use _6 / .&7 e%/_' e ! ##DATA.TXT## '6 / 7.use _6 / .e9e'/_/ *e ! ##FILE_ARRI-AL## '6 / 7.use _6 / .e9e'/_/0 es/ * # ueue_s*e% !" #HR.LOAD_ OB_E-ENT_Q#+,END,

    The code e ample shows a 2ob that is started when a file arrives on the operating system,as long as the file arrives before L5CC A . 4ou can assume that the message payload isan ob2ect with four attributes named &7 e%/_&:'e , &7 e%/_' e , e9e'/_/ *e , ande9e'/_/0 es/ * .

    BEGIN DBMS_SCHEDULER.CREATE_ OB( &7_' e!"#ADMIN.PERFORM_DATA_LOAD# &7_/ *e !" #EXECUTABLE# &7_ %/0&' !" # @& e us 67 ' e*& /_ 08u e.s@# s/ /_6 /e !" SYSTIMESTAMP e9e'/_%&'60/0&' !" #/ 7.use _6 / .&7 e%/_&:'e ! ##HR## '6 / 7.use _6 / .&7 e%/_' e ! ##DATA.TXT## '6 / 7.use _6 / .e9e'/_/ *e ! ##FILE_ARRI-AL## '6 / 7.use _6 / .e9e'/_/0 es/ * #

  • 8/10/2019 Oracle Database 11g Managing Resources and Task Automation

    43/68

    ueue_s*e% !" #HR.LOAD_ OB_E-ENT_Q#+,END,

    4ou can create a 2ob that directly references an event as the means to start the 2ob,instead of assigning a schedule to the 2ob. There are two types of events5

    user$or application$generated events

    *cheduler$generated events

    user7or application7generated events

    3ith user$ or application$generated events, an application can raise an event to beconsumed by the *cheduler. The *cheduler reacts to the event by starting a 2ob.

    An e ample of such events is when a running 2ob completes, a file arrives on the filesystem, an account within the database is loc%ed, and the inventory reaches a lowthreshold.

    "cheduler7generated events

    3ith *cheduler$generated events, the *cheduler can raise an event to indicate statechanges that occur within the *cheduler itself. ;or e ample, the *cheduler can raise anevent when a 2ob starts, completes, or e ceeds its allotted run time.

    The consumer of the event is an application that performs some action in response to theevent.

    4ou can configure a 2ob so that the *cheduler raises an event when the 2ob:s statechanges. 4ou do this by setting the 0se_e9e'/s 2ob attribute.

    y default, a 2ob does not raise any state change events until you alter the0se_e9e'/s attribute for a 2ob. To alter this attribute, you must first create the 2ob by

    using the CREATE_ OB procedure and then use the SET_ATTRIBUTE procedure tomodify the attribute:s default value.

    This code shows that the @ .6&_7 % u* 2ob is altered, so that it raises an event if the 2ob fails.

    DBMS_SCHEDULER.SET_ATTRIBUTE(#@ .6&_7 % u*# # 0se_e9e'/s# DBMS_SCHEDULER. OB_FAILED+,

    After you enable 2ob state change events for a 2ob, the *cheduler raises these events byen&ueuing messages onto the default event &ueue SYS.SCHEDULER$_E-ENT_QUEUE .

    The default *cheduler event &ueue is a secure &ueue. Depending on your application,you may have to configure the &ueue to enable certain users to perform operations on it.

    The default *cheduler event &ueue is intended primarily for *cheduler$generated events.

  • 8/10/2019 Oracle Database 11g Managing Resources and Task Automation

    44/68

    Oracle does not recommend the use of this &ueue for user applications, or user$definedevents.

    DBMS_SCHEDULER.SET_ATTRIBUTE(#@ .6&_7 % u*# # 0se_e9e'/s# DBMS_SCHEDULER. OB_FAILED+,

    *ome events that are raised by *cheduler 2obs include

    OB_START OB_SUCCEEDED OB_FAILED OB_BROKEN OB_COMPLETED OB_STOPPED

    JOB_START

    The OB_START event specifies that the 2ob is started.

    JOB_SUCCEEDED

    The OB_SUCCEEDED event specifies that the 2ob is successfully completed.

    JOB_FAILED

    The OB_FAILED event specifies that the 2ob failed, either by raising an error or byabnormally terminating.

    JOB_BROKEN

    The OB_BROKEN event specifies that the 2ob is disabled and changed to the BROKEN state, because it e ceeded the number of failures defined by the MAX_FAILURES 2obattribute.

    JOB_COMPLETED

    The OB_COMPLETED event specifies that the 2ob is completed, because it reached thevalues set by the MAX_RUNS or END_DATE 2ob attributes.

    JOB_STOPPED

    The OB_STOPPED event specifies that the 2ob is stopped by a call to the STOP_ OB procedure.

    Other events that are raised by *cheduler 2obs include

    OB_SCH_LIM_REACHED OB_DISABLED OB_CHAIN_STALLED OB_ALL_E-ENTS OB_RUN_COMPLETED

  • 8/10/2019 Oracle Database 11g Managing Resources and Task Automation

    45/68

  • 8/10/2019 Oracle Database 11g Managing Resources and Task Automation

    46/68

    !ption & is correct. The OB_FAILED event is generated when a

  • 8/10/2019 Oracle Database 11g Managing Resources and Task Automation

    47/68

    4ou want to create a schedule by combining several already$created schedulesusing only the dates that are common between them.

    3hat option will you need to use when defining the repeat interval for theschedule=

    Options5

    1. EXCLUDE

    >. INCLUDE

    ?. INTERSECT

    !ns#er

    4ou need to use the INTERSECT option when defining the repeat interval for theschedule.

    !ption " is incorrect. The EXCLUDE option is for removing certain dates from thecalendaring e-pression results when combining schedules.

    !ption % is incorrect. 3hen combining schedules, you can add a list of dates tothe calendaring e-pression results using the INCLUDE option when defining therepeat interval for the schedule. >owever, this option does not specify only thosedates that are common between the schedules.

    !ption & is correct. 3hen combining schedules, you can choose to use only thedates that are common to one or more schedules by using the INTERSECT option

    when defining the repeat interval for the schedule.

    ,. Creating job chains

    A chain is a named series of programs that are lin%ed together for a combined ob2ective.This is %nown as dependency scheduling. An e ample of a chain may be if you runprogram A and then program , but only run program 6 if programs A and completesuccessfully, otherwise run program D.

    8ach position within a chain of interdependent programs is referred to as a step.

    Typically, after an initial set of chain steps has started, the e ecution of successive stepsdepends on the completion of one or more previous steps.

    To create and use a chain, you complete four steps5

    1. create a chain ob2ect>. define chain steps?. define chain rules

  • 8/10/2019 Oracle Database 11g Managing Resources and Task Automation

    48/68

    @. start the chain

    All procedures mentioned are part of the D *K*6G8D!"8- pac%age, unless notedotherwise.

    4ou first create a chain by using theCREATE_CHAIN

    procedure. The chain name can beoptionally &ualified with a schema name / for e ample, s%@e . ' e .

  • 8/10/2019 Oracle Database 11g Managing Resources and Task Automation

    49/68

    All rules added to a chain wor% together to define the overall behavior of the chain. 3henthe 2ob starts and at the end of each step, all rules are evaluated to see what action oractions occur ne t.

    4ou add a rule to a chain with the DEFINE_CHAIN_RULE procedure. 4ou call this

    procedure once for each rule that you want to add to the chain.

    *tarting the chain involves two actions.

    ;irst, you enable a chain with the ENABLE procedure. A chain is always created disabled,so you can add steps and rules to the chain before it is e ecuted by any 2ob. 8nabling analready enabled chain does not return an error.

    *econd, to run a chain, you must create a 2ob of type CHAIN. The 2ob action must refer tothe chain name. 4ou can use either event$based or time$based schedules for this 2ob.

    As an e ample of a chain, consider all the tas%s and conditions that occur during a bul%data load. ;irst, you must have data to load. Then you load the data, observing the filesystem to ma%e sure that you do not run out of space during the load.

    After the data load completes, you need to rebuild the inde es defined on the updatedtables. Then you run reports against the newly loaded data.

    To create a chain ob2ect in 8nterprise anager, you clic% Chains in the Oracle *chedulersection of the *erver tabbed page.

    On the *cheduler 6hains page, you clic% Create to create a 2ob chain.

    On the 6reate 6hain page, you must enter the name and owner of the 2ob chain. 4ou canthen choose whether the newly created 2ob chain should be enabled or not. 4ou canenable the chain at a later time.

    To create a chain ob2ect in +" *7", you use this code.

    DBMS_SCHEDULER.CREATE_CHAIN (%@ 0'_' e !" #7u8 _8& 6_%@ 0'#

    u8e_se/_' e !" NULL e9 8u /0&'_0'/e 9 8 !" NULL%& e'/s !" #L& 6 6 / '6 u' e*& /s#+,

    After naming the 2ob chain and optionally providing a description, you enter the 2ob chainsteps, one at a time.

    4ou can create 2ob chain steps of three types5

    a step that runs a program / PROGRAM a step that is another 2ob chain / SUBCHAIN

  • 8/10/2019 Oracle Database 11g Managing Resources and Task Automation

    50/68

    a step that uses a stored event$based schedule / E-ENT_SCHEDULE

    Only one program can run during a step. 8very step in a chain must be defined before thechain can be enabled and used.

    To define chain steps, you perform five steps.

    "tep 1 5 The 8& 6_6 / _e9/ step uses an event$based schedule. The loadKdataKevtstep waits for a FILE_ARRI-AL event to be placed in HR.LOAD_ OB_E-ENT_Q . Thisevent notifies the *cheduler that the DATA.TXT data file has arrived on the file system.

    ecause ueue_s*e% does not include an agent name, the specified &ueue is not asecure &ueue.

    DBMS_SCHEDULER.DEFINE_CHAIN_E-ENT_STEP ( %@ 0'_' e !" #7u8 _8& 6_%@ 0'# s/e*_' e !" #8& 6_6 / _e9/#

    e9e'/_%&'60/0&' !" #/ 7.use _6 / .&7 e%/_&:'e ! ##HR## '6 / 7.use _6 / .&7 e%/_' e ! ##DATA.TXT## '6 / 7.use _6 / .e9e'/_/ *e ! ##FILE_ARRI-AL## # ueue_s*e% !" #HR.LOAD_ OB_E-ENT_Q#+,

    "tep * 5 The 6&_7u8 _8& 6 step performs a bul% data load into the schema tables.

    DBMS_SCHEDULER.DEFINE_CHAIN_STEP ( %@ 0'_' e !" #7u8 _8& 6_%@ 0'# s/e*_' e !" #6&_7u8 _8& 6#

    * &) _' e !" #@ .8& 6_6 / _* &)+,

    "tep , 5 The e7u086_0'6 step rebuilds the inde es for the tables following a dataload.

    DBMS_SCHEDULER.DEFINE_CHAIN_STEP ( %@ 0'_' e !" #7u8 _8& 6_%@ 0'# s/e*_' e !" # e7u086_0'6 # * &) _' e !" #@ . e7u086_0'6e es#+,

    "tep - 5 The u'_ e*& /s step runs a report against the new data. HR.GEN_REPORTS

    is another 2ob chain.

    DBMS_SCHEDULER.DEFINE_CHAIN_STEP (%@ 0'_' e !" #7u8 _8& 6_%@ 0'#

    s/e*_' e !" # u'_ e*& /s# * &) _' e !" #@ .)e'_ e*& /s#+,

  • 8/10/2019 Oracle Database 11g Managing Resources and Task Automation

    51/68

    "tep : 5 The s/&*_:@e'_60s _ u88_e9/ step ends the chain e ecution if the systemruns out of dis% space.

    DBMS_SCHEDULER.DEFINE_CHAIN_E-ENT_STEP ( %@ 0'_' e !" #7u8 _8& 6_%@ 0'# s/e*_' e !" #s/&*_:@e'_60s _ u88_e9/# e9e'/_s%@e6u8e_' e !" #60s _ u88_s%@e6#+

    6hain steps can also be created in 8nterprise anager. To do this, you navigate to the*teps section on the 6reate 6hain page and ma%e your entries.

    After you have specified the 2ob chain steps, you can create rules for the 2ob chain. 6hainrules define when steps run, and define dependencies between steps.

    8ach rule has a condition and an action. 0f the condition evaluates to TRUE, the action isperformed. The condition can also contain the *cheduler:s chain synta .

    To create a rule in 8nterprise anager, you clic% Create in the -ules section.

    3hen entering the rule conditions, character strings should be entered in single &uotationmar%s. The graphical user interface (9!0# automatically escapes the &uotation mar%s asneeded when e ecuting the commands.

    To define chain rules in +" *7", you use this code.

    DBMS_SCHEDULER.DEFINE_CHAIN_RULE ( %@ 0'_' e !" #7u8 _8& 6_%@ 0'# %&'60/0&' !" #TRUE %/0&' !" #START 8& 6_6 / _e9/ s/&*_:@e'_60s _ u88_e9/# u8e_' e !" #6 / 8& 6_ u8e5# %& e'/s !" #s/ / /@e %@ 0'#+,

    After you have finished creating and modifying the 2ob chain, you enable it by calling theENABLE procedure or enabling it from the 6hains page in 8nterprise anager.

    BEGIN DBMS_SCHEDULER.ENABLE (#7u8 _8& 6_%@ 0'#+,END,

    To run a chain, you must create a 2ob. 4ou set the &7_/ *e to CHAIN and the 2ob actionto the name of the 2ob chain you want to e ecute. The rest of the arguments areconfigured as you would configure them for any other type of 2ob. Alternatively, the 2obcalling the 2ob chain can be created and enabled using 8nterprise anager.

  • 8/10/2019 Oracle Database 11g Managing Resources and Task Automation

    52/68

    BEGIN DBMS_SCHEDULER.CREATE_ OB ( &7_' e !" #7u8 _8& 6_%@ 0'_ &7# &7_/ *e !" #CHAIN# &7_ %/0&' !" #7u8 _8& 6_%@ 0'# e*e /_0'/e 9 8 !" # e !6 08 ,7 @&u !>, 7 0'u/e!=,7 se%&'6!

  • 8/10/2019 Oracle Database 11g Managing Resources and Task Automation

    53/68

    OWNER NOT NULL -ARCHAR4(3

  • 8/10/2019 Oracle Database 11g Managing Resources and Task Automation

    54/68

    $ the name and owner of the 2ob that points to the chain$ the name of the steps in the chain and their current state$ errors encountered by the chain step$ the time at which the chain step started and ended$ how long it too% the step to complete$ the name of the 2ob running the step, if it is currently e ecuting

    N e Nu88 T *e

    OWNER NOT NULL -ARCHAR4(3

  • 8/10/2019 Oracle Database 11g Managing Resources and Task Automation

    55/68

    @. ALL_SCHEDULER_RUNNING_CHAINS

    !ns#er

    The ALL_SCHEDULER_RUNNING_CHAINS view contains information about the

    time at which a 2ob chain step started and when it ended.

    !ption " is incorrect. The ALL_SCHEDULER_CHAINS view contains informationabout the chain, as well as the number of rules and steps, among other things. ?ut it does not contain information about the time at which a

  • 8/10/2019 Oracle Database 11g Managing Resources and Task Automation

    56/68

  • 8/10/2019 Oracle Database 11g Managing Resources and Task Automation

    57/68

  • 8/10/2019 Oracle Database 11g Managing Resources and Task Automation

    58/68

    Alternatively, you can leave the es&u %e_%&'su e _) &u* attribute as NULL and setthe service attribute of a 2ob class to a desired database service name. That service can inturn be mapped to a resource consumer group.

    group jobs or prioriti;ation

    Mob classes enable you to group 2obs for prioriti ation. 3ithin the same 2ob class, you canassign priority values of 1$ to individual 2obs so that if two 2obs in the class are scheduledto start at the same time, the one with the higher priority ta%es precedence. This ensuresthat you do not have a less important 2ob preventing the timely completion of a moreimportant one.

    0f two 2obs have the same assigned priority value, the 2ob with the earlier start date ta%esprecedence. 0f no priority is assigned to a 2ob, its priority defaults to ?.

    0f both the es&u %e_%&'su e _) &u* and service attributes are set, and thedesignated service maps to a resource consumer group, the resource consumer group

    named in the es&u %e_%&'su e _) &u* attribute ta%es precedence.

    4ou can use the CREATE_ OB_CLASS procedure of the DBMS_SCHEDULER pac%age tocreate a 2ob class. A class always belongs to the s s schema. To create a class, youmust have the MANAGE SCHEDULER privilege.

    After a 2ob class has been created, you can specify 2obs as members of this 2ob classwhen you create the 2obs, or after the 2obs are created. To do so, you use theSET_ATTRIBUTE procedure of the DBMS_SCHEDULER pac%age.

    EXECUTE DBMS_SCHEDULER.CREATE_ OB_CLASS(

    &7_%8 ss_' e !" #ADMIN_ OBS# es&u %e_%&'su e _) &u* !" #DAYTIME_ OBS# 8&))0')_8e9e8 !" DBMS_SCHEDULER.LOGGING_OFF+ se 90%e_' e !" RACDB5,

    0f you are using 8nterprise anager Database 6ontrol, you can use the 6reate Mob 6lasspage to create or edit a 2ob class that you will assign to a 2ob. 4ou enter the name of the

    2ob class and the resource consumer group with which this 2ob class is associated. 4oucan select the resource consumer group by using the search function.

    There is a default 2ob class named DEFAULT_ OB_CLASS that is created with the

    database. 0f a 2ob is not associated with a 2ob class, then the 2ob belongs to this default 2ob class.

    0f a resource consumer group is not specified when a 2ob class is created, the 2ob classmaps to the DEFAULT_CONSUMER_GROUP resource consumer group. Mobs in the default

    2ob class or in a 2ob class associated with the default resource consumer group may notbe allocated enough resources to complete their tas%s when the -esource anager isenabled.

  • 8/10/2019 Oracle Database 11g Managing Resources and Task Automation

    59/68

    0n addition, you can assign a 2ob class an affinity to a specific service in a -A6environment.

    The priority of 2obs can change over a period of time. ;or e ample, you might want toallocate a high percentage of the database resources to data warehouse loading 2obs atnight and allocate a higher percentage of the resources during the day to the application

    2obs. To accomplish this, you can change the database resource plan by using a*cheduler window.

    4ou create windows to automatically start 2obs or to change resource allocation among 2obs during various time periods of the day, wee%, and so on. A window is represented byan interval of time with a well$defined beginning and end, such as Jfrom 1>5CC A to 5CC

    A .J

    3indows wor% with 2ob classes to control resource allocation. 8ach window specifies theresource plan to activate when the window opens or becomes active. 8ach 2ob classspecifies a resource consumer group or specifies a database service, which can map to aconsumer group.

    A 2ob that runs within a window, therefore, has resources allocated to it according to theconsumer group of its 2ob class and the resource plan of the window.

    A window is open if it is in effect. Only one window can be in effect at any given time. ;ore ample, this code shows that

    $ the window opens / or becomes active / at 5CC + on December 1, >CCI$ the duration, specified as an INTER-AL DAY TO SECOND data type, indicates that thewindow closes at 5CC A on December >, >CCI$ the ne t time the window opens is calculated using the value for REPEAT_INTER-AL ,which evaluates to 5CC + on December >, >CCI$ at 5CC A on December ?1, >CCI, the window closes and is disabled

    BEGIN DBMS_SCHEDULER.CREATE_WINDOW( :0'6&:_' e !" #DEC_NIGHTS# es&u %e_*8 ' !" #END_OF_YEAR# s/ /_6 /e !" #

  • 8/10/2019 Oracle Database 11g Managing Resources and Task Automation

    60/68

    3hile the DEC_NIGHTS window is open, the resources allocated to the 2obs aredetermined by the guidelines specified in the END_OF_YEAR resource plan.

    BEGIN DBMS_SCHEDULER.CREATE_WINDOW(

    :0'6&:_' e !" #DEC_NIGHTS# es&u %e_*8 ' !" #END_OF_YEAR# s/ /_6 /e !" #

  • 8/10/2019 Oracle Database 11g Managing Resources and Task Automation

    61/68

    +rioriti ation is not guaranteed for 2obs in different 2ob classes. ;or e ample, a high$priority 2ob in the APPL_ OBS 2ob class might not get started before a low$priority 2ob inthe ADMIN_ OBS 2ob class, even if they share the same schedule.

    0f the APPL_ OBS 2ob class has a lower level of resource available, then the high$priority

    2ob in that class has to wait for resources to become available, even if there are resourcesavailable to lower$priority 2obs in a different 2ob class.

    A more efficient way to create a set of 2obs is the use of a 2ob array. This also applies tolightweight 2obs. The 2ob array type and CREATE_ OBS procedure are new to theDBMS_SCHEDULER pac%ager in Oracle Database 11g.

    ;or e ample, suppose 1CC 2ob specifications are created in a 2ob array and submitted tothe 2ob &ueue in a single transaction. ;or a lightweight 2ob there is a very limited amountof information needed. 0n this e ample, the s/ /_/0 e parameter defaults to NULL, sothe 2ob is scheduled to start immediately.

    To create an array of lightweight 2obs, you perform five steps.

    "tep 1 5 4ou declare the variable to hold a 2ob definition and a 2ob array variable.

    DECLARE 'e: &7 s s. &7, 'e: &7 s s. &7_ ,

    "tep * 5 4ou initiali e the 2ob array using the SYS. OB_ARRAY constru