| Lesson 8 | Recovering with a Backup Control File |
| Objective | Demonstrate how to use a backup control file to recover. |
A control file is one of the most critical structures in an Oracle database. It records the physical layout of the database: datafiles, redo log files, tablespaces, and the current checkpoint information. When a control file is lost, corrupted, or missing information (for example, about a dropped tablespace that you must restore), recovery can only succeed if you have a usable backup of that control file.
This lesson shows how to recover a database using a backup control file, focusing on a dropped tablespace scenario. The techniques apply to modern Oracle releases (such as 11g through 23c), even though the sample environment uses older tools and paths. In current environments, you would typically use Recovery Manager (RMAN) to restore control files and datafiles, but the underlying concepts are the same.
A backup control file is needed in situations such as:
RESTORE CONTROLFILE FROM AUTOBACKUP in RMAN) and then recover the database.
In both cases, you recover by applying redo to a backup control file, using the
USING BACKUP CONTROLFILE clause. This almost always results in an
incomplete recovery and requires opening the database with
RESETLOGS.
Suppose the current time is 2:14 PM on 21-JAN-2000. A DBA in training has
just informed you that, about ten minutes ago, he executed:
DROP TABLESPACE STUDENT INCLUDING CONTENTS;
The STUDENT tablespace contains the CUSTOMERS table. A large
volume of customer updates occurred about two hours earlier, and you need to minimize
data loss. Fortunately, you have a complete database backup from the previous night.
Your task is to restore the dropped tablespace and its data with minimal data loss, using a backup control file.
Before diving into the commands, it helps to summarize the plan:
Because the current control file no longer knows about the dropped tablespace, you must fall back to a backup control file taken when the tablespace still existed. To prevent any further changes while you prepare for recovery, place the database in restricted mode:
ALTER SYSTEM ENABLE RESTRICTED SESSION;
At the same time, instruct users to record any work they performed after the drop time (about ten minutes) so that it can be manually re-entered after recovery if needed.
Because you are about to replace the current control file, it is a good idea to collect information about the database structure that may be useful during recovery. Start by identifying the current online redo log you are using.
Query the V$LOG view to identify the current log sequence number:
SQL> SELECT * FROM V$LOG;
GROUP# SEQUENCE# BYTES MEMBERS ARC STATUS FIRST_TIME
------ --------- ------- ------- --- -------- -------------------
1 74 1048576 1 NO INACTIVE 21-FEB-00 14:04:04
2 75 1048576 1 NO CURRENT 21-FEB-00 14:09:00
...
From this output you note that the current log sequence number is 75. You will use this information during recovery to verify that all required redo has been applied.
Next, you need the exact filenames and paths of the datafiles that belonged to the
STUDENT tablespace:
SQL> SELECT tablespace_name, file_name
2 FROM dba_data_files
3 WHERE tablespace_name = 'STUDENT';
TABLESPACE_NAME FILE_NAME
--------------- ----------------------------------------
STUDENT C:\ORANT\DATABASE\STUDENT.ORA
1 row selected.
This tells you which datafile must be restored from backup along with the control file.
Use the database alert log to find the exact time when the STUDENT
tablespace was dropped:
...
Mon Feb 21 14:04:13 2000
Drop tablespace student including contents
...
This timestamp will be used in the UNTIL TIME recovery clause. In this
example, you plan to recover to 2000-02-21:14:04:00, just before the drop.
At this point, the database is ready for an incomplete recovery using a backup control file. The following simulation walks through the detailed steps. Although it uses an older Windows/Server Manager environment, the overall sequence is still instructive for modern Oracle systems.
A backup control file is typically created with a command such as:
ALTER DATABASE BACKUP CONTROLFILE TO 'file_name';
-- or
ALTER DATABASE BACKUP CONTROLFILE TO TRACE;
When you recover using a backup control file, Oracle does not trust the redo log history
in that file, so you must always use the
USING BACKUP CONTROLFILE clause and then open the database with
RESETLOGS.
Here is a step-by-step outline of a backup control file recovery. In modern
installations you would often replace the manual copy commands with RMAN
RESTORE commands, but the logic is the same.
IMMEDIATE or NORMAL.V$RECOVER_FILE).
RECOVER DATABASE UNTIL TIME '<time>' USING BACKUP CONTROLFILE;.
ALTER DATABASE OPEN RESETLOGS; to synchronize
datafiles, control file, and redo logs and to begin a new database incarnation.
STUDENT tablespace) exist.SYSDBA and confirm that the STUDENT tablespace
has been dropped:
SQL> SELECT tablespace_name FROM dba_tablespaces;
SQL> SHUTDOWN IMMEDIATE;
SQL> HOST
C:\orant> COPY C:\ORANT\DATABASE\CTL1ORCL.ORA C:\ORANT\DATBASEX
1 file(s) copied.
DO_RESTORE_DCFILE.BAT might perform this for you:
C:\orant> DO_RESTORE_DCFILE
C:\orant\databaseX\CTL1ORCL.ORA
C:\orant\databaseX\LOG1ORCL.ORA
C:\orant\databaseX\LOG2ORCL.ORA
C:\orant\databaseX\LOG3ORCL.ORA
C:\orant\databaseX\LOG4ORCL.ORA
C:\orant\databaseX\OEM.ORA
C:\orant\databaseX\RBS1ORCL.ORA
C:\orant\databaseX\STUDENT.ORA
C:\orant\databaseX\SYS1ORCL.ORA
C:\orant\databaseX\TMP1ORCL.ORA
C:\orant\databaseX\USER_TEMP.ORA
C:\orant\databaseX\USR1ORCL.ORA
12 file(s) copied.
SQL> STARTUP MOUNT;
USING BACKUP CONTROLFILE clause:
SQL> RECOVER DATABASE UNTIL TIME '2000-02-21:14:04:00'
2 USING BACKUP CONTROLFILE;
Oracle requests archived redo logs as needed, for example:
ORA-00279: change 6262125 generated at 02/13/00 20:21:24 needed for thread 1
ORA-00289: suggestion : C:\ORANT\RDBMS80\ARC480.1
ORA-00280: change 6262125 for thread 1 is in sequence #480
Specify log: {<RET> = suggested | filename | AUTO | CANCEL}
AUTO
Log applied.
...
Media recovery complete.
SQL> ALTER DATABASE OPEN RESETLOGS;
Statement processed.
STUDENT tablespace has been recovered:
SQL> SELECT tablespace_name FROM dba_tablespaces;
TABLESPACE_NAME
------------------------------
SYSTEM
USER_DATA
ROLLBACK_DATA
TEMPORARY_DATA
STUDENT
USER_TEMP
OEM
7 rows selected.
Once the recovery is complete and the database is open with RESETLOGS, you should:
In the next lesson, you will learn how to perform a recovery when the current online redo log is lost.