Tuesday 11 September 2007

Database Recovery



Assumptions

It is assumed that you have a working knowledge of the Oracle data structures and syntax, and also some knowledge of Windows file systems.

For the purposes of this document it is assumed that you are either restoring a database that has ‘crashed’ / needs to be restored in a new location, or you are copying a database for test purposes.

You can login to the database as administrator.

Steps leading to failure:

1. The NT server crashes
2. Database is in archivelog mode
3. Online backup of datafiles and controlfile(s) is available

Option 1A:
Re-create the database in an identical machine, with the database files placed in the same directory. However, the archivelog files needed for rolling forward are located in a shared drive.

1. Create oracle service using oradim utility. Check that the services are created (START\CONTROL PANEL\SERVICES).

oradim -new -sid [INST_NAME] -intpwd [PASSWD] -startmode auto -pfile d:\ora805....

2. Copy the datafiles and controlfile(s) into proper directories. 

3. Once all database files are in place, change the log_archive_dest in the init.ora file to point to the shared drive (e.g. j:\archive).

4. Go to control panel\services and double click on the oracleservice[SID].

   Change info in "Log on As" from "SYSTEM ACCOUNT" to "THIS ACCOUNT" and enter the administrator user (e.g. "administrator"). Also enter and confirm the administrator password. Click on "APPLY" and "CLOSE".

5. Do the same for the oraclestart[SID] .

6. Stop then restart the service oracleservice[SID].

7. Open a DOS window, type "set oracle_sid= [SID]"

   An alternative would be to set this environment variable permanently. Click on Start/Settings/Control Panel/System. Then click on the environment tab and fill in VARIABLE (oracle_sid) and VALUE (SID). Then click on APPLY and OK.

8. Open server manager and connect internal/[passwd]

9. Startup in mount mode.

   (SVRMGR> startup mount pfile=d:\ora805\database...)

10. Do incomplete recovery.

   (SVRMGR>recover database using backup controlfile until cancel;)

11. Apply archive logs when prompted.

12. When oracle asks for archive log that does not exist, type "CANCEL".

13. Open the database.

   (SVRMGR> alter database open resetlogs).

14. Shutdown the database, and exit from Server Manager.

15. Modify the log_archive_dest parameter in the init.ora file back to local drive.

16.  Go back to control panel\services\oracleservice[SID] and modify 
     "Log on As" section back to "SYSTEM" account.

17.  Do the same for oraclestart[SID].

18.  Shutdown both services. Restart just oracleservice[SID].

19.  Go back to server manager and restart the database. 

20.  Shutdown the database and perform a full backup.


Note:

1. If the service "LOG ON AS" section is not changed from "SYSTEM" account, you
   will get the errors below:

ORA-00256 error occurred in translating archive text string 'j:\archive_dest'
ORA-09291 sksachk: invalid device specified for archive destination
OSD-04018 Unable to access the specified directory or device

2. If "UNTIL CANCEL" is not specified during recovery, you will get: 

   ORA-01113 file d:\orant\database\sys.dbf needs media recovery 

Scenario 2:
-----------

1. The NT server crashes
2. DB in archivelog mode
3. Online backup of datafiles is available
4. No backup of controlfile or a controlfile trace is available

1. Create service using oradim utility. (See Step 1, Option 1A for syntax)

2. Copy the datafiles into proper directories. 

3. Open a DOS window, type "set oracle_sid= [SID]".

4. Open Server Manager and connect internal/[password].

5. Startup in nomount mode.

  (SVRMGR> startup mount pfile=d:\ora805\database...)

6. Run the create controlfile script. You need to modify a few lines in this script. For example, be sure to have "RESETLOGS" and "ARCHIVELOG" in the CREATE CONTROLFILE statement. If you do not have RESETLOGS option for example, you will get the following errors since oracle will look for your redo log files. Remember the REUSE and SET keywords in the script. REUSE will REUSE the database and SET allows you to change the database name. You also have the option of ‘pre-positioning your data files etc.. before creating your control file. Just remember to reflect all changes

CREATE CONTROLFILE REUSE DATABASE "ORCL" NORESETLOGS ARCHIVELOG
*
ORA-01503: CREATE CONTROLFILE failed
ORA-01565: error in identifying file 'D:\ORA_805\DATABASE\LOG4ORCL.ORA'
ORA-27041: unable to open file
OSD-04002: unable to open file
O/S-Error: (OS 2) The system cannot find the file specified.

STARTUP NOMOUNT
CREATE CONTROLFILE REUSE SET DATABASE "MAPBACK2" RESETLOGS  ARCHIVELOG
--  SET STANDBY TO MAXIMIZE PERFORMANCE
    MAXLOGFILES 50
    MAXLOGMEMBERS 5
    MAXDATAFILES 100
    MAXINSTANCES 1
    MAXLOGHISTORY 113
LOGFILE
  GROUP 1 'E:\ORACLE\TEST\REDO01.LOG'  SIZE 100M,
  GROUP 2 'E:\ORACLE\TEST\REDO02.LOG'  SIZE 100M,
  GROUP 3 'E:\ORACLE\TEST\REDO03.LOG'  SIZE 100M
-- STANDBY LOGFILE
DATAFILE
  'E:\ORACLE\TEST\SYSTEM01.DBF',
  'E:\ORACLE\TEST\UNDOTBS01.DBF',
  'E:\ORACLE\TEST\CWMLITE01.DBF',
  'E:\ORACLE\TEST\DRSYS01.DBF',
  'E:\ORACLE\TEST\EXAMPLE01.DBF',
  'E:\ORACLE\TEST\INDX01.DBF',
  'E:\ORACLE\TEST\TOOLS01.DBF',
  'E:\ORACLE\TEST\USERS01.DBF',
  'E:\ORACLE\TEST\RBS01.DBF',
  'E:\ORACLE\TEST\MAP_TABLES01.DBF',
  'E:\ORACLE\TEST\MAP_LOB01.DBF',
  'E:\ORACLE\TEST\MAP_INDEXES_IM.ORA',
  'E:\ORACLE\TEST\MAP_INDEXES_PK.ORA',
  'E:\ORACLE\TEST\LOC2003091.DBF',
  'E:\ORACLE\TEST\LOC2003081.DBF',
  'E:\ORACLE\TEST\LOC2003071.DBF',
  'E:\ORACLE\TEST\LOC2003061.DBF',
  'E:\ORACLE\TEST\LOC2003101.DBF',
  'E:\ORACLE\TEST\LOC2003111.DBF'
CHARACTER SET WE8ISO8859P1
;


7. Do incomplete recovery.

  (SVRMGR>recover database using backup controlfile until cancel;)

8. Apply archive logs when prompted.

9. When oracle asks for archive log that does not exist, type "CANCEL".

10. Open database 

    (SVRMGR> alter database open resetlogs;) 

11. Shutdown the database and perform a full backup.