Recovery Principles Recovery principles are the same, regardless of whether you are in a Unix or Windows NT environment.

The following are general guidelines for recovery using a cold backup, hot backup, and export. Definitions

Control File—The control file contains records that describe and maintain information about the physical structure of a database. The control file is updated continuously during database use and must be available for writing whenever the database is open. If the control file is not accessible, the database will not open. System Change Number (SCN)—The system change number is a clock value for the database that describes a committed version of the database. The SCN functions as a sequence generator for a database and controls concurrency and redo record ordering. Think of the SCN as a timestamp that helps ensure transaction consistency. Checkpoint—A checkpoint is a data structure in the control file that defines a consistent point of the database across all threads of a redo log. Checkpoints are similar to SCNs and they also describe which threads exist at that SCN. Checkpoints are used by recovery to ensure that Oracle starts reading the log threads for the redo application at the correct point. For a parallel server, each checkpoint has its own redo information.

Media Recovery Commands To perform either a complete media recovery or incomplete media recovery, you need to be familiar with the following three media recovery commands.
• • • • • • •

• • • •

RECOVER DATABASE This command performs a media recovery on all the data files that require the application of redo. This can be used only when the database is mounted but not open. This command is generally used when the system data file is lost. RECOVER TABLESPACE tablespace_name This command performs a media recovery on all the data files in the tablespaces listed. The database must be mounted and open. The tablespace in question must be offline to perform the media recovery. To recover the tablespace, you need to mount the database first, put the data file that is in trouble offline, and then open the database and put the tablespace offline. Then give the recover tablespace tablespace_name command and put the tablespace online when the recovery is complete. RECOVER DATAFILE 'filename' This command performs a recovery on listed data files. The database can be open or closed. If the database is open, data file recovery can only recover offline files. To recover the data file in question, mount the database and put the troubled data file offline, open the database and issue the 'RECOVER DATAFILE 'FILE_NAME' command, and put the data file online. This command is generally used when a non-system data file is lost.

Performing Recovery, Where to Start? You are a new DBA and you get a call from the project manager saying that the users are not able to connect to the database. As a first step, try to establish a connection for yourself as a DBA as shown. If the connection succeeds, try to connect as a regular user and see if you receive any errors during connection,

If you do not see any errors. you are sure that the database is down. Copy all data files. check the alert log file for any errors. try to determine what kind of backups you have taken recently and see which one is most beneficial for recovering as much data as possible.because some errors that are seen by regular users do not show up when you connect as Internal or SYSDBA (such as Max sessions reached). error number. Recovery Using Cold Backup To restore a full database. Recovery When a Data File Is Lost To recover a database using c cold backup. If you see any errors. As a sixth step. you can be sure that you can recover all or most of the data. start up the database (sometimes it will report an error when you try to startup the database). inform the project manager that somebody has caused a problem in the database and try to find out what happened (a hard disk problem or perhaps somebody deleted the file). 2. 3. As a fifth step. Shutdown the database. do the following: 1. As a second step. Limit your time to this research based on time available. Start up the database. just restore all the files from the backup location to their original locations and open the database. If the database starts. .ora file. If it does not list any processes. As a third step. $ps –ef|grep –i ORCL This should list the processes that are running. $sqlplus user/pwd Now you determined that you are not able to connect to the database. This depends on the types of backups your site is employing to protect from database crashes. that is wonderful! If it doesn't start. control files. The alert log file is located under the directory defined by BACKGROUND_DUMP_DEST in the Init. follow the instructions in this chapter. This file lists any errors encountered by database. As a fourth step. and error message. the data changes since the time of last backup will be lost. You can find the original physical location in the trace file you generated as part of the backup. given your recovery scenario. Now you determined from the error that the database is not finding one of the data files. Verify the owner and permissions for the files (for Unix only). and redo log files from the backup location to the original location. try to see whether the processes are running by using the following command. You cannot recover the transactions that occurred between the last backup and the point of failure—that information is lost. If you have a hot backup mechanism in place. note the time of the error. it will generally complain about the error onscreen and also report the error in the alert log file. Check the alert log again for more information. If you have an export or cold backup mechanism in place.

