Translate

Search This Blog

Clone the database and make standby database using RMAN in Oracle 11g

CLONE DATABSE(duplicate database): Use the DUPLICATE command to create a copy of a source database. A duplicate database, is a copy of the source database with a unique DBID which RMAN generated. Because a duplicate database has a unique DBID, it is independent of the source database and can be registered in the same recovery catalog.  Following are steps of an example where sorce(target) database and clone(duplicate or auxilary instace) are on different machines.

#1. create the oracle password file in the clone database oracle_home

orapwd file=$ORACLE_HOME/dbs/prod

#2.  Take the backup of source(target) database including control file auto backup

#3 Make tns entry for source and clone (say auxilary or target or duplicate ) instance.

#4. Prepare init file of auxilary instance
# Minimum parameters file in $ORACLE_HOME/dbs/initprod at clone oracle home.
DB_NAME=prod

If source and clone db has to be in different location then optional parameters are:
DB_FILE_NAME_CONVERT = ("+SOURCEDSK","+DUPDSK")
LOG_FILE_NAME_CONVERT = ("+SOURCEDSK","+DUPDSK")


#5. create all directories required to start the clone or duplicate database
    like directory for diag_dest,audit_file_dest etc

#6. ftp or scp copy the backups taken at step# 2  to same locations on duplicate(clone) database node.

#7. startup the clone (auxilary) instance in nomount mode at clone db node

# Backup files are in matching location to that on the source server.
# Duplicate database to TARGET's current state.
DUPLICATE TARGET DATABASE TO prod
SPFILE
NOFILENAMECHECK;

# Duplicate database to TARGET's state 4 days ago.
DUPLICATE TARGET DATABASE TO DB11G
  UNTIL TIME 'SYSDATE-4'
  SPFILE
  NOFILENAMECHECK;

# Backup files are in a different location to that on the source server.
# Duplicate database to the most recent state possible using the provided backups.
# Works with just an AUXILIARY connection only.
DUPLICATE DATABASE TO DB11G
  SPFILE
  BACKUP LOCATION '/source/app/oracle/fast_recovery_area/DB11G'
  NOFILENAMECHECK;

STANDBY DATABASE:  standby database, which is a special copy of the source database (called a primary database in a Data Guard environment) that is updated by applying archived redo logs from the primary database. A standby database does not get a new DBID.
steps for creating standby database using RMAN are similar to steps for creating duplicate(clone) database.
To create a standby database with the DUPLICATE command you must connect as target to the primary database and specify the FOR STANDBY option.

A database in a Data Guard environment is uniquely identified by means of the DB_UNIQUE_NAME parameter in the initialization parameter file. TheDB_UNIQUE_NAME must be unique across all the databases with the same DBID for RMAN to work correctly in a Data Guard environment.

Recovery of a Standby Databas By default, RMAN does not recover the standby database after creating it. RMAN leavesthe standby database mounted, but does not place the standby database in manual or managed recovery mode.

Use the DORECOVER option of the DUPLICATE command to specify that RMAN should recover the standby database. RMAN performs the following steps after creating the standby database files: 

1.RMAN begins media recovery. If recovery requires archived redo log files, and if the log files are not already on disk, then RMAN attempts to restore backups.

2. RMAN recovers the standby database to the specified time, system change number (SCN), or log file sequence number, or to the latest archived redo log file generated if none of the preceding are specified.

3. RMAN leaves the standby database mounted after media recovery is complete, but does not place the standby database in manual or managed recovery mode. 

simple example : DUPLICATE TARGET DATABASE FOR STANDBY DO RECOVER
           NOFILENAMECHECK;

NOFILENAMECHECK: prevents RMAN from checking whether the datafiles and online redo logs files of the source database are in use when the source database files share the same names as the duplicate database files (see Example 2-73). You are responsible for determining that the duplicate operation will not overwrite useful data. This option is necessary when you are creating a duplicate database in a different host that has the same disk configuration, directory structure, and filenames as the host of the source database. For example, assume that you have a small database located in the /dbs directory of host1:
/oracle/dbs/system_prod1.dbf
/oracle/dbs/users_prod1.dbf
/oracle/dbs/rbs_prod1.dbf
Assume that you want to duplicate this database to host2, which has the same file system /oracle/dbs/*, and you want to use the same filenames in the duplicate database as in the source database. In this case, specify the NOFILENAMECHECK option to avoid an error message. Because RMAN is not aware of the different hosts, RMAN cannot determine automatically that it should not check the filenames.

If duplicating a database on the same host as the source database, then make sure that NOFILENAMECHECK is not set. Otherwise, RMAN may signal the error.

Active Database Duplication: Beginning from Oracle 11g it has ability to create duplicate databases directly without the need for a backup,known as active database duplication. Its requirement is source database have to be in ARCHIVELOG mode..Both the source and destination database servers require a "tnsnames.ora" entry for the destination database.

Using the DUPLICATE Command to Create a Standby Database:
1. Creating a Standby Database with Active Database Duplication  (available from 11g)

DUPLICATE TARGET DATABASE
  FOR STANDBY
  FROM ACTIVE DATABASE
  DORECOVER
  SPFILE
    SET "db_unique_name"="foou" COMMENT ''Is a duplicate''
    SET LOG_ARCHIVE_DEST_2="service=inst3 ASYNC REGISTER
     VALID_FOR=(online_logfile,primary_role)"
    SET FAL_CLIENT="inst3" COMMENT "Is standby"
    SET FAL_SERVER="inst1" COMMENT "Is primary"

  NOFILENAMECHECK;

2. Creating a Standby Database with Backup-Based Duplication

DUPLICATE TARGET DATABASE
  FOR STANDBY
  DORECOVER
  SPFILE
    SET "db_unique_name"="foou" COMMENT ''Is a duplicate''
    SET LOG_ARCHIVE_DEST_2="service=inst3 ASYNC REGISTER
     VALID_FOR=(online_logfile,primary_role)"
    SET FAL_CLIENT="inst3" COMMENT "Is standby"
    SET FAL_SERVER="inst1" COMMENT "Is primary"
  NOFILENAMECHECK;

Other examples:

Copying the Server Parameter File in Active Database Duplication

RMAN> CONNECT TARGET SYS@prod

target database Password: password
connected to target database: PROD1 (DBID=39525561)

RMAN> CONNECT AUXILIARY SYS@dup

auxiliary database Password: password
connected to auxiliary database: DUP1 (not mounted)

RMAN> DUPLICATE TARGET DATABASE TO dup
2> FROM ACTIVE DATABASE
3> PASSWORD FILE
4> SPFILE;

Setting New Filenames Manually for Duplication:

DUPLICATE TARGET DATABASE TO dup
  FOR STANDBY
  FROM ACTIVE DATABASE
  PASSWORD FILE
  SPFILE 
    PARAMETER_VALUE_CONVERT '/disk1', '/disk2'
    SET DB_FILE_NAME_CONVERT '/disk1','/disk2'
    SET LOG_FILE_NAME_CONVERT '/disk1','/disk2'
    SET SGA_MAX_SIZE 200M
    SET SGA_TARGET 125M;

references: oracle doc1
                 oracle doc2
                 oracle base
                      

Follow by Email