Vous êtes sur la page 1sur 5

ORAtips4On Database

Page 

October 2006 Volume II Issue 4

Survey of Oracle Recovery Options


®

By Steve Callan

Editor’s Note: Losing data is like to delete that information” is likely Statement errors, in the context
riding a roller-coaster, your stomach to be countered with a “Why were defined in the documentation, should
drops, you break out in a cold sweat, you looking at that in the first place” be minimized, if not eliminated,
and you take a new interest in reli- interrogative. Plenty of time for guilt during the development, quality
gion. ORAtips Associate Editor Steve and recrimination later, so for now, assurance review/testing, and user
Callan’s latest contribution won’t let’s focus on retrieving the deleted acceptance test phases of whichever
help you battle your amusement ride data. software development lifecycle meth-
fears, but he can definitely take some odology is being used. After release
of the fear out of losing data with his into production, statement errors
tips on recovery options and getting (bugs) may cause some data errors.
back to where you started. Validation, integrity, and anomalies
Oracle itself has are types of data-related errors that
can be difficult, if not impossible, to
Introduction built in mechanisms recover from. A series of bad state-
From an applications or Applica- ment errors (assuming there are
tions standpoint, this article about to recover process intermediate commits in a proce-
recovery options is an example of dure before an error is returned) may
where general knowledge is useful, but and instance require an extensive effort to effect
knowing the exact details isn’t neces- recovery.
sary because you have the resources failures, and human
to get those if needed. Unless you Process, instance, and media
are in a down-in-the-trenches data- intervention is errors will be immediately noticed
base administrator position, know- by administrators, either system or
ing the exact step-by-step details of required for database. These types of errors are
how to recover a dropped table isn’t immediate attention getters because
essential. However, what is essential media failure. across the board, they all result in
from an Applications or managerial the database (or instance, depending
standpoint is knowing the recovery upon how precise you want to be in
operations at your disposal. It is also describing the problem) coming to
important to note that not all recov- Types Of Errors an immediate halt or shutdown. Ora-
ery operations may be available. As stated in Chapter 1 of Oracle cle itself has built in mechanisms to
Database Concepts, Oracle identi- recover process and instance failures,
ORAtipsJournal

Dropping a table isn’t likely (or fies errors as one of five types. These and human intervention is required
not even possible depending on the types are (and a brief description or for media failure.
application) in a Forms environment example):
as your interaction with the database Statement, process, instance, and
is primarily at the statement level. • User - Dropping a table media errors are less likely to occur
Statement level operations are those than user errors, and as mentioned,
associated with insert, update, and • Statement - Logical error in a there are other processes, safeguards,
delete, or in database terms, data procedure or mechanisms in place to perform
manipulation language (DML) oper- recovery. This leaves us with users as
ations. An example would be delet- • Process - Abnormal disconnec- the main source of error-generating
ing the salary record of an employee tion entities in an organization. How do
and then issuing a commit. If the users create errors? Errors are gener-
record you just deleted happens to be • Instance - Power failure ated via statements issued by the user.
that of your supervisor, you may be In this context, a statement is valid in
experiencing that unsettling “oops” • Media - Disk-related problems, that it was successfully applied and
feeling way down deep inside. Your generally requires media recov- there were no logic errors in terms
protestation of “I didn’t really mean ery of the statement’s syntax. What is

ORAtips.com ORAtips © 2006 Klee Associates, Inc.


ORAtips4On Database
Page 

October 2006 Volume II Issue 4

in error is what the statement per- The third structure consists of ARCHIVELOG vs. NOAR-
formed. database backups. Which backup CHIVELOG Mode
method or utility you use depends If your database is operating in
Before discussing what your recov- on your situation or environment. NOARCHIVELOG mode, you should
ery options are, a brief overview of If you can afford to lose data, your first of all understand why it is
what Oracle uses for recovery will options are limited, but the steps to acceptable to operate in this manner.
help frame the difference between generate a backup are easier. If you Changes to the database are recorded
what is immediately versus what is cannot afford to lose data, which in the redo logs, and if your system is
not immediately recoverable. is more likely than not, then you not archiving the redo logs, there is
(or more precisely, your DBA) have no copy of them once they are over-
Structures Used In Recovery more options, but the steps are more written. Let’s suppose your database
There are three mechanisms used involved. is shutdown at 2 AM every morning
by Oracle for recovery: redo logs, and that the relevant files are copied
undo records, and backups. These are A fourth structure listed in the off somewhere before the database is
the “proper” means of what is used documentation is the control file, but restarted. Known as a cold backup,
for backup and recovery. Importing its role for the purpose of this article your ability to recover is limited to
an export dump file is a fourth way of can be ignored. However, when talk- that point in time when the database
recovering a database (or table), but ing with your DBA during a recov- was backed up. All changes since that
to be pedagogical and consistent with ery operation, you should know point in time are lost. If you lose a
Oracle’s definition of what constitutes that control files are essential to the disk at 2 PM, you can only recover to
a backup, export/import is not con- operation of all databases and it is the cold backup taken at 2 AM. Can
sidered as a true backup strategy. extremely important to have more you afford to lose 12 hours worth of
than one copy of this file distributed changes?
Immediate changes to data are across multiple disks. Casually ask
stored in the redo logs and undo where the control files are located As a side note to should this be
records. These structures allow for for the production database, and if how your database is being backed
near instantaneous recovery (or the your DBA tells you they are all on the up, ask if the redo logs are also cop-
start of it, anyway). A recovery oper- same drive or partition, you could be ied during the cold backup. If so, ask
ation may take a significant amount in serious trouble. why this takes place since copying
of time if the original user opera- the redo logs in a cold backup is in
tion involved an extensive amount At this point in time, let’s discuss direct contravention of Oracle’s guid-
of DML. Each of these structures is how “point in time” applies in a ance.
time-limited in that, because they are recovery.
after all just datafiles, they can con- Another single point in time recov-
tain only so much information. Once ery option is offered via the export
a redo log is “filled up” to a certain utility. The “exp” utility can create a
point, it is archived off as an archived logical record or backup of your data-
ORAtipsJournal