we always try to perform a complete recovery unless the need is to recover the database only to a specific point in time for specific reasons. Where group 1 is the corrupted log group number. you simply recreate the control file knowing the structure of the database (from the trace of control file) and open the database with reset logs. you need to know the full structure of the database. Follow the steps explained in Chapter 10. The reset logs option resets the redo log sequence numbering and recreates any missing logfiles. such as those discussed in the next section. Suppose that you are running a 24/7. there are a variety of options for recovering the database. If a non-system data file is lost. that provide maximum protection for your data. This way. To create the new control file. Or you can create a new control file and open the database in the Reset Logs mode (alter database open resetlogs).Recovery When a Redo Log File Is LostTo recover the database when a redo log file is lost or corrupted alter database clear logfile group 1. and only part of the database (non-system) is damaged. "Database Maintenance and Reorganization. If you lose system data files. the only choice is a closed database recovery. Recovery When a Control File Is Lost To recover the database in case of a lost control file." for creating a new control file. Incomplete Media Recovery . we want to be able to fully recover the data in case of a database failure. Recovery Using Hot Backup When the database is running in ARCHIVELOG mode and online backup is being used. Recovery can be classified as follows: • • • • • • • • Complete media recovery Closed database recovery Open database/offline tablespace recovery Open database/offline tablespace/individual data file recovery Incomplete media recovery Cancel-based recovery Time-based recovery Change-based recovery Complete Media Recovery At all costs. users can access the rest of the database while the recovery is being performed on the damaged data files." The choice of whether to use a closed or open database recovery is based on the type of failure. up to the point of failure. We have taken the trace of control file by using Alter database backup controlfile to trace as part of the backup. Follow the steps explained in Chapter 10 for creating a new control file. "Incomplete Media Recovery. you can open the database for users by taking the damaged data files offline and then performing a recovery on the damaged files. Consequently. mission-critical database. For this the database need to be in NOMOUNT state (startup NOMOUNT). you can perform recovery by using either a closed or open database method. In this situation.

so that the Oracle knows what archived redo log files to apply. With the following command. 5.dbf' offline. you can roll forward the changes by applying redo log files up to the point just before the accidental drop (time-based recovery). When I tried to bring up the database. use the following command: alter tablespace users offline. you will be prompted for the location of the archived redo log files. With the following command. the database opened and immediately died as soon as I started executing any SQL statement. This crippled my ability to perform troubleshooting of the problem. in the evening and the database crashed. mount the database but do not open it: startup mount 3. if the corrupted data file belongs to USERS tablespace. 4. mount database but do not open it: startup mount 3. Restore the damaged files from the backup. Offline Tablespace Recovery Steps 1. Open the database as follows: alter database open. For example. By using the latest control file. 4. you have to use the latest control file to roll forward with the archived redo log files. If you know the time the table drop occurred. Closed Database Recovery Steps 1. 2. Start media recovery as follows: recover database At this point.Incomplete media recovery is very useful as well. Point in Time Recovery There was a database corruption at 5 p. if necessary. if a user drops a table accidentally and comes to you for help. I restored the database from a backup and applied the archive redo log files up to just before the time of the crash and the database came up fine. Restore the damaged files from backup. take the tablespace offline. Take the corrupted data file offline: alter datafile '/u01/oradata/users01. Remember. After the database is open. for example. . 2. Open the database: alter database open Verify that the recovery worked. you can restore the database from a backup.m.

or immediate priority. 5. At this point. 4. Take the corrupted data file offline: alter datafile '/u01/oradata/users01. use the following command: alter tablespace users offline. if the corrupted data file belongs to USERS tablespace. 7. Verify that the recovery worked. take the damaged tablespace offline with a normal or temporary priority to minimize the amount of recovery. Open the database: alter database open.Here. 2.dbf'. tablespace can be taken offline either with a normal. Start the recovery on the data file: recover datafile '/u01/oradata/users01. 8. Offline Datafile Recovery Steps 1. you will be prompted for the location of the archived redo log files. If possible. temporary. tablespace can be taken offline either with a normal. After the database is open. if necessary. .dbf' offline. Using the following command. mount the database but do not open it: Startup mount 3. If possible. if necessary. you will be prompted for the location of the archived redo log files. temporary. For example. 8. Start the recovery on the tablespace: recover tablespace users. take the damaged tablespace offline with a normal or temporary priority to minimize the amount of recovery. take the tablespace offline. 6. or immediate priority. Bring the tablespace online: alter tablespace users online. Bring the tablespace online: alter tablespace users online. Restore the damaged files from the backup. 6. Here. 7. At this point. Verify that the recovery worked.

you will be prompted for the location of the archived redo log files. Open the database: alter database open resetlogs Whenever an incomplete media recovery is being performed or the backup control file is used for recovery.Cancel-Based Recovery Steps 1. 4. if necessary. Time-Based Recovery Steps 1. you should specify the using backup controlfile option. Verify that the recovery worked. . you will be prompted for the location of the archived redo log files. Start the recovery: recover database until time [using backup controlfile] For example recover database until time '1999-01-01:12:00:00' using backup controlfile At this point. 6. The resetlogs option will reset the redo log files. Using the following command. If a backup control file or recreated control file is being used with incomplete recovery. Enter cancel to cancel recovery after Oracle has applied the archived redo log file just prior to the point of corruption. 5. 2. if necessary. Using the following command. mount the database but do not open it: startup mount 3. In time-based recovery. you should specify the using backup controlfile option. mount the database but do not open it: startup mount 3. Perform a full backup of database. a full backup of the database should be performed immediately after recovery. the database should be opened with the resetlogs option. Start the recovery: recover database until cancel [using backup controlfile] At this point. Restore the damaged files from the backup. regardless of the archived redo log number. you will not be able to recover changes made after you reset the logs. Restore the damaged files from the backup. You either completely apply a redo log file or you don't apply it at all. 2. In cancel-based recovery. If you open the database with resetlogs. you cannot stop in the middle of applying a redo log file. you can apply to a specific point in time. Oracle automatically terminates the recovery when it reaches the correct time. If a backup control file or recreated control file is being used with incomplete recovery. Otherwise.

so that it resets the log numbering. you will not be able to recover the changes made after you reset the logs. Verify that the recovery worked. Otherwise. Perform a full backup of the database. 6. the database should be opened with the resetlogs option. Start the recovery: recover database until change [using backup controlfile] For example recover database until change 2315 using backup controlfile At this point. Otherwise. Restore the damaged files from the backup. .4. Verify that the recovery worked. If the database is opened with resetlogs. Oracle automatically terminates the recovery when it reaches the correct system change number (SCN). Open the database: alter database open resetlogs Whenever an incomplete media recovery is being performed or the backup control file is used. a full backup of the database should be performed immediately after recovery. 6. Using the following command. 5. alter database open resetlogs 5. System Tablespace Versus a Non-System Tablespace Recovery When a system data file is lost or damaged. Open the database. the only way to recover the database is by doing a closed database recovery using RECOVER DATABASE command. you will not be able to recover the changes made after you reset the logs. you will be prompted for the location of the archived redo log files. 2. If a backup control file or a recreated control file is being used with an incomplete recovery. Change-Based Recovery Steps 1. you should specify using the backup controlfile option. If the database is opened with resetlogs. mount the database but do not open it: startup mount 3. if necessary. 4. a full backup of the database should be performed immediately after recovery. Perform a full backup of the database.

Table-Level Import A table level import allows you to import specific objects without importing the whole database.name. Example 1: For example.file# = b. For example. It works whether archiving is turned on or off. if one of the developers requests that you transfer the EMP and DEPT tables of user SCOTT from database ORCL to TEST. you can obtain information about the files that need recovery by executing the following command. select name. . The IGNORE=Y option ignores any create errors. You can use the import command to restore the database from the previous day's backup.dmp log=import.log full=y ignore=y destroy=n 4. 1. 2. This command works when the database is mounted or open.file# Recovery Using Import The import utility is used to import the database from the dump file generated through the export utility. v$datafile b where a.Checking for Files Needing Recovery The following command can be used to check the data file status. The restore steps are as follows.dmp. status from v$datafile. Full database import performance can be improved by turning off archiving during the import. C:\>imp system/manager file=export. This is very useful for transferring data across platforms and importing only specific objects or users. Create a blank database—Refer to Chapter 10 for instructions on how to create a database. The command also gives error information. To execute the statement.error from v$recover_file a. 3. assuming that your export dump filename is export. you have a full export of the database from yesterday and your database crashed this afternoon. There are three levels of Import: • • • Full User-level Table-level Full Import A full import can be used to restore the database in case of a database crash. Verify the import log for any errors—With this import. the database must be mounted. select b. Before you actually start recovering the database. the data changes between your previous backup and the crash will be lost. a. You can use the following steps to transfer these two tables. and the DESTROY=N option does not destroy the existing tablespaces. Import the database—The following command performs a full database import.

scott.DEPT) file=export. 3. Connect to TEST database. The steps to restore the table are as follows (assuming that this happened in the TEST database): 1. C:\>set ORACLE_SID=TEST 2.dmp log=export. constraints and any indexes on the table. Import the table from previous backup.SQL>Drop table DEPT. you could do something if you have an export dump file from your previous backup. Example 2: Suppose you walk into the office in the morning and a developer meets you in the hallway and says that he accidentally dropped the SALES table. C:\>set ORACLE_SID=ORCL This step sets the correct database to which to connect. you can truncate the tables or drop the tables as shown. we need to precede them with the owner in the export command. 6.log This command exports table data. 2. . 8. If the TEST database already has EMP and DEPT tables. SQL>Truncate table EMP. 7. Verify the export.log ignore=Y Check for any errors in the import log file. Because the tables belong to owner scott.dmp log=import. C:\>exp system/manager tables=(scott. Perform an export of EMP and DEPT. Set your ORACLE_SID to the TEST database. 5.dept) file=export. Drop the tables if it already exists. He wants to see whether you can do anything to restore the table. Import the tables to TEST.log file to make sure there are no errors in the export.emp. SQL>Connect system/manager@TEST 4. Set your ORACLE_SID to ORCL. Well. Or SQL>Drop table EMP.SQL>Truncate table DEPT.1. C:\>set ORACLE_SID=TEST C:\>imp system/manager fromuser=scott touser=scott tables=(EMP.

17 is created by the Oracle installer when you install the Oracle database under Unix operating system. RMAN operates using the recovery catalog to store metadata information about backup and recovery operations. C:\>imp system/manager tables=(SCOTT. Using the control file is especially appropriate for small databases where installation and administration of another database for the sole purpose of maintaining the recovery catalog is burdensome.log ignore=Y This command imports the SALES table from previous backup. control files and archived redo log files. Listing 3. You should back up the recovery catalog frequently. When you perform a backup using RMAN. Using RMAN you can backup and restore datafiles.17 oratab . The auto startup flag tells whether the Oracle database should be started automatically when the system is rebooted. When you use RMAN with a recovery catalog. To avoid this you should make frequent backups of the control file. information about the backup is stored in the catalog and the actual backups(physical files) are stored on disk or tape(requires media management software). then you can partially reconstruct the catalog from the current control file or control file backups. the RMAN environment is comprised of the following components • • • • RMAN executable Recovery catalog database (Database to hold the catalog) Recovery catalog schema in the recovery catalog database (Schema to hold the metadata information) Optional Media Management Software (for tape backups) Sample Files Sample oratab File Listing 3. Because most information in the recovery catalog is also available in the target database's control file. Oracle home directory. RMAN supports using the target database control file instead of a recovery catalog. A single recovery catalog is able to store information for multiple target databases. The installer adds the instance name.SALES) file=export. If the recovery catalog is destroyed and no backups of it are available. and auto startup flag (Y/N) for the database in the format [SID:ORACLE_HOME:FLAG]. Typically the recovery catalog is stored in a separate database. If you do not want to use the recovery catalog RMAN can use the target database control file to perform backup and recovery operations. The disadvantage of using the control file is that RMAN does not support restore or recovery when the control file is lost. Consequently.dmp log=import. After the import check the import log file for any errors Backup and Recovery Tools Recovery Manager (RMAN) RMAN is an Oracle provided tool that allows you perform backup and recovery operations on the database. loss of the recovery catalog can be disastrous.3. 4.

# All the entries in oratab file follow the # following syntax.18 trace of control file /u02/oracle/DEV/common/admin/udump/DEV_ora_11817.7 System name: SunOS Node name: mking07 Release: 5. This is useful if you need to recreate the control file.1. Each instance listed on a separate line # SID:ORACLE_HOME:Y/N DEV:/u02/oracle/DEV/oracle/8. control files. A trace of the control file can be generated by using the alter database backup control file to trace.Production ORACLE_HOME = /u02/oracle/DEV/oracle/8.7.1.730 . image: oracle@mking07 (TNS V1-V3) *** SESSION ID:(9.trc Oracle8i Enterprise Edition Release 8. Listing 3. It lists the data files.1.1.1.0 .1.6 Version: Generic_105181-25 Machine: sun4u Instance name: DEV Redo thread mounted by this instance: 1 Oracle process number: 10 Unix process pid: 11817.18 will have the structure of the database.730 *** 2001-05-17 21:15:28.1. and the redo log files and their location.0 .Production With the Partitioning option JServer Release 8.7.13) 2001-05-17 21:15:28.7:N TEST:/u05/oracle/TEST/oracle/8.7:N #PREPROD:/u06/oracle/PREPROD/oracle/8.1.7:N Sample Trace of Control File Listing 3.

dbf'. CHARACTER SET WE8ISO8859P1 .# The following commands will create a new control file and use it # to open the database. '/u03/oracle/DEV/data/log02b. Additional logs may # be required for media recovery of offline data files.dbf'. DATAFILE '/u02/oracle/DEV/data/system01.dbf'. Use this # only if the current version of all online logs are available. '/u03/oracle/DEV/data/log01b. '/u02/oracle/DEV/data/indx01.dbf'. '/u02/oracle/DEV/data/temp01.dbf'.dbf'. # Data used by the recovery manager will be lost. '/u02/oracle/DEV/data/rbs01.dbf' ) SIZE 400M. GROUP 2 ( '/u03/oracle/DEV/data/log02a.dbf'. '/u02/oracle/DEV/data/users. STARTUP NOMOUNT CREATE CONTROLFILE REUSE DATABASE "DEV" NORESETLOGS NOARCHIVELOG MAXLOGFILES 16 MAXLOGMEMBERS 4 MAXDATAFILES 1022 MAXINSTANCES 1 MAXLOGHISTORY 453 LOGFILE GROUP 1 ( '/u03/oracle/DEV/data/log01a. .dbf' ) SIZE 400M.

# or if the last shutdown was not normal or immediate. RECOVER DATABASE # Database can now be opened normally. ALTER DATABASE OPEN. # .dbf' REUSE. # Other tempfiles may require adjustment.# Recovery is required if any of the datafiles are restored backups. # End of tempfile additions. ALTER TABLESPACE TEMP ADD TEMPFILE '/u03/oracle/DEV/data/temp04. # Online tempfiles have complete space information.dbf' REUSE. # Commands to add tempfiles to temporary tablespaces. ALTER TABLESPACE TEMP ADD TEMPFILE '/u03/oracle/DEV/data/temp03.

Sign up to vote on this title
UsefulNot useful