January 29, 2017

RMAN in Oracle

Oracle Recovery Manager (RMAN)

RMAN was introduced in Oracle8, RMAN has since been enhanced (in Oracle 9i), enhanced (in Oracle 10g) and enhanced (in Oracle 11g
and enhanced (in Oracle 12c ).

Recovery Manager(RMAN) is an Oracle provided (free) utility for backing-up, restoring and recovering Oracle databases. RMAN ships with the Oracle database and doesn't require a separate installation. The RMAN executable is located in $ORACLE_HOME/bin directory.


RMAN is a Pro*C application that translates commands to a PL/SQL interface through RPC (Remote Procedure Call). The PL/SQL calls are statically linked into the Oracle kernel, and does not require the database to be opened (mapped from the ?/rdbms/admin/recover.bsq file).

The RMAN environment consists of the utilities and databases that play a role in backing up our data. At a minimum, the environment for RMAN must include the following:

  • The target database to be backed up.
  • The RMAN client (rman executable and recover.bsq), which interprets backup and recovery commands, directs server sessions to execute those commands, and records our backup and recovery activity in the target database control file.

Some environments will also use these optional components:
  • A recovery catalog database, a separate database schema used to record RMAN activity against one or more target databases (this is optional, but highly recommended).
  • A flash recovery area, called as fast recovery area from 11g release2, a disk location in which the database can store and manage files related to backup and recovery.
  • Media management software, required for RMAN to interface with backup devices such as tape drives.

Large pool (LARGE_POOL_SIZE) is used for RMAN.

Benefits of RMAN
Some of the benefits provided by RMAN include:

  • Backups are faster and uses less tapes (RMAN will skip empty blocks)
  • Less database archiving while database is being backed-up
  • RMAN checks the database for block corruptions
  • Automated restores from the catalog
  • Files are written out in parallel instead of sequential

RMAN can be operated from OEM (Oracle Enterprise Manager), or from command line. Here are the command line arguments:
Argument Value Description
target quoted-string connect-string for target database
catalog quoted-string connect-string for recovery catalog
nocatalog none if specified, then no recovery catalog
cmdfile quoted-string name of input command file
log quoted-string name of output message log file
trace quoted-string name of output debugging message log file
append none if specified, log is opened in append mode
debug optional-args activate debugging
msgno none show RMAN-nnnn prefix for all messages
send quoted-string send a command to the media manager
pipe string building block for pipe names
timeout integer number of seconds to wait for pipe input
checksyntaxnonecheck the command file for syntax errors

$ rman
$ rman TARGET SYS/pwd@target

$ rman TARGET SYS/pwd@target NOCATALOG
$ rman TARGET SYS/pwd@target CATALOG rman/pwd@cat
$ rman TARGET=SYS/pwd@target CATALOG=rman/pwd@cat
$ rman TARGET SYS/pwd@target LOG $ORACLE_HOME/dbs/log/rman_log.log APPEND
$ rman TARGET / CATALOG rman/pwd@cat
$ rman TARGET / CATALOG rman/pwd@cat CMDFILE cmdfile.rcv LOG outfile.txt
$ rman CATALOG rman/pwd@cat$ rman @/my_dir/my_commands.txt


Using recovery catalog
One (base) recovery catalog can manage multiple target databases. All the target databases should be register with the catalog.


Start by creating a database schema (usually named rman), in catalog database. Assign an appropriate tablespace to it and grant it the recovery_catalog_owner role.
$ sqlplus "/as sysdba"
SQL> create user rman identified by rman
default tablespace rmants quota unlimited on rmants;
SQL> grant resource, recovery_catalog_owner to rman;
No need to grant
connect role explicitly, because
recovery_catalog_owner role has it.

Log in to catalog database with rman and create the catalog.
$ rman catalog rman/rman
RMAN> create catalog;
RMAN> exit;

Now you can continue by registering your databases in the catalog.
$ rman catalog rman/rman@cat target system/manager@tgt
RMAN> register database;

Using virtual private catalog
A virtual private catalog is a set of synonyms and views that enable user access to a subset of a base recovery catalog. The owner of the base recovery catalog can GRANT or REVOKE restricted access to the catalog to other database users. Each restricted user has full read/write access to his own metadata, which is called a virtual private catalog. The RMAN metadata is stored in the schema of the virtual private catalog owner. The owner of the base recovery catalog controls what each virtual catalog user can access.

$ sqlplus "/as sysdba"
SQL> create user vpc identified by vpc
default tablespace rmants quota unlimited on rmants;
SQL> grant resource, recovery_catalog_owner to vpc;
Log in to catalog database with rman and grant the catalog to vpc.
$ rman catalog rman/rman
RMAN> GRANT CATALOG FOR DATABASE target_db TO vpc;
RMAN> exit;

Log in to catalog database with vpc and create the virtual private catalog.
$ rman catalog vpc/vpc
RMAN> CREATE VIRTUAL CATALOG;
RMAN> exit;

$ sqlplus vpc/vpc
SQL>exec rman.DBMS_RCVCAT.CREATE_VIRTUAL_CATALOG;

Recovery Manager commands

ADVISE FAILUREWill display repair options for the specified failures. 11g R1 command.
ALLOCATEEstablish a channel, which is a connection between RMAN and a database instance.
ALTER DATABASEMount or open a database.
BACKUP Backup database, tablespaces, datafiles, control files, spfile, archive logs.
BLOCKRECOVERWill recover the corrupted blocks.
CATALOGAdd information about file copies and user-managed backups to the catalog repository.
CHANGE Update the status of a backup in the RMAN repository.
CONFIGURE To change RMAN settings.
CONNECTEstablish a connection between RMAN and a target, auxiliary, or recovery catalog database.
CONVERTConvert datafile formats for transporting tablespaces and databases across platforms.
CREATE CATALOGCreate the base/virtual recovery catalog.
CREATE SCRIPTCreate a stored script and store it in the recovery catalog.
CROSSCHECK Check whether backup items still exist or not.
DELETE Delete backups from disk or tape.
DELETE SCRIPTDelete a stored script from the recovery catalog.
DROP CATALOGRemove the base/virtual recovery catalog.
DROP DATABASE Delete the target database from disk and unregisters it.
DUPLICATEUse backups of the target database to create a duplicate database that we can use for testing purposes or to create a standby database.
EXECUTE SCRIPTRun an RMAN stored script.
EXIT or QUIT Exit/quit the RMAN console.
FLASHBACK DATABASE Return the database to its state at a previous time or SCN.
GRANTGrant privileges to a recovery catalog user.
HOSTInvoke an operating system command-line subshell from within RMAN or run a specific operating system command.
IMPORT CATALOGImport the metadata from one recovery catalog into another recovery catalog.
LIST List backups and copies.
PRINT SCRIPTDisplay a stored script.
RECOVER Apply redo logs or incremental backups to a restored backup set in order to recover it to a specified time.
REGISTERRegister the target database in the recovery catalog.
RELEASE CHANNELRelease a channel that was allocated.
REPAIR FAILUREWill repair database failures identified by the Data Recovery Advisor. 11g R1 command.
REPLACE SCRIPTReplace an existing script stored in the recovery catalog. If the script does not exist, then REPLACE SCRIPT creates it.
REPORT Report backup status - database, files, backups.
RESET DATABASEInform RMAN that the SQL statement ALTER DATABASE OPEN RESETLOGS has been executed and that a new incarnation of the target database has been created, or reset the target database to a prior incarnation.
RESTORE Restore files from RMAN backup.
RESYNC CATALOGPerform a full resynchronization, which creates a snapshot control file and then copies any new or changed information from that snapshot control file to the recovery catalog.
REVOKERevoke privileges from a recovery catalog user.
RUN To run set of RMAN commands, only some RMAN commands are valid inside RUN block.
SENDSend a vendor-specific quoted string to one or more specific channels.
SET Settings for the current RMAN session.
SHOW Display the current configuration.
SHUTDOWN Shutdown the database.
SPOOLTo direct RMAN output to a log file.
SQL Execute a PL/SQL procedure or SQL statement (not SELECT).
STARTUP Startup the database.
SWITCHSpecify that a datafile copy is now the current datafile, that is, the datafile pointed to by the control file.
TRANSPORT TABLESPACE Create transportable tablespace sets from backup for one or more tablespaces.
UNREGISTERUnregister a database from the recovery catalog.
UPGRADE CATALOGUpgrade the recovery catalog schema from an older version to the version required by the RMAN executable.
VALIDATETo validate. 11g R1 command.

All RMAN commands executed through channels. A channel is a connection (session) from RMAN to target database. These connections or channels are used to perform the desired operations.


Flash/Fast Recovery Area (FRA)
Flash recovery area is a disk location in which the database can store and manage files related to backup and recovery.
To set the flash recovery area location and size, use DB_RECOVERY_FILE_DEST and DB_RECOVERY_FILE_DEST_SIZE.

RMAN new features in Oracle 10g

  • Managing recovery related files with flash recovery area.
  • Optimized incremental backups using block change tracking (Faster incremental backups) using a file (named block change tracking file). CTWR (Change Tracking Writer) is the background process responsible for tracking the blocks.
  • Reducing the time and overhead of full backups with incrementally updated backups.
  • Comprehensive backup job tracking and administration with Enterprise Manager (OEM).
  • Backup set binary compression.
  • New compression algorithm BZIP2 brought in.
  • Automated Tablespace Point-in-Time Recovery.
  • Automatic channel failover on backup & restore.
  • Cross-Platform tablespace conversion.
  • Ability to preview the backups required to perform a restore operation.
    RMAN> restore database preview [summary];
    RMAN> restore tablespace tbs1 preview;

RMAN new features in Oracle 11g Release 1
  • Multisection backups of same file - RMAN can backup or restore a single file in parallel by dividing the work among multiple channels. Each channel backs up one file section, which is a contiguous range of blocks. This speeds up overall backup and restore performance, and particularly for bigfile tablespaces, in which a datafile can be sized upwards of several hundred GB to TB's.
  • Recovery will make use of flashback logs in FRA (Flash Recovery Area).
  • Fast Backup Compression - in addition to the Oracle Database 10g backup compression algorithm (BZIP2), RMAN now supports the ZLIB algorithm, which offers 40% better performance, with a trade-off of no more than 20% lower compression ratio, versus BZIP2.
    RMAN>
    configure compression algorithm 'ZLIB' ;
  • Will backup uncommitted undo only, not committed undo.
  • Data Recovery Advisor (DRA) - quickly identify the root cause of failures; auto fix or present recovery options to the DBA.
  • Virtual Private Catalog - a recovery catalog administrator can grant visibility of a subset of registered databases in the catalog to specific RMAN users.
    RMAN>
    grant catalog for database db-name to user-name;
  • Catalogs can be merged/moved/imported from one database to another.
  • New commands in RMAN
    • RMAN> list failure;
    • RMAN> list failure errnumber detail;
    • RMAN> advise failure;
    • RMAN> repair failure;
    • RMAN> repair failure preview;
    • RMAN> validate database; -- checks for corrupted blocks
    • RMAN> create virtual catalog;

RMAN new features in Oracle 11g Release2
  • The following are new clauses and format options for the SET NEWNAME command:A single SET NEWNAME command can be applied to all files in a database or tablespace.
    SET NEWNAME FOR DATABASE TO format;
    SET NEWNAME FOR TABLESPACE tsname TO format;
  • # New format identifiers are as follows:
    # %U - Unique identifier. data_D-%d_I-%I_TS-%N_FNO-%f
    # %b - UNIX base name of the original datafile name. For example, if the original datafile name was $ORACLE_HOME/data/tbs_01.f, then %b is tbs_01.f.

RMAN related views

Control File V$ View Recovery Catalog View View Describes
V$ARCHIVED_LOG RC_ARCHIVED_LOG Archived and unarchived redo logs
V$BACKUP_DATAFILE RC_BACKUP_CONTROLFILE Control files in backup sets
V$BACKUP_CORRUPTION RC_BACKUP_CORRUPTION Corrupt block ranges in datafile backups
V$BACKUP_DATAFILE RC_BACKUP_DATAFILE Datafiles in backup sets
V$BACKUP_FILES RC_BACKUP_FILES RMAN backups and copies in the repository
V$BACKUP_PIECE RC_BACKUP_PIECE Backup pieces
V$BACKUP_REDOLOG RC_BACKUP_REDOLOG Archived logs in backups
V$BACKUP_SET RC_BACKUP_SET Backup sets
V$BACKUP_SPFILE RC_BACKUP_SPFILE Server parameter files in backup sets
V$DATAFILE_COPY RC_CONTROLFILE_COPY Control file copies on disk
V$COPY_CORRUPTION RC_COPY_CORRUPTION Information about datafile copy corruptions
V$DATABASE RC_DATABASE Databases registered in the recovery catalog (RC_DATABASE) or information about the currently mounted database (V$DATABASE)
V$DATABASE_
BLOCK_CORRUPTION
RC_DATABASE_
BLOCK_CORRUPTION
Database blocks marked as corrupt in the most recent RMAN backup or copy
V$DATABASE_INCARNATION RC_DATABASE_INCARNATION All database incarnations registered in the catalog
V$DATAFILE RC_DATAFILE All datafiles registered in the recovery catalog
V$DATAFILE_COPY RC_DATAFILE_COPY Datafile image copies
V$LOG_HISTORY RC_LOG_HISTORY Historical information about online redo logs
V$OFFLINE_RANGE RC_OFFLINE_RANGE Offline ranges for datafiles
V$PROXY_ARCHIVEDLOG RC_PROXY_ARCHIVEDLOG Archived log backups created by proxy copy
V$PROXY_CONTROLFILE RC_PROXY_CONTROLFILE Control file backups created by proxy copy
V$PROXY_DATAFILE RC_PROXY_DATAFILE Datafile backups created by proxy copy
V$LOG and V$LOGFILE RC_REDO_LOG Online redo logs for all incarnations of the database since the last catalog resynchronization
V$THREAD RC_REDO_THREAD All redo threads for all incarnations of the database since the last catalog resynchronization
V$RESTORE_POINT RC_RESTORE_POINT All restore points for all incarnations of the database since the last catalog resynchronization
- RC_RESYNC Recovery catalog resynchronizations
V$RMAN_CONFIGURATION RC_RMAN_CONFIGURATION RMAN persistent configuration settings
V$RMAN_OUTPUT RC_RMAN_OUTPUT Output from RMAN commands for use in Enterprise Manager

V$RMAN_STATUS
RC_RMAN_STATUS Historical status information about RMAN operations
V$TABLESPACE RC_TABLESPACE All tablespaces registered in the recovery catalog, all dropped tablespaces, and tablespaces that belong to old incarnations
V$TEMPFILERC_TEMPFILEAll tempfiles registered in the recovery catalog

RMAN related Packages
DBMS_RCVCAT
DBMS_RCVMAN
DBMS_BACKUP_RESTORE

4 comments:

  1. I'm really enjoying the theme/design of your blog. Do you ever run into any internet browser compatibility problems? A small number of my blog audience have complained about my website not operating correctly in Explorer but looks great in Firefox. Do you have any ideas to help fix this problem?
    Also visit my web site ... software

    ReplyDelete
  2. Thanks for splitting your comprehension with us. It’s really useful to me & I hope it helps the people who in need of this vital informationOracle Training in Tambaram

    ReplyDelete
  3. Nice explanation of the concepts , I am reading your blog from past 4 months and it helped me a lot.

    Thanks and Regards

    ReplyDelete
  4. Thanks for the blog,the way you explained is simply superb.
    Selenium training in chennai.

    ReplyDelete