redo log and stored elsewhere on the base (tables, schemas, or the entire
file system (or eventually written to database). Suppose a user drops a
tape). table. If that table were included
in the export dump file, then it can
Undo records, present since ver- Immediate changes be imported back into your data-
sion 9i, can ensure a specific amount base. You may encounter integrity
of time in the past to be readily to data are stored or constraint errors when importing
available, and may have more than directly into the owning schema, so it
the specified time. An undo reten- in the redo logs and may be necessary to import the table
tion period of 60 minutes results in into another schema (have the table
Oracle maintaining an undo file (or undo records. be owned by another user) and then
space) large enough to store or record work on getting the data back into
60 minutes worth of change. Because the original schema.
the space tends to grow and shrink,
you may have 70 minutes worth of What if you don’t need the entire
look-back recovery time, but no table, but just a single record? You
guarantee of that extra ten minutes. cannot import based on a query (but

ORAtips.com ORAtips © 2006 Klee Associates, Inc.


ORAtips4On Database
Page 

October 2006 Volume II Issue 4

you can export data filtered by a In ARCHIVELOG mode, the data- DBAs should have an “emergency
query), so you’ll still need the entire base is still using redo logs, but as procedures” guide for recovery oper-
table. How else can you retrieve the mentioned, once a redo log is filled ations. Although all of this infor-
data for a single record? up and cycled out of the rotation, it mation is available on the Internet,
is archived off to a separate location. from Oracle or otherwise, and in
Oracle’s LogMiner utility “enables The original redo log stays in the same numerous database administration
you to query redo log files through a place; it’s just that the file is copied books, you’re goal is to minimize the
SQL interface. All changes made to to one or more locations. While in research (and learn) time and maxi-
user data or to the database diction- archive mode, your backup options mize the “do” time.
ary are recorded in the Oracle redo now include the traditional hot back-
log files.” One of the stated potential up and RMAN (Recovery Manager). Flashback
uses is for “Detecting and when- One way to frame the difference here Flashback deserves two entries
ever possible, correcting user error,” is that of user versus server-based or because there are two types of flash-
where user error is defined as a user managed recovery. In other words, back available in Oracle 10g. Proba-
“deleting the wrong rows because of you can do the recovery work or let bly the more commonly known flash-
incorrect values in a WHERE clause, Oracle do it. Again, the point of this back has to do with flashback table
[and] updating rows with incorrect article is not to make you an expert or flashback database. The “other”
values.” [From the Oracle Database on syntax, but to point out what your flashback is flashback query. Flash-
Concepts guide.] options are in a recovery situation back query does not undo anything,
– options that your DBA should be but it does allow you to look back in
LogMiner is frequently overlooked experienced and knowledgeable in. time (again, up to a certain point or
as a means of data recovery. A user limit). If a user made an error, one
operating in a well-functioning/well- Speaking of DBAs, your on-call option would be to flashback query
operating database (meaning, you are DBA may be a new junior DBA. In the affected table or data and store
following best practices with respect a panic situation, it can help if oth- the results of that query in a work-
to backup and recovery) is not likely ers have some knowledge of what the ing table. Then, at a more convenient
to have to use LogMiner, but it is a possibilities are. Instead of guessing time, the original data can be fixed or
utility to keep tucked away in the or remembering possibilities, your restored. But, since we are likely to
back of your mind because of
“what-if” situations, such as
what if your database is not
flashback enabled or what if
your database version is 9i
and you don’t have a recycle
bin? If you have to resort to
LogMiner, it will help your
DBA if you can provide an
ORAtipsJournal

approximate time of when the


user error occurred.

