📄 ch16.htm
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE>Teach Yourself Oracle 8 In 21 Days -- Ch 16 -- Understanding Effective Backup Techniques</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="../ch15/ch15.htm"><IMG SRC="../buttonart/previous.gif" WIDTH="128" HEIGHT="28"
ALIGN="BOTTOM" ALT="Previous chapter" BORDER="0"></A><A HREF="../ch17/ch17.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 16 -<BR>
Understanding Effective Backup Techniques</FONT></H1>
</CENTER>
<P>In the next three days, you will learn about some of my favorite topics: backup
and recovery and ways to engineer maximum uptime. This is one of my favorites because
of the various ways you can design backup and recovery strategies and because of
the enormous importance of this task.
<H2><FONT COLOR="#000077"><B>Review of Oracle Procedures</B></FONT></H2>
<P>Before you learn how backups work, I would like to review a little bit about how
Oracle works. This section does not cover all the Oracle functions and processes,
just those pertinent to the integrity of the data in the database.</P>
<P>If none of the data in the database ever changed, there would never be a need
to back up that data more than once. Because the data never changed, any backup that
occurred in the past could be used to restore the data to a useful state. Well, this
is not the case in most systems, although by using read-only tablespaces it can be
achieved.</P>
<P>Because most systems' data changes, the database is now a constantly changing
system. It is of utmost importance that this data be protected. If a system failure
should occur, it is unreasonable to think that all changes that are in progress should
be recovered, but it is a reasonable expectation that all committed transactions
be recovered.</P>
<P><FONT COLOR="#000077"><B>New Term:</B></FONT><B> </B>In fact, if you have a good
backup-and-recovery plan, no committed transactions should ever be lost. In recovering
the database from a failure, you have to determine which of the two types of failure
occurred so you know which recovery mechanism to use. The two types of recovery are
<I>instance recovery</I> and <I>data recovery</I>.
<H3><FONT COLOR="#000077"><B>Instance Recovery</B></FONT></H3>
<P><FONT COLOR="#000077"><B>New Term:</B></FONT><B> </B>An <I>instance failure</I>
can occur due to a system failure, such as a power outage or a hardware or software
problem. When an instance failure occurs, the Oracle recovery process can completely
recover the database on instance startup. All committed transactions will be recovered
or rolled forward, and all noncommitted transactions will be rolled back.
<BLOCKQUOTE>
<P>
<HR>
<FONT COLOR="#000077"><B>NOTE:</B></FONT><B> </B>Instance recovery can be quite time
consuming. How much time instance recovery takes depends on the number of dirty buffers
in the SGA, and the number of dirty buffers depends on the amount of time since the
last checkpoint. The time it takes for instance recovery also depends on the recovery
parallelism. The recovery parallelism is the amount of parallelism used in the recovery
process; this is part of the Parallel Query option's Parallel Recovery feature.
<HR>
</BLOCKQUOTE>
<P>As you will see later today and tomorrow, instance recovery can and should be
tuned to provide for the shortest possible recovery time.
<BLOCKQUOTE>
<P>
<HR>
<FONT COLOR="#000077"><B>TIP:</B></FONT><B> </B>By tuning the checkpoint interval
and recovery parallelism, you can shorten the recovery time.
<HR>
</BLOCKQUOTE>
<H3><FONT COLOR="#000077"><B>Data Recovery</B></FONT></H3>
<P>Data recovery is necessary when media failure has occurred--for example, when
a datafile is damaged. If a datafile is damaged, you must first restore the damaged
file from backup before recovery can occur. The Oracle recovery process will then
apply archive log files and redo log files to restore the damaged datafile to the
state that it was at prior to the failure. It may take as many as all the archive
log files created since the backup to recover the restored datafile. This process
can be quite time consuming.
<BLOCKQUOTE>
<P>
<HR>
<FONT COLOR="#000077"><B>TIP:</B></FONT><B> </B>By scheduling frequent backups, you
can shorten the restoration and recovery time.
<HR>
</BLOCKQUOTE>
<P>As you will see today and tomorrow, the goal is to have the shortest possible
downtime in the event of a catastrophic system failure.
<H3><FONT COLOR="#000077"><B>Log File Recovery</B></FONT></H3>
<P>You cannot do anything to recover a lost log file. If a log file is damaged and
the system is still functional, you can drop the log file, re-create it, and immediately
perform a full backup. (The backup is necessary because you will not be able to use
the archive log files and redo log files for any recovery on this database.) This
is why I always recommend that log volumes be fault tolerant.
<H3><FONT COLOR="#000077"><B>How Transactions Work</B></FONT></H3>
<P>Remember, the term <I>transaction</I> is used to describe a logical group of work.
This group of work can consist of one or many SQL statements and must end with a
commit or a rollback. This definition assumes a client/server application, so SQL*Net
is necessary. To review the steps required to execute a transaction, review Day 2,
"Exploring the Oracle Architecture."</P>
<P>For today's lesson it is important to note that the transaction requires the redo
log entry to be written out before the transaction has been committed. If a failure
occurs before that entry has been written, the transaction will not be recovered.
<H4><FONT COLOR="#000077"><B>Logging and Archiving</B></FONT></H4>
<P>As mentioned on Day 2, the <I>redo log</I> records all changes made to the Oracle
database. The purpose of the redo log is to ensure that, in the event of the loss
of a datafile caused by some sort of system failure, the database can be recovered.
By restoring the datafiles back to a known good state from backups, the redo log
files (including the archive log files) can replay all the transactions to the restored
datafile, thus recovering the database to the point of failure.</P>
<P>When a redo log file is filled in normal operation, a log switch occurs and the
LGWR process starts writing to a different redo log file. When this switch occurs,
the ARCH process copies the filled redo log file to an archive log file. When this
archive is complete, the redo log file is marked as available. It is critical that
this archive log file be safely stored, because it might be needed for recovery.
<BLOCKQUOTE>
<P>
<HR>
<FONT COLOR="#000077"><B>NOTE:</B></FONT><B> </B>Remember that a transaction has
not been committed until the redo log file has been written. Slow I/Os to the redo
log files can slow down the entire system.
<HR>
</BLOCKQUOTE>
<H4><FONT COLOR="#000077">ARCHIVELOG<B> Mode</B></FONT></H4>
<P>The Oracle RDBMS is not required to run in <TT>ARCHIVELOG</TT> mode, so the archiving
mechanism can be disabled. However, if you do not run in <TT>ARCHIVELOG</TT> mode,
it is impossible to recover any transactions that are not in the current redo log
files.
<BLOCKQUOTE>
<P>
<HR>
<FONT COLOR="#000077"><B>WARNING:</B></FONT><B> </B>If you do not run in <TT>ARCHIVELOG</TT>
mode, you will most likely lose valuable data in the event that a datafile is lost.
I recommend that all production systems be run in <TT>ARCHIVELOG</TT> mode. You can
run test systems without archiving.
<HR>
</BLOCKQUOTE>
<P>If your data is important to you, you should always run your production systems
in <TT>ARCHIVELOG</TT> mode.</P>
<P><FONT COLOR="#000077"><B>Enabling Archiving</B></FONT></P>
<P>Archiving is enabled by running the <TT>ALTER DATABASE</TT> command with the parameter
<TT>ARCHIVELOG</TT>. To enable archiving, use</P>
<PRE><FONT COLOR="#0066FF">ALTER DATABASE ARCHIVELOG;
</FONT></PRE>
<P><FONT COLOR="#000077"><B>Disabling Archiving</B></FONT></P>
<P>Archiving is disabled by running the <TT>ALTER DATABASE</TT> command with the
parameter <TT>NOARCHIVELOG</TT>. To disable archiving, use</P>
<PRE><FONT COLOR="#0066FF">ALTER DATABASE NOARCHIVELOG;
</FONT></PRE>
<P>If you are in <TT>ARCHIVELOG</TT> mode and want to disable it for a particular
startup, you can set the Oracle parameter <TT>LOG_ARCHIVE_START=FALSE</TT>.</P>
<P><FONT COLOR="#000077"><B>Setting the Archiving Destination</B></FONT></P>
<P>Use the Oracle parameter <TT>LOG_ARCHIVE_DEST</TT> to set the destination for
Oracle archiving. Archive log files will be created in this directory with a different
filename for each archive log file. This filename is defined by the Oracle parameter
<TT>LOG_ARCHIVE_FORMAT</TT>. Both of these parameters are described in the Oracle
documentation.
<H2><FONT COLOR="#000077"><B>How to Configure Your System</B></FONT></H2>
<P>In configuring your hardware system, it is important to plan for protecting your
data. By carefully configuring your system for data integrity, you can optimally
configure for both performance and protection. In this section, I give you a few
tips on how to configure your system using RAID disk subsystems.
<H3><FONT COLOR="#000077"><B>Review of Disk Arrays</B></FONT></H3>
<P><FONT COLOR="#000077"><B>New Term:</B></FONT><B> </B>A <I>disk array</I> is collection
of disk drives configured to act as one larger disk drive. Both hardware and software
disk arrays are available today. Hardware disk arrays consist of a disk array controller
and a set of disk drives (typically SCSI). Software disk arrays are made up of a
software layer that lies between the file system and the device driver layers.</P>
<P>Disk arrays usually support disk striping, disk mirroring, disk parity, and so
on. Hardware disk arrays also support other features such as hot-swappable disks.
An array with fault tolerance and hot-swappable disks allows you to replace a defective
disk while the system is active. Depending on the manufacturer and model, the disk
array controller can support several different types of RAID fault tolerance.</P>
<P>Disk arrays offer many benefits to the system administrator and the end users:
<UL>
<LI>Ease of management. A disk array can offer tens of gigabytes of disk space that
appear to the administrator as one large disk. This arrangement simplifies some of
the management tasks involved with managing large numbers of disks.
<P>
<LI>I/O balancing. Because a disk array is made up of many individual disks with
striped data, random I/O is automatically distributed among the disks.
<P>
<LI>Fault tolerance. Disk arrays provide a wide range of RAID options with a wide
variety of performance and economic choices.
</UL>
<P><FONT COLOR="#000077"><B>New Term:</B></FONT><B> </B>A disk array is a set of
disk drives that make up a larger logical disk, which is sometimes called a <I>logical
volume</I>. The logical volume is made up of identical-sized pieces of the individual
drives, called <I>stripes</I>. The data is said to be <I>striped</I> across the logical
volume because the logical drive has pieces of all the individual drives striped
within it, as shown in Figure 16.1. If you look at the logical volume, the physical
drives seem to make stripes.</P>
<P>The stripes are all the same size and in sequence (that is, disk 1 holds the first
stripe, disk 2 the second, and so on). The size of the stripe varies based on the
manufacturer and model of the disk array controller. The stripe size also varies
in a software array. The size of the stripe is called the <I>striping factor</I>
and is given in number of blocks. A typical striping factor is 32. Given a size of
512 bytes per block, a striping factor of 32 makes the disk stripe 16KB in size.</P>
<P><A NAME="01"></A><A HREF="01.htm"><B>Figure 16.1.</B></A></P>
<P><I>Disk stripes on a logical volume.</I></P>
<P>As far as the user and the RDBMS are concerned, there is only one large disk drive.
It is up to the OS and the hardware to manage the individual disks within the array.
<H4><FONT COLOR="#000077"><B>RAID Levels</B></FONT></H4>
<P>The configuration of disks in an array is sometimes called a <I>Redundant Array
of Inexpensive Disks</I> (RAID) configuration. RAID technology allows systems to
maintain very large amounts of storage at relatively low cost. The inexpensive SCSI
drives that make up the array have not only improved in performance and quality over
the years, but they have significantly dropped in price.</P>
<P><FONT COLOR="#000077"><B>New Term:</B></FONT><B> </B>The term <I>RAID</I> is also
used to describe the type of striping you use. Striping methods vary in both performance
and space overhead. The type of configuration used in your system depends on your
individual needs. Different configurations of striping and fault-tolerant striping
are identified by RAID levels.</P>
<P>The various RAID levels are determined by a body of computer vendors called the
RAID Advisory Board. This standards body determines the basics of the various RAID
levels but does not force any particular implementation, thus allowing vendors to
differentiate themselves. Following are brief descriptions of the various RAID levels.</P>
<P><FONT COLOR="#000077"><B>RAID-0</B></FONT></P>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -