标签:nat ice lin let continue values create load data 电子
Using Oracle Scheduler to Automate Tasks
Objectives
After completing this lesson, you should be able to:
• Simplify management tasks by using Oracle Scheduler
• Create a job, program, and schedule
• Monitor job execution
• Use a time-based or event-based schedule for executing Oracle Scheduler jobs
• Describe the use of windows, window groups, job classes, and consumer groups
• Use email notification
• Use job chains to perform a series of related tasks
• Describe Scheduler jobs on remote systems
• Use advanced Scheduler features to prioritize jobs
目标
完成本课程后,您应该能够:
•使用Oracle Scheduler简化管理任务
•创建工作、计划和时间表
•监控作业执行
•使用基于时间或基于事件的计划来执行Oracle计划程序作业
•描述窗口、窗口组、作业类和消费者组的使用
•使用电子邮件通知
•使用工作链执行一系列相关任务
•描述远程系统上的调度程序作业
•使用高级调度器功能对作业进行优先级排序
Simplifying Management Tasks 简化管理任务
Understanding a Simple Job 理解简单的工作
BEGIN
sys.dbms_scheduler.create_job(
job_name => ‘"HR"."CREATE_LOG_TABLE_JOB"‘,
job_type => ‘PLSQL_BLOCK‘, job_action => ‘begin
execute immediate (‘‘create table session_history(
snap_time TIMESTAMP WITH LOCAL TIME ZONE,
num_sessions NUMBER)‘‘); end;‘,
start_date => systimestamp at time zone
‘America/New_York‘,
job_class => ‘DEFAULT_JOB_CLASS‘,
comments => ‘Create the SESSION_HISTORY table‘,
auto_drop => FALSE, enabled => TRUE);
END;
Oracle Scheduler Core Components Oracle Scheduler核心组件
Using Oracle Scheduler
To simplify management tasks with the Scheduler:
1. Create a program (enabled or disabled)—optional
– To reuse this action within multiple jobs
– To change the schedule for a job without having to re-create the PL/SQL block
2. Create and use a schedule.
3. Create and submit a job.
使用Oracle计划程序
要使用计划程序简化管理任务,请执行以下操作:
1创建程序(启用或禁用)-可选
–在多个作业中重用此操作
–在不需要重新创建PL/SQL块的情况下更改作业的计划
2创建和使用明细表。
3创建并提交作业
Quiz
Select the statements that are true about the Scheduler.
a. Creating a program is a mandatory part of using the Scheduler.
b. When the job action is in a program (rather than directly in the job), you can change the job schedule without having to re-create the PL/SQL block.
c. Creating a job is an optional part of using the Scheduler.
d. Each job must have a schedule. It can be a predefined one or defined as part of the job creation.
测验
选择关于调度程序的正确语句。
a、 创建程序是使用调度程序的必需部分。
b、 当作业操作在程序中(而不是直接在作业中)时,您可以更改作业计划,而不必重新创建PL/SQL块。
c、 创建作业是使用调度程序的可选部分。
d、 每个工作都必须有一个时间表。它可以是预定义的,也可以定义为创造就业机会的一部分。
Persistent lightweight jobs:
• Reduce the overhead and time required to start a job
• Have a small footprint on disk for the job metadata and for storing runtime data
• Are created from a job template (in the command line)
持久的轻量级作业:
•减少开始工作所需的开销和时间
•磁盘上的作业元数据和运行时数据的存储空间较小
•根据作业模板创建(在命令行中)
Using a Time-Based or Event-Based Schedule 使用基于时间或基于事件的计划
Creating a Time-Based Job
Example: Create a job that calls a backup script every night at 11:00, starting tonight.
BEGIN
DBMS_SCHEDULER.CREATE_JOB(
job_name=>‘HR.DO_BACKUP‘,
job_type => ‘EXECUTABLE‘,
job_action =>‘/home/usr/dba/rman/nightly_incr.sh‘,
start_date=> SYSDATE,
repeat_interval=>‘FREQ=DAILY;BYHOUR=23‘,/* next night at 11:00 PM */
comments => ‘Nightly incremental backups‘);
END;
/
Creating an Event-Based Schedule
To create an event-based job, you must set:
• A queue specification (where your application enqueues messages to start a job)
• An event condition (same syntax as an Oracle Streams AQ rule condition) that if TRUE starts the job
创建基于事件的计划
要创建基于事件的作业,必须设置:
•队列规范(应用程序将消息排队以启动作业)
•事件条件(与Oracle Streams AQ规则条件的语法相同),如果为TRUE,则启动作业
Creating Event-Based Schedules by Using Enterprise Manager Cloud Control
使用Enterprise Manager云控制创建基于事件的计划
Creating an Event-Based Job 创建基于事件的作业
Example: Create a job that runs if a batch load data file arrives on the file system before 9:00 AM.
示例:创建在批处理加载数据文件在上午9:00之前到达文件系统时运行的作业。
BEGIN
DBMS_SCHEDULER.CREATE_JOB(
job_name=>‘ADMIN.PERFORM_DATA_LOAD‘,
job_type => ‘EXECUTABLE‘,
job_action => ‘/loaddir/start_my_load.sh‘,
start_date => SYSTIMESTAMP,
event_condition => ‘tab.user_data.object_owner =
‘‘HR‘‘ and tab.user_data.object_name = ‘‘DATA.TXT‘‘
and tab.user_data.event_type = ‘‘FILE_ARRIVAL‘‘
and tab.user_data.event_timestamp < 9 ‘,
queue_spec => ‘HR.LOAD_JOB_EVENT_Q‘);
END;
Event-Based Scheduling
Event types:
• User-generated or application-generated events
• Scheduler-generated events
Events raised by Scheduler jobs:
基于事件的调度
事件类型:
•用户生成或应用程序生成的事件
•调度程序生成的事件
计划程序作业引发的事件:
Example of raising an event:
DBMS_SCHEDULER.SET_ATTRIBUTE(‘hr.do_backup‘,
‘raise_events‘, DBMS_SCHEDULER.JOB_FAILED);
Creating Complex Schedules 创建复杂计划
Quiz
Select the statements that are true about persistent lightweight jobs:
a. Persistent lightweight jobs have a small footprint on disk for the job metadata and also for storing runtime data.
b. Use persistent lightweight jobs for maximum flexibility.
c. Persistent lightweight jobs are created from a job template.
d. Persistent lightweight jobs can be created in Enterprise Manager and via command line.
测验
选择对持久性轻量级作业正确的语句:
a、 对于作业元数据和存储运行时数据,持久性轻量级作业在磁盘上占用的空间很小。
b、 使用持久的轻量级作业以获得最大的灵活性。
c、 持久的轻量级作业是从作业模板创建的。
d、 持久的轻量级作业可以在enterprisemanager中通过命令行创建。
Using Email Notification
• Email notifications for change of job state
• Triggered by job state events
• Multiple notifications, multiple recipients
• *_SCHEDULER_NOTIFICATIONS views
使用电子邮件通知
•工作状态变更的电子邮件通知
•由作业状态事件触发
•多个通知、多个收件人
•**计划程序通知视图
Using Scheduler Email Notification:
1. Specify the address of the SMTP server you will use to send email messages:
DBMS_SCHEDULER.SET_SCHEDULER_ATTRIBUTE
(‘email_server‘,‘host[:port]‘);
2. Optionally, set a default sender email address:
DBMS_SCHEDULER.SET_SCHEDULER_ATTRIBUTE
(‘email_sender‘,‘valid email address‘);
3. Add email notifications for a specified job. (continued)
使用计划程序电子邮件通知:
1指定将用于发送电子邮件的SMTP服务器的地址:
2(可选)设置默认发件人电子邮件地址:
3为指定作业添加电子邮件通知。(续)
Adding and Removing Email Notifications 添加和删除电子邮件通知
DBMS_SCHEDULER.ADD_JOB_EMAIL_NOTIFICATION (
job_name IN VARCHAR2,
recipients IN VARCHAR2,
sender IN VARCHAR2 DEFAULT NULL,
subject IN VARCHAR2
DEFAULT dbms_scheduler.default_notification_subject,
body IN VARCHAR2
DEFAULT dbms_scheduler.default_notification_body,
events IN VARCHAR2
DEFAULT ‘JOB_FAILED,JOB_BROKEN,JOB_SCH_LIM_REACHED,
JOB_CHAIN_STALLED,JOB_OVER_MAX_DUR‘,
filter_condition IN VARCHAR2 DEFAULT NULL);
DBMS_SCHEDULER.REMOVE_JOB_EMAIL_NOTIFICATION (
job_name IN VARCHAR2,
recipients IN VARCHAR2 DEFAULT NULL,
events IN VARCHAR2 DEFAULT NULL);
Creating Job Chains
1. Create a chain object.
2. Define chain steps.
3. Define chain rules.
4. Starting the chain:
– Enable the chain.
– Create a job that points to the chain.
创建作业链
1创建链对象。
2定义链步骤。
3定义链规则。
4启动链条:
–启用链条。
–创建指向链条的作业
Example of a Chain 链条示例
Dependency scheduling 依赖关系调度
Using Advanced Scheduler Features 使用高级计划程序功能
Job Classes
• Assign the same set of attribute values to member jobs
• Are created by the CREATE_JOB_CLASS procedure
• Specify jobs in a job class (with the SET_ATTRIBUTE procedure )
• Belong to the SYS schema
• Set resource allocation for member jobs
• Set the service attribute to a desired database service name
• Group jobs for prioritization
工作类别
•为成员作业分配相同的属性值集
•由CREATE_JOB_CLASS过程创建
•指定作业类中的作业(使用SET_ATTRIBUTE过程)
•属于系统架构
•为成员作业设置资源分配
•将服务属性设置为所需的数据库服务名称
•分组作业以确定优先级
Windows
Scheduler windows:
• Can start jobs or change resource allocation among jobs for various time periods
• One active at a time
• Created with the CREATE_WINDOW procedure
窗户
计划程序窗口:
•可以在不同的时间段内启动作业或更改作业之间的资源分配
•一次一个活动
•使用CREATE_WINDOW过程创建
Prioritizing Jobs Within a Window
Prioritizing jobs:
• At the class level (via resource plans)
• At the job level (with the job priority attribute)
• Not guaranteed for jobs in different job classes
在窗口内排列作业的优先级
工作优先级:
•在班级层面(通过资源计划)
•工作优先级(工作级别)
•不保证不同工作类别的工作
Creating a Job Array
1. Declare variables of types sys.job and sys.job_array:
DECLARE
newjob sys.job;
newjobarr sys.job_array;
2. Initialize the job array:
BEGIN
newjobarr := SYS.JOB_ARRAY();
3. Size the job array to hold the number of jobs needed:
newjobarr.EXTEND(100);
创建作业数组
1声明类型的变量系统作业以及sys.job_数组:
2初始化作业数组:
3调整作业数组的大小以容纳所需的作业数:
4. Place jobs in the job array:
FOR i IN 1..100 LOOP
newjob := SYS.JOB(job_name => ‘LWTJK‘||to_char(i),
job_style => ‘LIGHTWEIGHT‘,
job_template => ‘MY_PROG‘,
enabled => TRUE );
newjobarr(i) := newjob;
END LOOP;
5. Submit the job array as one transaction:
DBMS_SCHEDULER.CREATE_JOBS(newjobarr,
‘TRANSACTIONAL‘);
4将作业放入作业数组:
5将作业数组作为一个事务提交:
Quiz
Select the statements that are true about the advanced
Scheduler features and functionality:
a. Lightweight jobs can be created with a job array.
b. Prioritizing jobs at the class level (via resource plans) and at the job level (with the job priority attribute) are mutually exclusive.
c. Scheduler windows work with job classes to control resource allocation.
d. Job chains are used to implement “dependency scheduling.”
测验
选择关于高级
调度程序特性和功能:
a、 可以使用作业数组创建轻量级作业。
b、 在类级别(通过资源计划)和作业级别(使用job priority属性)对作业进行优先级排序是互斥的。
c、 调度程序窗口使用作业类来控制资源分配。
d、 作业链用于实现“依赖调度”
Creating a File Watcher and an Event-Based Job
Perform the following tasks:
1. Create a Scheduler credential object and grant EXECUTE.
2. Create a file watcher and grant EXECUTE.
3. Create a Scheduler program object with a metadata argument that references the event message.
4. Create an event-based job that references the file watcher.
(Optionally, enable the job to run for each instance of the file arrival event.)
5. Enable the file watcher, the program, and the job.
创建文件监视程序和基于事件的作业
执行以下任务:
1创建调度程序凭据对象并授予执行权限。
2创建一个文件监视程序并授予EXECUTE。
三。使用引用事件消息的元数据参数创建调度程序对象。
4创建引用文件监视程序的基于事件的作业。
(可选地,为文件到达事件的每个实例启用作业运行。)
5启用文件监视程序、程序和作业。
Enabling File Arrival Events from Remote Systems
Perform the following tasks to enable the raising of file arrival events at remote systems:
1. Set up the database to run remote external jobs.
2. Install, configure, register, and start the Scheduler agent on the first remote system.
3. Repeat step 2 for each additional remote system.
从远程系统启用文件到达事件
执行以下任务以启用在远程系统上引发文件到达事件:
1设置数据库以运行远程外部作业。
2在第一个远程系统上安装、配置、登记和启动调度器代理。
3对每个附加的远程系统重复步骤2
Scheduling Remote Database Jobs
• Create a job that runs stored procedures and anonymous PL/SQL blocks on another database instance on the same host or a remote host.
• The target database can be any release of Oracle Database.
• DBMS_SCHEDULER.CREATE_DATABASE_DESTINATION and DBMS_SCHEDULER.CREATE_CREDENTIAL can be used for remote database jobs.
• Jobs with job types of PLSQL_BLOCK and STORED_PROCEDURE can be the subject of SET_ATTRIBUTE calls for the DESTINATION and CREDENTIAL attributes.
计划远程数据库作业
•创建在同一主机或远程主机上的另一个数据库实例上运行存储过程和匿名PL/SQL块的作业。
•目标数据库可以是Oracle数据库的任何版本。
•数据库管理系统_SCHEDULER.CREATE_DATABASE_目的地和数据库管理系统_SCHEDULER.CREATE_凭据可用于远程数据库作业。
•作业类型为PLSQL_BLOCK和存储的_过程的作业可以作为目的地和凭证属性的SET_ATTRIBUTE调用的主题。
Creating Remote Database Jobs
Perform the following tasks to create a remote job:
1. Set up the originating database for remote jobs.
2. Create the job by using DBMS_SCHEDULER.CREATE_JOB.
3. Create a credential by using DBMS_SCHEDULER.CREATE_CREDENTIAL.
4. Set the job CREDENTIAL_NAME attribute by using DBMS_SCHEDULER.SET_ATTRIBUTE.
5. Set the job DESTINATION attribute by using DBMS_SCHEDULER.SET ATTRIBUTE.
6. Enable the job by using DBMS_SCHEDULER.ENABLE.
创建远程数据库作业
执行以下任务以创建远程作业:
1为远程作业设置原始数据库。
2使用DBMS创建作业_SCHEDULER.CREATE_作业.
3使用DBMS创建凭据_SCHEDULER.CREATE_凭据.
4使用DBMS设置job CREDENTIAL_NAME属性_SCHEDULER.SET_属性.
5使用DBMS设置作业目的地属性_调度程序.SET属性。
6使用DBMS启用作业_调度程序.ENABLE.
Scheduling Multiple Destination Jobs
• This enables you to specify several targets on which your jobs should execute.
• It provides the ability to monitor and control the jobs from the database on which they were created.
• While running, a multiple-destination job is viewed as a collection of jobs, which are near-identical copies of each other.
• All jobs will execute based on the time zone that is specified in the start date of the job or will use the time zone of the source database.
调度多个目标作业
•这使您能够指定要执行作业的多个目标。
•它能够从创建作业的数据库中监控作业。
•运行时,多目标作业被视为作业的集合,这些作业彼此几乎完全相同。
•所有作业将根据作业开始日期中指定的时区执行,或将使用源数据库的时区。
Viewing Scheduler Meta Data
Scheduler management views, displaying:
• *_SCHEDULER_JOBS: All jobs, enabled and disabled
• *_SCHEDULER_SCHEDULES: All schedules
• *_SCHEDULER_PROGRAMS: All programs
• *_SCHEDULER_RUNNING_JOBS: Active job states
• *_SCHEDULER_JOB_LOG: All job state changes
• *_SCHEDULER_JOB_RUN_DETAILS: All completed job runs
SELECT job_name, status, error#, run_duration
FROM user_scheduler_job_run_details;
JOB_NAME STATUS ERROR# RUN_DURATION
---------------- ------ ------ ------------
GATHER_STATS_JOB SUCCESS 0 +000 00:08:20
PART_EXCHANGE_JOB FAILURE 6576 +000 00:00:00
查看调度程序元数据
调度程序管理视图,显示:
•*\u SCHEDULER_作业:所有作业,启用和禁用
•*\u调度器_时间表:所有时间表
•*\u计划程序:所有程序
•*\u调度程序运行作业:活动作业状态
•**调度程序作业日志:所有作业状态更改
•*\u调度器_JOB_RUN_详细信息:所有已完成的作业运行
Quiz
Select the statements that are true about the Oracle Scheduler.
a. Creating remote database jobs is a manual task requiring the use of OS-specific commands.
b. A Scheduler credential is an object with which to authenticate with the host operating system for file access.
c. You can specify several targets on which your jobs should execute and monitor them from the database on which they were created.
测验
选择关于Oracle计划程序的正确语句。
a、 创建远程数据库作业是一项手动任务,需要使用特定于操作系统的命令。
b、 调度程序凭据是一个对象,用于向主机操作系统验证文件访问。
c、 您可以指定多个作业应在其上执行的目标,并从创建作业的数据库中监视这些目标。
Summary
In this lesson, you should have learned how to:
• Simplify management tasks by using the Scheduler
• Create a job, program, and schedule
• Monitor job execution
• Use a time-based or event-based schedule for executing Scheduler jobs
• Describe the use of windows, window groups, job classes, and consumer groups
• Use email notification
• Use job chains to perform a series of related tasks
• Describe Scheduler jobs on remote systems
• Use advanced Scheduler features to prioritize jobs
摘要
在本课中,您应该学习如何:
•使用调度程序简化管理任务
•创建工作、计划和时间表
•监控作业执行
•使用基于时间或基于事件的时间表来执行
计划程序作业
•描述窗口、窗口组、作业类的使用,
以及消费者群体
•使用电子邮件通知
•使用工作链执行一系列相关任务
•描述远程系统上的调度程序作业
•使用高级调度器功能对作业进行优先级排序
Practice: Overview
This practice covers the following topics:
• Creating a job that runs a program outside the database
• Creating a program and a schedule
• Creating a job that uses a program and a schedule
• Creating a lightweight job
• Monitoring job runs
实践:概述
本实践包括以下主题:
•创建在数据库外运行程序的作业
•制定计划和时间表
•创建使用计划和时间表的工作
•创造轻量级工作
•监控作业运行
oracle 03-20 使用Oracle调度程序自动化任务
标签:nat ice lin let continue values create load data 电子
原文地址:https://www.cnblogs.com/cloud7777/p/13244770.html