So far, we’ve been limited to


a single point in time recovery,
which is better than nothing,
but one feature, which makes
Oracle so powerful, is its abil-
ity to provide an almost infi-
nite range of points in time,
that is, you can recover to
practically any point in time
of your choosing. To facilitate
this ability, your database will
need to be in ARCHIVELOG
mode.
Figure 1: Overview of Oracle Flashback Features

ORAtips.com ORAtips © 2006 Klee Associates, Inc.


ORAtips4On Database
Page 

October 2006 Volume II Issue 4

be more interested in a more imme- So far, the user error somewhat things down, but having a less than
diate recovery, let’s move on to the implicitly implied here is an erro- optimally performing database is
other type of flashback. neous drop table statement. Unless much better than having a database
there is a dropped version of the table corrupted due to data loss.
With a table or database operating with some rows of interest, flashback
in flashback mode, recovery is about table basically applies to an entire One rule to live by when it comes to
as simple as issuing one command. table, not just a few rows. That is recovery is to never put yourself in an
You can flashback a table or database why flashback query deserves special unrecoverable situation. A corollary
to a point in time without missing a mention as it can perform the look to that is to not do anything, which
beat. Figure 1 (from Chapter 17 in back in time to retrieve the original makes the situation worse. Timely
the Concepts guide) summarizes the record set. identification of an error goes a long
different flashback features found in way towards keeping the situation
Release 2 of Oracle 10g. Part of what enables flashback recoverable. Now that you’re armed
table to work is a recycle bin. When with a better understanding of recov-
As far as a user is concerned, bar- a user drops a table, it can go into ery operations, you stand a better
ring any special privileges, is DBA a recycle bin, and when flashback chance of recovering your manager’s
intervention required to use a flash- table is used, the user is retrieving lost data.
back feature? If you are in your own the dropped object from the bin. A
schema and drop a table you own, user can control his own recycle bin Steve Callan – Steve is an Oracle
can you flashback table to recover by setting a session parameter value. DBA and developer. His Oracle expe-
it, or do you need DBA interven- Further, a user can see the contents of rience includes several versions of the
tion? Fortunately, a user can recover his own bin by querying the USER_ RDBMS, Forms & Reports, and Appli-
objects owned by that user. Howev- RECYCLEBIN view. cation Server. In addition to working
er, you may want to clarify what is with Oracle, Steve also spends time
meant by user. There is a huge differ- From a managerial standpoint, on researching other database sys-
ence between “Scott” and a schema you may want to ensure that the tems such as SQL Server and DB2
owner/user name “application_mgr.” necessary parameters for this feature and would someday like to start his
The impact of a Scott-level type of are set by default in user sessions. In own software company. Steve may be
user dropping and recovering his other words, you want to make it dif- contacted at Steve.Callan@ERPtips.com.
own table is likely to be minimal, if ficult for users to truly and perma- ≈
significant at all. The main schema nently erase or alter data.
user performing the same step should
be done in coordination with a DBA Conclusion
(and what if Scott can log on as Oracle’s, and hence your, abil-
application_mgr?). ity to recover lost data has greatly
improved with the release of Oracle
10g. One of the problems with new
ORAtipsJournal

releases is that DBAs are usually so


busy with maintaining the status
quo that it is hard to assimilate the
You can flashback myriad of features found in a new
release. No doubt, there are compa-
a table or database nies still using rollback segments and
hot backups because things work and
to a point in time why fix what isn’t broken reasoning.
New features become old features,
without missing typically at the cost of making some
older feature obsolete (say goodbye
a beat. to rollback segments because they
are going, going, gone in the near
future). Backup and recovery skills,
individually or jointly, can easily be
argued as the key skill set needed by
a DBA. Poor performance can slow

ORAtips.com ORAtips © 2006 Klee Associates, Inc.


ORAtipsJournal
The information on our website and in our publications is the copyrighted work of Klee Associates, Inc. and is owned by Klee Associates, Inc. NO WARRANTY: This
Page 

October 2006 Volume II Issue 4

documentation is delivered as is, and Klee Associates, Inc. makes no warranty as to its accuracy or use. Any use of this documentation is at the risk of the user. Although
we make every good faith effort to ensure accuracy, this document may include technical or other inaccuracies or typographical errors. Klee Associates, Inc. reserves
the right to make changes without prior notice. NO AFFILIATION: Klee Associates, Inc. and this publication are not affiliated with or endorsed by Oracle Corporation.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Klee Associates, Inc. is a member of the Oracle Partner Network

This article was originally published by Klee Associates, Inc., publishers of JDEtips and SAPtips.
For training, consulting, and articles on JD Edwards or SAP, please visit our websites:
www.JDEtips.com and www.SAPtips.com.
ORAtipsJournal

ORAtips.com ORAtips © 2006 Klee Associates, Inc.

Vous aimerez peut-être aussi