Ioug tip book11_gunukula


Published on

IOUG 2011 Best Practices Booklet

Published in: Technology
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Ioug tip book11_gunukula

  1. 1. Understand the Power of Oracle RMAN By Satishbabu Gunukula This article addressees anyone using RMAN with an Oracle database version 10g+. Throughout my experience, I have seen many situations where DBAs end up with a failed recovery of a database because they did not know what was backed or what is needed for a backup. Many users are posting the same RMAN-failure related questions in the My Oracle Support and Oracle Technology forums. Oracle RMAN Reporting For any company, the most important asset is data, and the most challenging job is to recover the database with less downtime while eliminating data loss in the event of a database failure. You should ensure that your database is backed up efficiently and able to be restored. RMAN reporting provides the most effective and the easiest way to determine the best database backup strategy for a successful recovery. In general, when using an RMAN catalog, the catalog view contains the metadata of all databases. This would require a complex query to extract usable backup information, but with RMAN reporting you can obtain the same information with LIST and REPORT commands. RMAN reporting has been enhanced from version to version, and now you can determine which database files have not been backed up and preview the backups required for a successful restore. As part of your backup and recovery strategy, you should periodically run reports that indicate: 1) what you have backed up; 2) which datafiles need backups or which files have not been backed up to satisfy retention and recovery policies; IOUG TIPS & BeST PracTIceS BOOKLeT | 47Reprinted with permission from Select Journal, the official publication of the Independent Oracle Users Group, Chicago, Illinois. Visit for more publication and membership information. All rights reserved.
  2. 2. 3) which backups RMAN would need to restore if a problem occurs; and4) historical information about RMAN jobs.What Do You Have Backed Up?To know what you have backed up, use the LIST command to get the listsof backups, copies and other objects relating to backup and recovery (e.g.,backups that are expired or restricted).For example, you can list backups of all files in the database. RMAN> LIST BACKUP OF DATABASE;You can list a copy of specified datafile. RMAN> LIST COPY OF DATAFILE ‘/oradata/users01.dbf;Besides backups and copies, the RMAN can list other types of data usingthe LIST command, and it supports a number of options that enable youto control how output is displayed.For example, you can list restore points known to the RMAN catalog forthis database. RMAN> LIST RESTORE POINT;You can list the names of recovery catalog scripts created with theCREATE SCRIPT or REPLACE SCRIPT command. RMAN> LIST SCRIPT NAMES;You can list all of the expired backup sets.48 | INdePeNdeNT OracLe USerS GrOUP www.IOUG.OrG
  3. 3. RMAN> LIST EXPIRED BACKUP SET;Which Datafiles Need a Backup?To know which files need to be backed up, the REPORT commandanalyzes the available backups in the RMAN catalog repository and returnsresults about which files need a backup, which files have had unrecoverableoperations on them and which files are obsolete.Use the REPORT NEED BACKUP command to determine which databasefiles need backup under a specific retention policy. For example, displayobjects requiring backup to satisfy a recovery window-based retention policy. RMAN> REPORT NEED BACKUP RECOVERY WINDOW OF n DAYS;Use the REPORT UNRECOVERABLE command to determine whichdatabase files need a backup when a database file has been affected byunrecoverable operation, such as insert with no logging or direct-pathinsert. Normal media recovery cannot be used to recover the file becausean unrecoverable operation does not generate redo log entries resulting inthem not being captured in the archived redo. You must perform eithera full or incremental backup of the affected datafiles after no loggingoperations to ensure that data blocks affected by the unrecoverableoperation can be recovered using RMAN.For example, identify the datafiles affected by an unrecoverable operation. RMAN > REPORT UNRECOVERABLE;You should also know which backups are obsolete according to the retentionpolicy and can therefore be deleted. A database can be unresponsive as wellas exhibit performance issues when it runs out of room at the disk level. IOUG TIPS & BeST PracTIceS BOOKLeT | 49
  4. 4. The CROSSCHECK command is used to update the status of backupsin the RMAN repository compared to their backup status on disk ortape. Running the REPORT OBSOLETE command identifies whichbackups are obsolete and are no longer needed for recovery. When scriptingDELETE OBSOLETE commands, you will need to add the NOPROMPTkeyword so the script won’t stop and wait for your response.For example, crosscheck all backups and copies on the disk. RMAN>CROSSCHECK BACKUP DEVICE TYPE DISK; RMAN> CROSSCHECK BACKUP;Identify which backups are obsolete and no longer needed for recovery. RMAN> REPORT OBSOLETE;Delete obsolete backup information from RMAN repository. RMAN> DELETE OBSOLETE; RMAN> DELETE NOPROMPT OBSOLETE;This way you can effectively manage the backups and space.Which Backups RMAN Would Need to Be Restored if Problems Occur?Use RESTORE... PREVIEW to know which backups would need to berestored if a problem occurs. The RESTORE…PREVIEW command doesnot actually restore; rather, it identifies the backups required to completea given restore operation based on the information in the repository. Thiscommand ensures that all required backups are available or identifies thebackups required for successful recovery. In case a backup is unavailable,use the CHANGE…UNAVAILABLE command to mark the backup statusto UNAVAILABLE and re-run the RESTORE…PREVIEW to see50 | INdePeNdeNT OracLe USerS GrOUP www.IOUG.OrG
  5. 5. the backups required to perform a restore operation without using theunavailable backup.You can use RESTORE…VALIDATE HEADER as an alternative toRESTORE…PREVIEW. In addition to listing of the files needed forrestore and recovery, this command validates the backup file headers todetermine whether the files on disk or in the media management catalogcorrespond to the metadata in the RMAN repository.For example, identify the backups required to complete a database restore. RMAN> RESTORE DATABASE PREVIEW;Use the REVIEW...SUMMARY command to summarize the lengthy output. RMAN> RESTORE DATABASE PREVIEW SUMMARY;The RESTORE... PREVIEW RECALL can be used in case a restore failsdue to a needed backup not available on a local drive. Using this RECALLmode with a media manager that supports vaulted (secure offsite storage)backups simplifies the RECALL operation by recalling the backups that areneeded for restore from remote storage.For example, to recall backups stored offsite, use: RMAN>RESTORE DATABASE PREVIEW RECALL;You can also use RMAN validation to be sure they can be used for arestore. (For example, check for block corruption and missing backup sets.)The RESTORE…VALIDATE command tests whether you can restorefrom a particular backup and validates the restore of the backup controlfile, SYSTEM tablespace and all archived logs related to that backup set. IOUG TIPS & BeST PracTIceS BOOKLeT | 51
  6. 6. For example, to validate RMAN backups, use: RMAN> RESTORE DATABASE VALIDATE;By default, VALIDATE does not check for logical corruption.To identify logical corruption, use the CHECK LOGICAL clausewith RESTORE…VALIDATE command, which populates theV$DATABASE_BLOCK_CORRUPTION view.Historical Information About RMAN JobsIn some cases, the V$ views supply information that is not availablethrough use of the LIST and REPORT commands. You shouldperiodically run the reports to obtain historical information about RMANjobs. For example, you may want to know how many backup jobs havebeen issued, the status of each backup job (i.e., whether it failed orcompleted), when a job started and finished and what type of backupwas performed.The following query shows the failed backup jobs for a particular time period.Use the query in a script to generate a weekly or monthly report. These typesof queries are run against the RMAN catalog repository database. SQL>select DB_NAME, START_TIME, END_TIME, OBJECT_TYPE, STAMP, STATUS from RC_RMAN_STATUS WHERE OBJECT_TYPE IN (DB FULL,ARCHIVELOG,DATAFILE FULL) and START_TIME > to_date(08-01-2011,MM-DD-YYYY) and START_TIME < to_date(08-07-2011,MM-DD-YYYY) and STATUS=FAILED order by START_TIME;You can also use the example code that follows in your backup script toreport the backup job failure errors immediately instead of after the backupjob is finished.52 | INdePeNdeNT OracLe USerS GrOUP www.IOUG.OrG
  7. 7. V_LOGFILE=/backup/RMAN/pindbts_hotbackup.log ERRORS=`cat $V_LOGFILE | grep "RMAN-"| wc -l` if [ $ERRORS -gt 0 ]; then echo `cat $V_LOGFILE | grep "RMAN-"` | mailx -s "Database Backup Failed" fi Where V_LOGFILE is the backup log generated by your backup script.The views V$RMAN_BACKUP_JOB_DETAILS and V$RMAN_BACKUP_SUBJOB_DETAILS provide details about RMAN backup jobs.RMAN reporting has been enhanced through the V$VIEWS from versionto version. Backup operations are more transparent. DBAs can now easilyembed queries to these views in SQL scripts to generate historical reports.These reports help to analyze the issues and provide information to comeup with the correct action plan to prevent further failures.All the recovery catalog views have corresponding underlying V$ views: Recovery Catalog View Corresponding V$ View --------------------- ------------------------------------ RC_RMAN_BACKUP_JOB_DETAILs V$RMAN_BACKUP_JOB_DETAILS RC_RMAN_OUTPUT V$RMAN_OUPUT RC_RMAN_STATUS V$RMAN_STATUS RC_BACKUP_DATAFILE V$BACKUP_DATAFILE RC_BACKUP_FILES V$BACKUP_FILES RC_BACKUP_CORRUPTION V$BACKUP_CORRUPTION RC_RMAN_STATUS V$RMAN_STATUS RC_RMAN_CONFIGURATION V$RMAN_CONFIGURATIONEnhanced V$ Views from Oracle 10g+The V$RMAN_STATUS view shows the status of completed andrunning RMAN jobs. The running RMAN job information is storedin memory. Once the job is completed, the information is stored in thecontrol file. That information is kept in the control file for the lengthof time specified in the initialization parameter CONTROL_FILE_RECORD_KEEP_TIME. My Oracle Support document 397269.1, IOUG TIPS & BeST PracTIceS BOOKLeT | 53
  8. 8. CONTROL_FILE_RECORD_KEEP_TIME should be higher than theRMAN retention policy with a suggested formula: CONTROL_FILE_RECORD_KEEP_TIME = retention period + level 0 backup interval + 1The following query shows the status of completed, completed with errors,failed and running RMAN jobs. SQL> select OPERATION, START_TIME, END_TIME, OBJECT_TYPE, STATUS from v$RMAN_STATUS order by START_TIME; OPERATION START_TIME END_TIME OBJECT_TYPE SESSION_ STAMP STATUS ---------------- ----------------------------- ----------------------------- ---------------- --- ------------------------ --------------------------- RMAN 09/20/2009 20:00:06 09/20/2009 20:01:21 698172917 COMPLETED BACKUP 09/20/2009 20:00:09 09/20/2009 20:01:06 DB FULL 698172913 COMPLETED BACKUP 09/20/2009 20:01:11 09/20/2009 20:01:21 ARCHIVELOG 698172917 COMPLETED RMAN 09/20/2009 20:05:03 09/20/2009 20:05:28 698172924 COMPLETED WITH ERRORS BACKUP 09/20/2009 20:05:16 09/20/2009 20:05:28 ARCHIVELOG 698172932 FAILED RMAN 09/20/2009 20:10:15 09/20/2009 20:10:47 698172938 RUNNING BACKUP 09/20/2009 20:10:39 09/20/2009 20:10:47 ARCHIVELOG 698172917 RUNNINGYou can find out the errors using the V$RMAN_OUTPUT view. TheV$RMAN_OUTPUT view is an in-memory view that shows the outputof all currently running, recently completed and any failed RMAN jobs.The following query shows the output of a RMAN job. Notice that theSESSION_STAMP comes from the V$RMAN_STATUS output in theprevious command above.54 | INdePeNdeNT OracLe USerS GrOUP www.IOUG.OrG
  9. 9. SQL> Select OUTPUT from V$RMAN_OUTPUT where SESSION_STAMP=698172913; OUTPUT ----------------------------------------------------------------- connected to target database: PINDBTS (DBID=3952868985) executing command: SET SNAPSHOT using target database control file instead of recovery catalog snapshot control file name set to: /backup/dvtestrac01/RMAN/pindbts1/snapcf.f new RMAN configuration parameters are successfully stored allocated channel: d1 channel d1: sid=311 instance=pindbts1 devtype=DISK sql statement: alter system archive log current Starting backup at 21-SEP-09 channel d1: starting full datafile backupset channel d1: specifying datafile(s) in backupset including current control file in backupset channel d1: starting piece 1 at 21-SEP-09 ---- (Some detail removed for brevity) ---- Finished backup at 21-SEP-09 released channel: d1 95 rows selected.The V$BACKUP_FILES view simulates the LIST BACKUP and LISTCOPY RMAN commands. This view also provides the information usedas the basis of the REPORT OBSOLETE command. Now you can getthe exact physical size of the backup set from BS_BYTES column, as theBYTES column shows the size of the physical file.Other Tips and Tricks Using RMANRestoring a Never-Backed-up DatafileRecovery in this situation can come from the combination of online redoand available archived logs. IOUG TIPS & BeST PracTIceS BOOKLeT | 55
  10. 10. Note: Try this in a test environment, as it may leave your database in anunusable state.Remove any online backups. You can temporarily move the backupdirectories to a location unknown to RMAN. You already have an existingdatabase account with logon; create table privileges to do the test with.This database is in archivelog mode: SYS@ORCL>show parameter create_file SYS@ORCL>db_create_file_dest string /u01/oradata SYS@ORCL> create tablespace tbs_from_online; SYS@ORCL> alter user testcaseuser quota unlimited on tbs_from_online; SYS@ORCL> alter user testcaseuser default tablespace tbs_from_online; TESTCASEUSER@ORCL> create table table_from_online as select * from user_tables; SYS@ORCL> alter system switch logfile;The newly created tablespace was taken offline and its status was verified.The database has to be in archivelog mode to be able to accomplish thefollowing task without shutting down the database. SYS@ORCL> alter tablespace tbs_from_online offline immediate; SYS@ORCL> select tablespace_name,status from dba_tablespaces; SYS@ORCL> select name, status from v$data_file; /u01/oradata/ORCL/data_file/01_tbs_1_5nz5261s_.dbf RECOVERRemove the datafile from the operating system location. Remember, thereis no backup of this new tablespace at this point in time. Start an RMANrestore session. RMAN> restore tablespace tbs_from_online;At this point at the OS level, the datafile still doesn’t exist. It is during therecover command where Oracle searches for redo and/or archive logs. Duringthis particular restore session, no archive logs were applied (by viewing56 | INdePeNdeNT OracLe USerS GrOUP www.IOUG.OrG
  11. 11. the output from the RMAN session and alert_$ORACLE_SID.log), so itrestored the missing data file from online redo. RMAN> recover tablespace tbs_from_online; SYS@ORCL> alter tablespace tbs_from_online online; SYS@ORCL>select tablespace_name, status from dba_tablespaces;Upgrading/Downgrading a Database During an RMAN Restore/Recovery SessionRMAN can directly downgrade or upgrade a database. This is particularlyuseful during migration projects when you need to create a clone/copy of adatabase that is a different Oracle version.Use this method for the following reasons:• You can migrate between one-off operating system levels.• You can change database word sizes (32-vit to 64-bit and vice versa).• There is no need to install multiple ORACLE_HOMES of the different versions, just the one you are migrating to. This is assumed you are working with a different server than the original.• It can be used for one-off patches, patchsets or single version differences.For example: 10.2.x to 11.2.x, to, to11. Just be aware of any post-patch steps that might have to beexecuted against a database. You will find these as part of the readmes foreach version involved. These post upgrade tasks typically include catalog.sql, catproc.sql, catpatch.sql and utlrp.sql. Follow the steps used for amanual upgrade/downgrade — search in MOS for the documents thatstart with the keywords Complete Checklist for Manual Upgrades.This method is:• Great for a trial restore of a critical database — so you can test your RMAN restores and recoverability. IOUG TIPS & BeST PracTIceS BOOKLeT | 57
  12. 12. • Useful for a situation where you need to downgrade to a version different than the original.• Useful for cloning a database using a user-managed backup (commonly called cold or hot backups) — in this case, you would need to use the RMAN catalog command to let the repository catalog know where to find the datafile copies.This allows you to skip the step where you would first need to clone (like theRMAN duplicate command) to the same binary version as the original andthen finish the database upgrade/downgrade. See Oracle Database Backupand Recovery Users Guide 11g (Chapter 19, Performing RMAN Recovery:Advanced Scenarios) Look for the section labeled “Restoring a Database on aNew Host” for more details that aren’t included in the following steps.This type of restore/recovery in order to upgrade/downgrade scenariocannot be used in conjunction with the RMAN duplicate databasecommand. Also, be careful to use the NOCATALOG mode of RMANrecovery when you are attempting this on the same host as the originaldatabase. See MOS Note: 245262.1 for more information.Steps for RMAN upgrade:1. Install higher-versioned Oracle software. Create oratab entry — ORACLE_SID same as original. Use NID to change later if desired. Create necessary datafile directories; you can change the datafile locations using SET NEWNAME as part of the RMAN command.2. Run Pre-Upgrade Tool.3. Make backups available on the server to which you are restoring.4. Set environmental variables, run oraenv and start RMAN. RMAN> CONNECT TARGET / RMAN>SET DBID XXXXXXXXXX; RMAN>STARTUP NOMOUNT58 | INdePeNdeNT OracLe USerS GrOUP www.IOUG.OrG
  13. 13. 5. Recover spfile or create a new pfile. If upgrading from 10.x, the spfile won’t be included if the controlfile is configured for autobackup.6. Restore the controlfile, then mount the database. run { SET CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO /backuplocation/%F; restore controlfile from autobackup; alter database mount; }7. Restore datafiles and recover the database. The following example restores to a certain point in time: RUN { set until time = "to_date(02/05/11:16:00:00,MM/DD/YY:HH24:MI:SS)"; # restore the database and switch the datafile names, this example will restore the # datafiles to their original location. RESTORE DATABASE; SWITCH DATAFILE ALL; RECOVER DATABASE; }8. Open the database using the following command. This step can also be accomplished at the RMAN command line or using SQL*PLUS. SYS@ORCL> or RMAN> alter database open resetlogs upgrade;9. Finish the upgrade by following the standard manual upgrade method. There may be more post steps than what is listed. The shortened example outlined just highlights the differences between using RMAN and a traditional manual upgrade. SYS@ORCL> @$ORACLE_HOME/rdbms/admin/catupgrd.sql IOUG TIPS & BeST PracTIceS BOOKLeT | 59
  14. 14. Backup Strategies and RecommendationsWhat is the best number of days to set for a recovery window? It dependson how much backup space is available and the type of backups — fullor incremental. For an incremental backup policy, the most efficient useof backup space would be a window that is one less than the default ofseven days: six days. That makes an older Level 0 obsolete prior to the nextLevel 0. This is assumed that you will take a Level 0 incremental backup(basically a full backup) once a week with all other backups as incrementaland/or differential. Of course, you can extend this window strategy to 13or 20 days and so on.While using a recovery window is one of the most common backup andrecovery strategies used, you should also familiarize yourself with Oracle’srecommendation: Incrementally Updated Backup. To take full advantage ofthis type of strategy (fastest restores/recovery), store the backups in the FlashRecovery Area (FRA). This allows you to switch the database to the actualcopy stored in the FRA. This also removes the need (hint: save time) to restoreor recover any datafiles, as you are actually switching to the backup set plusthe step of media recovery — applying archivelogs. Note this type of backupstrategy limits the time period to restore from as it is a daily updated backup.The difference between a normal incremental and the merge method isthe RECOVER command that comes before the backup and the FORRECOVER OF COPY keywords in the backup command. The followingexample also checks for logical corruption while compressing: RMAN> run{ backup as compressed backupset check logical incremental level 1 for recover of copy with tag MY_DAILY_COPY database filesperset 1; recover copy of database with tag MY_DAILY_COPY; }60 | INdePeNdeNT OracLe USerS GrOUP www.IOUG.OrG
  15. 15. Fastest Way to Restore Entire Database using Incremental MergeBackup Strategy1. Create a pfile with control_file =’/FRA_location_copy of controlfile.’2. Mount DB.3. Switch Database to Copy .4. Recover.5. Open.Recommendations Utilizing RMAN, FRA & DATA GUARD with 11gHere are some generalized tips combining Incremental Merged Backups,FRA and DataGuard for a fully redundant backup solution:• One-time image copy backup to Fast Recovery Area (FRA)• Daily differential incremental backup to FRA• Image copy rolled forward daily until “sysdate – 4,” extends recovery time period• FRA sized for one image copy backup + 4 incrementals + 4 days of archived logs• Daily backup of FRA to tape and/or Cloud (retained for one month)• Daily vaulting of tape backups to offsite location (retained for one year)• Real time, synchronized physical standby database in Maximum Performance mode for disaster recovery and other point in time recoveries• Utilize RMAN Recovery Advisor + DATA GUARD for real-time detection, analysis and recovery of failures• ASM — excellent FRA destination due to raw device-like performance, management capabilities, working with large pools and/or multiple FRA IOUG TIPS & BeST PracTIceS BOOKLeT | 61
  16. 16. Datawarehouse RMAN Backup over Several Days MethodThe following example runs the backup command for the next eighthours, running the same command again at the next interval takes upwhere it left off.RMAN> BACKUP DATABASE NOT BACKED UP SINCE‘SYSDATE-3’ DURATION 08:00 PARTIAL MINIMIZE TIME;If you haven’t started using RMAN yet, now is the time to start. It isbecoming the standard for Oracle database. ■ ■ ■ About the Author Satishbabu Gunukula has more than 12 years of experience in Oracle database technologies and has specialized in Oracle rac administration on a wide variety of UNIX platforms. He has implemented many business critical rac and Maa systems for Fortune 500 and Fortune 1000 companies. He also has experience in Oracle applications and Oracle Hyperion. He received his master’s and is an Oracle certified dBa in OcP 8i/9i/10g and Oracle certified expert in Oracle 10g rac. He is currently working for Intuitive Surgical, a medical device company, as senior database administrator. .?.Did You KNOW… The highest rated member benefit is the IOUG SELECT Journal, IOUG’s quarterly technical journal that provides in-depth technical articles from recognized authorities in Oracle technology.62 | INdePeNdeNT OracLe USerS GrOUP www.IOUG.OrG