Database Recovery For Newbies Paper #521 Bonnie Bizzaro, Susan McClain
Objectives Provide basic understanding of recovery processes and terms Define different types of recovery Discuss common recovery strategies Demo of Recovery Manager (RMAN) 2
Basic Recovery Types Instance recovery Media recovery Data recovery Disaster recovery 3
Basic Recovery Terms Data block Data file Tablespace System change number (SCN) 4
Basic Recovery Terms, cont d Rollback segment / Undo segment Online redo log Archive redo log (No)Archivelog mode Offline backup Online backup 5
Instance Recovery What is instance recovery When database crashes Automatically brings to consistent state Should shutdown/restart database before resuming normal activity 6
Instance Recovery, cont d Entries in the alert log Database mounted in Exclusive Mode. Completed: alter database mount Sun Feb 23 05:50:20 2003 alter database open Beginning crash recovery of 1 threads Sun Feb 23 05:50:24 2003 Thread recovery: start rolling forward thread 1 Recovery of Online Redo Log: Thread 1 Group 2 Seq 35417 Reading mem 0 Mem# 0 errs 0: u05/oradata/lprod/redolprod2.log Sun Feb 23 05:50:27 2003 Thread recovery: finish rolling forward thread 1 Thread recovery: 241 data blocks read, 241 data blocks written, 3771 redo blocks read Crash recovery completed successfully 7
Media Recovery What is Media recovery physical components of the database 8
Media Recovery, cont d Common causes of media loss or failure Lost or corrupted data file strategies Lost or corrupt control file strategies Complete or incomplete recovery strategies 9
Lost or Corrupted Data File For non-system tablespace Offline the object Alter tablespace xxxx offline; Alter database datafile /u01/oradata/xxxxx offline; Restore the file from backup Execute recover command Recover tablespace xxxx; Recover datafile /u01/oradata/xxxxx ; 10
Lost or Corrupted Data File For non-system tablespace, cont d Apply archive logs if prompted Online the object Alter tablespace xxxx online; Alter database datafile /u01/oradata/xxxxx online; Verify recovery Select name,status from v$datafile; Status should be ONLINE 11
Lost or Corrupted Data File For system tablespace Shutdown database Restore the file from backup Start the database in mounted state Startup mount; Execute recover command Recover database; Apply logs if prompted Open database Alter database open; 12
Lost or Corrupted Data File No archivelog mode Shutdown database, do a backup Restore all files from previous offline backup Restore control file from the same backup Startup database If you don t have a copy of your control file from the previous offline backup Startup mount; Alter database open resetlogs; Immediately do a backup 13
Lost or Corrupted Control File Shutdown database If control files multiplexed Copy a good control file over corrupted one Restart database If all copies of control file are gone Use backup controlfile script Restart database Backup database 14
Lost or Corrupted Control File Alter database backup controlfile to trace; STARTUP NOMOUNT CREATE CONTROLFILE REUSE DATABASE "LPROD" NORESETLOGS ARCHIVELOG MAXLOGFILES 16 MAXLOGMEMBERS 2 MAXDATAFILES 800 MAXINSTANCES 1 MAXLOGHISTORY 2726 LOGFILE GROUP 1 '/u06/oradata/lprod/redolprod01.log' SIZE 80M, GROUP 2 '/u05/oradata/lprod/redolprod2.log' SIZE 80M DATAFILE /u06/oradata/lprod/system01.dbf, /u06/oradata/lprod/rbs101.dbf, /u01/oradata/lprod/temp01.dbf, /u01/oradata/lprod/tools01.dbf, 15
Lost or Corrupted Control File Alter database backup controlfile to trace;, cont d.. # Recovery is required if any of the datafiles are restored backups, # or if the last shutdown was not normal or immediate. RECOVER DATABASE # All logs need archiving and a log switch is needed. ALTER SYSTEM ARCHIVE LOG ALL; # Database can now be opened normally. ALTER DATABASE OPEN; 16
Incomplete Recovery Common scenarios Database point in time recovery Tablespace point in time recovery Recover until cancel Recover until change (SCN) 17
Database Point In Time Recovery Shutdown database Restore all datafiles from previous backup Verify archive logs are available Startup database in mounted state Startup mount ; 18
Database Point In Time Recovery, cont d Execute recovery command Recover database until time 2002-12- 28:10:38:00 ; Or, Recover database until cancel; Open database and resetlogs Alter database open resetlogs; Backup database 19
Data Recovery Using export/import Partial database recovery, then export Transportable tablespace Logminer 20
Disaster Recovery Loss of Server Data center Building If different OS on DR server, use import Verify Oracle version Create shell database Import full database Restore your initsid.ora 21
Disaster Recovery, cont d If same OS on DR server, restore files from hot/cold backup Restore files using original paths Rename files in mounted state Restore initsid.ora file Startup database, recover Standby database Have a plan and test it! 22
Server Managed Recovery RMAN Overview Uses Oracle s server processes Scripts are found in $ORACLE_HOME/bin Target database Repository Media Manager Channels / Disk Devices 23
RMAN Overview Repository Setup Create repository owner Grant RECOVERY_CATALOG_OWNER role Connect to the repository and create catalog Connect to target (needs SYSDBA role) and register the database 24
RMAN DEMO Susan McClain, Alliance Data Systems 25
Final Notes Keep users out of your database while recovering Startup restrict Backup your database before starting a recovery If you think it can t get any worse, trust me, it can Analyze all alternatives before you begin Successful recoveries require successful backups. Make sure you have data files, controlfiles, initsid.ora, archive logs, redo logs (hot backups) 26
Final Notes The best recovery is no recovery Multiplex control files Multiplex redo logs Have appropriate OS and database security TEST YOUR RECOVERY PLAN REGULARLY! If you can t recover your database Select * from v$my_resume; 27
Q & A Paper #521 28
Database Recovery for Newbies Paper #521 Bonnie J. Bizzaro Lead Database Administrator Alliance Data Systems Bbizzaro@alldata.net Susan McClain Systems Manager, Distributed Database Support Alliance Data Systems Special thanks to Joe Testa, Data Management Consulting 29