?? ch15.htm
字號(hào):
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE>Teach Yourself Oracle 8 In 21 Days -- Ch 15 -- Managing Job Queues and Using Oracle Auditing</TITLE>
</HEAD>
<BODY TEXT="#000000" BGCOLOR="#FFFFFF">
<CENTER>
<H1><IMG SRC="../buttonart/sams.gif" WIDTH="171" HEIGHT="66" ALIGN="BOTTOM" BORDER="0"><BR>
<FONT COLOR="#000077">Teach Yourself Oracle 8 In 21 Days</FONT></H1>
</CENTER>
<CENTER>
<P><A HREF="../wk3/wk3.htm"><IMG SRC="../buttonart/previous.gif" WIDTH="128" HEIGHT="28"
ALIGN="BOTTOM" ALT="Previous chapter" BORDER="0"></A><A HREF="../ch16/ch16.htm"><IMG
SRC="../buttonart/next.gif" WIDTH="128" HEIGHT="28" ALIGN="BOTTOM" ALT="Next chapter"
BORDER="0"></A><A HREF="../index.htm"><IMG SRC="../buttonart/contents.gif" WIDTH="128"
HEIGHT="28" ALIGN="BOTTOM" ALT="Contents" BORDER="0"></A>
<HR>
</CENTER>
<CENTER>
<H1><FONT COLOR="#000077">- Day 15 -<BR>
Managing Job Queues and Using Oracle Auditing</FONT></H1>
</CENTER>
<P>Today you will learn about managing job queues and the Oracle auditing facility.
Job queues are used to schedule jobs during off-peak hours or to schedule certain
tasks on a recurring basis. The Oracle job queue facility allows you to schedule
single or recurring tasks in an easy and reliable manner.</P>
<P>The Oracle auditing facility allows the administrator to monitor or audit the
system usage. Auditing is important if one or more incident has occurred to make
you suspicious of the activity of one or more users. Through auditing, a record is
made of the suspicious activity and can be used to track down the party at fault.
Think of auditing as a way of logging activity in the system.</P>
<P>Oracle job queues are used to divert the execution of an operation to a later
time. This allows you to schedule jobs.
<H2><FONT COLOR="#000077"><B>Managing Job Queues</B></FONT></H2>
<P><FONT COLOR="#000077"><B>New Term:</B></FONT><B> </B>A <I>job queue</I> is a method
whereby you can schedule a PL/SQL task to run at some time in the future, or even
to run periodically. The job-scheduling task can be done either graphically through
the Enterprise Manager or via the Oracle job-scheduling commands. As always, you
will learn about both methods here.</P>
<P>Using the Oracle job-queuing facility, you can easily schedule jobs to be run
at various times or on a regular schedule. Some examples of where this might be useful
include
<UL>
<LI>Regularly scheduled jobs, such as end-of-day accounting--A job that must run
every weekday can be scheduled to run unattended.
<P>
<LI>Large jobs that need to be run during off-peak hours--If you schedule them, you
need not be present at 3:00 a.m.
<P>
<LI>A large number of jobs that must be run sequentially--In this case, the jobs
might be so large that in order to reduce CPU usage, only one is run at a time.
</UL>
<BLOCKQUOTE>
<P>
<HR>
<FONT COLOR="#000077"><B>NOTE:</B></FONT><B> </B>An advantage of scheduling jobs
is that you need not be present when the job runs. A disadvantage is that if the
job fails during its operation, nobody is around to restart it. Therefore, you should
thoroughly test your job before queuing it.
<HR>
</BLOCKQUOTE>
<P>Let's look at how to schedule jobs using both the Enterprise Manager and the stored
procedures in the <TT>DBMS_JOB</TT> package.
<H3><FONT COLOR="#000077"><B>Scheduling Jobs Using the Enterprise Manager</B></FONT></H3>
<P>As you recall from Day 5, "Managing the Oracle RDBMS," the Enterprise
Manager has a pane called the Job pane. Within this pane you can manage jobs that
are running on this or other systems managed by this Enterprise Manager. By default,
the Job pane is located in the lower-left corner of the Enterprise Manager, as shown
in Figure 15.1.</P>
<P>Because this lesson is concerned only with the job-queuing functions of the Enterprise
Manager, I closed the other Enterprise Manager panes for the remaining figures in
today's lesson by deselecting them in the View drop-down menu.</P>
<P>To create a job using the Enterprise Manager, select the Create option by pulling
down the Job menu. This will invoke the Create Job dialog box, as shown in Figure
15.2. It is from this dialog that you create an Oracle job, as you will see in this
section.</P>
<P><A NAME="01"></A><A HREF="01.htm"><B>Figure 15.1.</B></A></P>
<P><I>The Oracle Enterprise Manager.</I></P>
<P><A NAME="02"></A><A HREF="02.htm"><B>Figure 15.2.</B></A></P>
<P><I>The Create Job dialog box.</I></P>
<P>Say you're the president of a dog club that keeps track of a large number of dogs
and their owners. Each week, an export image of this database is sent out to various
other dog clubs. Therefore, you want to create a job that, on a weekly basis, will
export the <TT>Dogs</TT> database. The first task is to invoke the Create Job dialog,
as you saw in the previous figure. This dialog has four different tabs that invoke
different screens, each of which has its own function. These tabs are
<UL>
<LI>General
<P>
<LI>Tasks
<P>
<LI>Parameters
<P>
<LI>Schedule
</UL>
<P>These screens are very flexible and easy to use.
<H4><FONT COLOR="#000077"><B>The General Screen</B></FONT></H4>
<P>Use the General screen to uniquely define the job. Type the name of the job and
provide a description of it as well as defining the database, node, or listener that
the job will act on. The General screen, filled in for this example, is shown in
Figure 15.3.</P>
<P><A NAME="03"></A><A HREF="03.htm"><B>Figure 15.3.</B></A></P>
<P><I>Use the General screen to define the job.</I></P>
<P>
<H4><FONT COLOR="#000077"><B>The Tasks Screen</B></FONT></H4>
<P>You use the Tasks screen to define the task that the job will perform. There are
a number of predefined tasks, or you can define your own, as shown in Figure 15.4.</P>
<P><A NAME="04"></A><A HREF="04.htm"><B>Figure 15.4.</B></A></P>
<P><I>The Tasks screen is where you define what the job will do.</I></P>
<P>Possible choices include the following administrative tasks:
<UL>
<LI>Backup Tablespace
<P>
<LI>Export
<P>
<LI>Import
<P>
<LI>Load
<P>
<LI>Run DBA Script
<P>
<LI>Run SQL*Plus
<P>
<LI>Shutdown Database
<P>
<LI>Startup Database
</UL>
<P>There are also a number of predefined, non-database administrative tasks, such
as
<UL>
<LI>Broadcast Message
<P>
<LI>Run OS Command
<P>
<LI>Others
</UL>
<P>The appearance of the Parameters screen will vary depending on what type of task
is selected in the Tasks screen.
<H4><FONT COLOR="#000077"><B>The Parameters Screen</B></FONT></H4>
<P>The Parameters screen allows you to further define the parameters for the task
that was selected. Because I selected an export task for this example, this screen
allows me to define further export parameters, as shown in Figure 15.5.</P>
<P><A NAME="05"></A><A HREF="05.htm"><B>Figure 15.5.</B></A></P>
<P><I>You further define the task in the Parameters screen.</I></P>
<P>Here you can select the database to be exported as well as the export filename.
You can also choose to select export objects or advanced export options. The advanced
export options screen is shown in Figure 15.6.</P>
<P><A NAME="06"></A><A HREF="06.htm"><B>Figure 15.6.</B></A></P>
<P><I>You can choose advanced options for exporting.</I></P>
<P>This gives you a wide range of options for the export operation. Similarly, other
tasks have their own parameters you can set.
<H4><FONT COLOR="#000077"><B>The Schedule Screen</B></FONT></H4>
<P>The Schedule screen allows you to define how the job is to be run, as shown in
Figure 15.7.</P>
<P><A NAME="07"></A><A HREF="07.htm"><B>Figure 15.7.</B></A></P>
<P><I>You define the timing of the job in the Schedule screen.</I></P>
<P>Scheduling can be done at various rates, including
<UL>
<LI>Immediately
<P>
<LI>Once
<P>
<LI>Interval (for example, every <I>x</I> days)
<P>
<LI>On Day of Week
<P>
<LI>On Day of Month
</UL>
<P>Scheduling is very flexible and easy to set up and run. At this point, all that
is necessary to schedule the job is to click the Submit button. You will see the
scheduled job listed on the Active Jobs screen, as shown in Figure 15.8.</P>
<P><A NAME="08"></A><A HREF="08.htm"><B>Figure 15.8.</B></A></P>
<P><I>The Active Jobs screen shows the status of active jobs.</I></P>
<BLOCKQUOTE>
<P>
<HR>
<BR>
<FONT COLOR="#000077"><B>NOTE:</B></FONT><B> </B>For job queuing to work properly,
the user preferences must be set up correctly. The user for the database must be
a valid database user with the system permissions necessary to perform the task required.
The user for the node must be a valid NT user with "login as batch job"
permission. This user must also have a password. Accounts with no passwords cannot
be used. The preferences setup screen for the Enterprise Manager is shown in Figure
15.9. For my setup I created a batch account and added the proper privileges.
<HR>
</BLOCKQUOTE>
<P>It is important for the Enterprise Manager to be properly configured for it to
be able to submit jobs. After you have submitted the job, you can also modify it
from the Enterprise Manager.</P>
<P><A NAME="09"></A><A HREF="09.htm"><B>Figure 15.9.</B></A></P>
<P><I>Setting Enterprise Manager preferences.</I></P>
<P>
<H4><FONT COLOR="#000077"><B>Administering Jobs</B></FONT></H4>
<P>After the job has been scheduled, you can administer it from the Enterprise Manager.
You can't do much here except monitor the status and delete the job; these tasks
can be accomplished from the Jobs menu. Selecting the Show Details option shows you
how the job was submitted. Selecting the Remove Job option deletes the selected job.
<H3><FONT COLOR="#000077"><B>Scheduling Jobs Using the Command-Line Facilities</B></FONT></H3>
<P>It is possible to manage the Oracle job queues through the Server Manager or SQL*Plus
rather than use the Enterprise Manager. This is very useful because all users can
use Oracle queuing, and typically only administrators have access to the Enterprise
Manager console.</P>
<P>A job is administered by calling the <TT>DBMS_JOB</TT> package just as you would
call any other package. The stored procedures that make up this package are the following:
<UL>
<LI><TT>BROKEN</TT>--Disables job execution without removing the job.
<P>
<LI><TT>CHANGE</TT>--Can be used to alter the job description, when it will run,
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -