External Links http://www.fadalti.com/oracle/database/rman_effective_use.htm http://download.oracle.com/docs/cd/B19306_01/backup.102/b14193/toc.htm SELECT SID, SERIAL#, CONTEXT, SOFAR, TOTALWORK, ROUND(SOFAR/TOTALWORK*100, 2) "%_COMPLETE" FROM V$SESSION_LONGOPS WHERE OPNAME LIKE ' RMAN%' AND OPNAME NOT LIKE ' %aggregate%' AND TOTALWORK ! = 0 AND SOFAR <> TOTALWORK; SID SERIAL# CONTEXT SOFAR TOTALWORK %_COMPLETE ---------- ---------- ---------- ---------- ---------- --------- --------- 17 167 1 4784 116328 4.11 You can reissue this query throughout the backup process to get an update on the work still needing to be completed: SID SERIAL# CONTEXT SOFAR TOTALWORK %_COMPLETE ---------- ---------- ---------- ---------- ---------- --------- --------- 17 167 1 96999 116328 83.38 |
RMAN Quick Ref
Flash Recovery Area
The Flash R ecovery Area: The flash recovery area (FRA) is not a requirement for using RMAN, but it should be. New in 10g, the FRA is a specific location on disk that you set up to house all the Oracle recovery files. Recovery files refers to all files that might be required for a media recovery operation: full datafile backups, incremental backups, datafile copies, backup control files, and archive logs. The FRA also functions as a repository for mirrored copies of online redo log files, the block-change tracking file, and for a current control file. If set up, flashback logs for using the flashback database option also live in the FRA. (We discuss flashback technologies in Chapter 1 3.) The concept behind the FRA is to simplify the management of your backup and recovery duties by consolidating the requisite files into a single location that Oracle and RMAN can then micromanage, while the DBA moves on to other important duties. This simplification is based on some underlying principles of a solid backup strategy that focuses on availability:
The FRA that you set up can be either a directory on a normal disk volume or an Automatic Storage Management (ASM) disk group. The FRA is determined by two initialization parameters: DB_RECOVERY_FILE_DEST and DB_RECOVERY_FILE_DEST_SIZE. The first determines the location and the second, the size. These can be set With an FRA configured, you are not required to set any other LOG_ARCHIVE_DEST_n parameter for archive logs; by default, with an FRA, Oracle will default LOG_ARCHIVE_DEST_10 to the FRA. It should also be noted that with an FRA in use, you cannot use LOG_ARCH IVE_DEST or LOG_ARCH IVE_DUPLEX_DEST—but, of course, you rid yourself of these outdated parameters long ago… right? The FRA manages recovery files internally, first based on database name, then on types of files, and then by the dates the files are generated. The files themselves are named according to the Oracle Managed Files (OMF) format. As such, the files are hard to decipher (except for archive logs, which still maintain the structure you give them with the LOG_ARCHIVE_FORMAT parameter). Significant internal directory structures exist for file management. However, the point of an FRA is that you don’t need to spend much time worrying about the files. That being said, it’s worth taking note of the internal structure and familiarizing yourself with where the files go. Sooner or later, you will end up digging for a particular file manually. Trust us.The same FRA can be used by multiple databases. This can provide significant advantages, particularly for a Data Guard configuration, but also if you have a large ASM disk group and multiple databases on the same system. It can come in handy, as well, when it comes time to clone production for test purposes. Here’s the catch: all the databases that share the FRA either have a different value for DB_NAME or have a different name for the value DB_UNIQUE_NAME. Setting Up the Flash Recovery Area To set up the FRA, you will want to configure the following parameters: Parameter DB_RECOVERY_FILE_DEST_SIZE DB_RECOVERY_FILE_DEST Example Alter system set db_recovery_file_dest_size=20G scope=both; Purpose Sets the allocated size of the FRA, in bytes, and must be defined in order to enable the FRA. This allows you to control how much disk space is allocated to the FRA. You should not set this value to a size greater than the total amount of available disk space. Alter system set db_recovery_file_dest=' /u01/oracle/flash_recovery' scope=both; Specifies the location of the FRA. This can be a file system, an ASM disk location, or an OMF location. Note that you must specify the DB_RECOVERY_FILE_DEST_SIZE parameter before you specify the DB_RECOVERY_FILE_DEST parameter. Failure to do so will result in an ORA-32 001 error message. In a similar fashion, you must disable the DB_RECOVERY_FILE_DEST parameter before you reset the DB_RECOVERY_FILE_DEST_SIZE parameter. Leaving DB_RECOVERY_FILE_DEST empty will disable the FRA. Here is an example of disabling the FRA by resetting the DB_ RECOVERY_FILE_DEST parameter: alter system set db_recovery_file_dest=' ' scope=both; Oracle allows you to archive to both the FRA and to one or more additional locations through the use of the LOG_ARCHIVE_DEST_n parameters. One case when you would want to do this is if you were configuring standby databases and you still wanted to take advantage of the features of the FRA. To configure both FRA and archive log destination directories, you set the standard FRA parameter DB_RECOVERY_FILE_DEST, defining the location of the FRA. You will also define the various LOG_ARCHIVE_DEST_n parameters that are required. By default, when a LOG_ARCHIVE_DEST_n parameter is defined, that location will be used instead of the FRA. To get Oracle to use the FRA when a LOG_ARCHIVE_DEST_n parameter is set, you need to define an additional LOG_ARCHIVE_DEST_n parameter for the FRA. Typically, this will be LOG_ARCHIVE_DEST_1 0, and you will use the Oracle-supplied constant USE_DB_RECOVERY_FILE_DEST to indicate that this destination is the FRA. Here is an example where we configure Oracle to use the FRA and a regular archive log destination directory: alter system set log_archive_dest_10=' LOCATION=USE_DB_RECOVERY_FILE_DEST' ; alter system set log_archive_dest_1=' location=c: \oracle\oraarc\beta1 mandatory' ; In this example, the ARCH process will now create archived redo logs in both LOG_ARCHIVE_DEST_1 and LOG_ARCHIVE_DEST_10, which is the FRA. Flash Recovery Area Views Several views are available to help you manage the FRA. These views include the following:
SQL> select reason from dba_outstanding_alerts; REASON ------------------------------------------------------------- db_recovery_file_dest_size of 524288000 bytes is 100. 00% used and has 0 remaining bytes available. SQL> alter system set db_recovery_file_dest_size=800m; The V$RECOVERY_FILE_DEST View The V$RECOVERY_FILE_DEST view provides an overview of the FRA that is defined in your database. It provides the size that the FRA is configured for, the amount of space used, how much space can be reclaimed, and the number of files in the FRA. In the following example, we can see that the increase in space to the FRA to 800MB has been recorded (SPACE_LIMIT). However, we still have used too much space (SPACE_ USED), and the FRA is still full. SQL> select * from v$recovery_file_dest; NAME ----------------------------------------------------------------------- SPACE_LIMIT SPACE_USED SPACE_RECLAIMABLE NUMBER_OF_FILES -------------- ---------------------- ------------------ -------------- c: \oracle\product\10. 2.0\flash_recovery_area 838, 860, 800 1, 057, 116, 672 338, 081, 280 11 One nice thing about Oracle is that it manages the FRA space for us as much as it can, and if there is reclaimable space available, it will free it as required. Note that in the previous query, Oracle indicated we were out of FRA space. Did you notice the SPACE_RECLAIMABLE column, though? This column indicates that there is reclaimable space available. This is space that is taken up by archived redo logs or backup set pieces that are no longer needed by virtue of whatever retention criteria we have selected (we will discuss retention criteria and setting those criteria later in this chapter). When Oracle needs space in the FRA (say, for example, we force a log switch), it will remove any files that are reclaimable and free up space. In the next query, we can see that this has occurred. After we ran the previous query that indicated we were out of FRA space, we forced a log switch. This caused Oracle to reclaim space from the FRA for reuse, and it then was able to write out the archived redo log. We can query the V$RECOVERY_FILE_DEST view and see that this has indeed occurred: SQL> alter system switch logfile; System altered. SQL> select * from v$recovery_file_dest; NAME ----------------------------------------------------------------------- SPACE_LIMIT SPACE_USED SPACE_RECLAIMABLE NUMBER_OF_FILES -------------- ---------------------- ------------------ -------------- c: \oracle\product\10. 2.0\flash_recovery_area 838, 860, 800 719, 412, 7 36 64, 000 The V$FLASH_RECOVERY_AREA_USAGE View The V$FLASH_RECOVERY_AREA_USAGE view provides more detailed information on which types of files are occupying space in the FRA. This view groups the file types and then provides the percentage of space that is used by each file type, the percentage of the total FRA reclaimable space that comes from that group, and the number of files in the FRA that come from that group. Here is a query of the V$FLASH_RECOVERY_AREA_USAGE view: SQL> SELECT * FROM V$FLASH_RECOVERY_AREA_USAGE; FILE_TYPE PERCENT_SPACE_USED PERCENT_SPACE_RECLAIMABLE NUMBER_OF_FILES ------------ ------------------ ------------------------- --------------CONTROLFILE 0 0 0 ONLINELOG 0 0 0 ARCHIVELOG 17. 14 17 . 09 7 BACKUPPIECE 108. 88 23. 22 4 IMAGECOPY 0 0 0 FLASHBACKLOG 0 0 0 In this example, we notice a few things:We are over our defined space allocation (the PERCENT_SPACE_USED of all the rows exceeds 1 00 percent). This is probably because the size of the FRA was recently changed and Oracle has not yet reclaimed enough space to bring the total used below 1 00 percent.The backup set pieces are consuming most of that space, and 23 .22 percent of that space is reclaimable.The archived redo logs consume only 1 7 percent of the space allocated to the FRA, and even if we were to remove all of the archived redo logs, we would not free up enough space to bring the FRA under the amount of space allocated to it.Other Views with FRA Columns The column IS_RECOVERY_DEST_FILE can be found in a number of Oracle Database V$ views such as V$CONTROLFILE, V$LOGFILE, V$ARCHIVED_LOG, V$DATAFILE_COPY, V$DATAFILE, and V$BACKU P_PIECE. This column is a Boolean that indicates whether the file is in the FRA.Another column, BYTES, can be found in the V$BACKU P_PIECE and RC_BACKUP_PIECE (an RMAN recovery catalog view) views. |
Auxiliary Database
The auxiliary database refers to the instance that will become host to restored files from the target database in the event of a tablespace point-in-time recovery (TSPITR), a duplication operation (cloning the database), or the creation of a standby database using RMAN backups. When you perform any of these tasks, you will be connecting to the target database and the auxiliary database at the same time from within RMAN. In this way, you can utilize the information about the backups in the target database control file to coordinate the restore of those backups to the auxiliary database location. The following shows the connection to both the target database (locally) and the auxiliary database (using an Oracle Net connection): rman>connect target / rman>connect auxiliary sys/pwd@aux1 RMAN makes a simultaneous connection to each database and requires access to the SYS.DBMS_BACKUP_RESTORE and SYS.DBMS_RCVMAN packages in both the target database and the auxiliary database. As such, RMAN requires sysdba privileges at the auxiliary, just as it does at the target. Because RMAN must make a sysdba connection to two separate databases, you are required to configure at least one of them with a password file and make an Oracle Net connection to it.there is no way to connect locally to two different databases. |
The RMAN Server Processes
RMAN makes a client connection to the target database, and two server processes are spawned. The primary process is used to make calls to packages in the SYS schema in order to perform the backup or recovery operations. This process coordinates the work of the channel processes during backups and restores. The secondary, or shadow, process polls any long-running transactions in RMAN and then logs the information internally. You can view the results of this polling in the view V$SESSION_LONGOPS: SELECT SID, SERIAL#, CONTEXT, SOFAR, TOTALWORK, ROUND( SOFAR/TOTALWORK*100, 2) "%_COMPLETE" FROM V$SESSION_LONGOPS WHERE OPNAME LIKE ' RMAN%' AND OPNAME NOT LIKE ' %aggregate%' AND TOTALWORK ! = 0 AND SOFAR <> TOTALWORK / You can also view these processes in the V$SESSION view. When RMAN allocates a channel, it provides the session ID information in the output: allocated channel: ORA_DISK_1 channel ORA_DISK_1: sid=16 devtype=DISK The sid information corresponds to the SID column in V$SESSION. So you could construct a query such as this: SQL> column client_info format a30 SQL> column program format a15 SQL> select sid, saddr, paddr, program, client_info from v$session where sid=16; SID SADDR PADDR PROGRAM CLIENT_INFO ---------- -------- -------- --------------- ----------------------- 16 682144E8 681E82BC RMAN.EXE rman channel=ORA_DISK_1 |
Back up the control file
When you issue the command alter database backup control file to trace; the script that is generated does not include the information in the control file that identifies your backups. Without these backup records, you cannot access the backups when they are needed for recovery. All RMAN information is lost, and you cannot get it back. The only RMAN information that gets rebuilt when you rebuild the control file is any permanent configuration parameters you have set with RMAN. In Oracle 1 0g and higher, a new mechanism generates limited backup metadata within a control file, but you are still building in a lot of manual work that never used to exist. Therefore, we encourage you to avoid a control file rebuild at all costs. If you back up the control file to a binary file, instead of to trace, then all backup information is preserved. This command looks like the following: alter database backup controlfile to ' /u01/backup/bkup_cfile. ctl' ; |
SQL returns the min and max SCN numbers contained in the last online backup.
SELECT MIN(VBD.CHECKPOINT_CHANGE#), MAX(VBD.CHECKPOINT_CHANGE#) FROM V$BACKUP_DATAFILE VBD, V$DATAFILE VDF, (SELECT CREATION_CHANGE#, MAX(COMPLETION_TIME) COMPLETION_TIME FROM V$BACKUP_DATAFILE WHERE CREATION_CHANGE# IN ( SELECT CREATION_CHANGE# FROM V$DATAFILE) GROUP BY CREATION_CHANGE# ) QUERY1 WHERE VBD.CREATION_CHANGE# = VDF.CREATION_CHANGE# AND VBD.CREATION_CHANGE# = QUERY1.CREATION_CHANGE# AND VBD.COMPLETION_TIME = QUERY1.COMPLETION_TIME; Modify TNSNAMES.ORA cd $ORACLE_HOME/network/admin vi tnsnames.ora -- add the following: REPOS = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.119)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = repos) ) ) -- save change <Esc> zz $ tnsping repos Put the Database into Archive Log Mode -- as oracle $ sqlplus /nolog SQL> conn / as sysdba col name format a30 col value format a30 SELECT name, value FROM gv$parameter WHERE name LIKE '%arch%'; SQL> shutdown immediate; SQL> startup mount exclusive; SQL> alter database archivelog; SQL> alter database open; SQL> SELECT group#, thread#, sequence#, archived, status, first_time FROM v$log; SQL> alter system switch logfile; SQL> SELECT group#, thread#, sequence#, archived, status, first_time FROM v$log; SQL> alter system switch logfile; SQL> SELECT group#, thread#, sequence#, archived, status, first_time FROM v$log; SQL> SELECT dbid, name FROM v$database; -- be sure you save the dbid for future reference Create Repository Tablespace and Schema SQL> conn sys@repos AS SYSDBA password: ************ SQL> SELECT file_name FROM dba_data_files; SQL> SELECT name, value FROM gv$parameter WHERE name like '%block%'; SQL> CREATE TABLESPACE cat_tbs DATAFILE '/app/oracle/product/oradata/REPOS/cat_tbs.dbf' SIZE 50M AUTOEXTEND ON BLOCKSIZE 8192 FORCE LOGGING DEFAULT NOCOMPRESS EXTENT MANAGEMENT LOCAL UNIFORM SIZE 64K SEGMENT SPACE MANAGEMENT AUTO ONLINE; SQL> CREATE USER repoomega# IDENTIFIED BY oracle1 DEFAULT TABLESPACE cat_tbs TEMPORARY TABLESPACE temp QUOTA UNLIMITED ON cat_tbs; SQL> GRANT create session TO repoomega#; SQL> GRANT recovery_catalog_owner TO repoomega#; SQL> GRANT execute ON dbms_stats TO repoomega#; SQL> CREATE OR REPLACE PUBLIC SYNONYM dbms_stats FOR sys. dbms_stats; SQL> conn repoomega#/oracle1@repos SQL> SELECT COUNT(*) FROM user_objects; Create RMAN Catalog and Register the Database $ rman target / catalog repoomega#/oracle1@repos -- if the tablespace already exists: RMAN> create catalog; -- if CAT_TBS is not the default tablespace RMAN> create catalog tablespace cat_tbs; RMAN> register database; RMAN> report need backup; Explore the RMAN Catalog SQL> SELECT object_type, COUNT(*) FROM user_objects GROUP BY object_type; SQL> SELECT object_name, object_type FROM user_objects WHERE object_type IN ('FUNCTION', 'PACKAGE'); SQL> desc rc_listbackuppipe SQL> SELECT DISTINCT package_name, object_name FROM all_arguments WHERE owner = 'repoomega#' AND package_name LIKE 'DBMS%'; Configure Backup Parameters RMAN> show all; /* Enable the backup optimization feature introduced in 9i to make sure that RMAN won't backup an archivelog or datafile if there already exists a backup of that file. The FORCE option can be used to override optimization on a specific BACKUP command. */ RMAN> CONFIGURE BACKUP OPTIMIZATION ON; -- do not back up unchanged data files RMAN> CONFIGURE MAXSETSIZE TO 2 G; -- make filesize <= 2GB RMAN> CONFIGURE ENCRYPTION FOR DATABASE ON; -- encrypt backups RMAN> CONFIGURE ENCRYPTION ALGORITHM 'AES256'; -- use 256 bit encryption RMAN> CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default /* Configure the number of server processes (channels) that write backups to DISK. */ RMAN> CONFIGURE DEVICE TYPE DISK PARALLELISM 2; /* Set the retention policy to a recovery window of 30 days. This ensures that RMAN retains all backups needed to recover the database to any point in time in the last 30 days. You can use the DELETE OBSOLETE command to delete backups that are no longer required by the retention policy. To exclude a backup from consideration by the policy, you can use KEEP option with the BACKUP command. */ RMAN> CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 30 DAYS; /* Enable automatic controlfile backup after each database or archivelog backup */ RMAN> CONFIGURE CONTROLFILE AUTOBACKUP ON; RMAN> show all; Run Full Backup Need to configure a backup location. Go to NetApp but for now: $ mkdir $HOME/backup1 $ mkdir $HOME/backup2 RMAN> report need backup; RMAN> RUN { ALLOCATE CHANNEL d1 DEVICE TYPE DISK FORMAT '/home/oracle/backup1/%U'; ALLOCATE CHANNEL d2 DEVICE TYPE DISK FORMAT '/home/oracle/backup2/%U'; # AS COPY is default when backing up to disk BACKUP DATABASE PLUS ARCHIVELOG; } RMAN> report need backup; RMAN> list backup summary; SQL> ALTER SESSION SET NLS_DATE_FORMAT = 'DD-MON-YYYY HH24:MI:SS'; SQL> desc v$rman_status SQL> SELECT operation, status, mbytes_processed, start_time, end_time FROM v$rman_status; Validate Backup RMAN> crosscheck backup of database; -- need to look at data dictionary too Trash Control File and Recover $ cd /app/oracle/product/OracleHomes/oradata/orcl $ ls -la $ rm control02.ctl $ cd /app/oracle/product/OracleHomes/admin/orcl/bdump $ tail alert_orcl.log Trash Log File and Recover Error when you try to start db after copying one logfile to another (a common mistake) ORA-00341: log 1 of thread 1, wrong log # in header ORA-00312: online log 1 thread 1: '/app/oracle/product/oradata/prod/redo01.log' -- to recover alter database clear unarchived logfile group 1; alter database drop logfile group 1; -- then recreate the log file alter database add logfile group 1 ('/app/oracle/product/oradata/prod/redo01.log') SIZE 50M; |
RMAN Crosscheck
Check whether backup pieces, proxy copies, or disk copies still exist in comparison to the control file's repository. Syntax: CROSSCHECK { { BACKUP [OF listObjList] | COPY [OF listObjList] | archivelogRecordSpecifier } [maintQualifier [maintQualifier]...] | recordSpec [DEVICE TYPE deviceSpecifier [, deviceSpecifier]...] }; listObjList::= [ DATAFILE datafileSpec [, datafileSpec]... | TABLESPACE ['] tablespace_name ['] [, ['] tablespace_name [']]... | archivelogRecordSpecifier | DATABASE [SKIP TABLESPACE ['] tablespace_name ['] [, ['] tablespace_name [']]...] | CONTROLFILE | SPFILE ]... recordSpec::= { { BACKUPPIECE | PROXY } { 'media_handle' [, 'media_handle']... | primary_key [, primary_key]... | TAG [=] ['] tag_name ['] } | BACKUPSET primary_key [, primary_key]... | { CONTROLFILECOPY | DATAFILECOPY } { { primary_key [, primary_key]... | 'filename' [, 'filename']... } | TAG [=] ['] tag_name ['] [, ['] tag_name [']]... } | ARCHIVELOG { primary_key [, primary_key]... | 'filename' [, 'filename']... } } Use RMAN Crosscheck to check that files are in place ready for a restore. To validate a restore has worked, use the RMAN restore validate command. Examples: Assuming you have configured automatic channels: RMAN> CROSSCHECK BACKUP; RMAN> CROSSCHECK COPY; RMAN> CROSSCHECK backup of database; RMAN> CROSSCHECK backup of controlfile; RMAN> CROSSCHECK archivelog all; Query the media manager for the status of backup sets in a given date range: RMAN> ALLOCATE CHANNEL FOR MAINTENANCE DEVICE TYPE sbt; RMAN> CROSSCHECK BACKUP DEVICE TYPE sbt COMPLETED BETWEEN '01-AUG-04' AND '31-DEC-04'; "Wealth heaped on wealth, nor truth nor safety buys, The dangers gather as the treasures rise" - Samuel Johnson: The Vanity Of Human Wishes Related Commands: RMAN Restore Validate RMAN CHANGE - Update the status of a backup in the RMAN repository. RMAN CONFIGURE - Persistent RMAN settings. RMAN DELETE - Delete backups from disk or tape RMAN LIST - List backups and copies RMAN REPORT - Report backup status: database, files, backups NLS_DATE_FORMAT parameter |
RMAN Quick References
1-8 of 8