Looking for something? Try here..

Wednesday, May 4, 2011

CREATING A STANDBY DATABASE USING RMAN STEPS - (UNIX / LINUX)

Overview

This article provides a quick introduction on how to create an Oracle standby database using the RMAN DUPLICATE TARGET DATABASE FOR STANDBY command on the UNIX / Linux operating environment. For this demonstration, we will create a standby database using RMAN's DUPLICATE command to a different host other than the primary database.
You can use the Recovery Manager DUPLICATE TARGET DATABASE FOR STANDBY command to create a standby database. RMAN automates the following steps of the creation procedure:

  1. Restores the standby control file.
  2. Restores the primary datafile backups and copies.
  3. Optionally, RMAN recovers the standby database (after the control file has been mounted) up to the specified time or to the latest archived redo log generated.
  4. RMAN leaves the database mounted so that the user can activate it, place it in manual or managed recovery mode, or open it in read-only mode.
RMAN cannot fully automate creation of the standby database because you must manually create an initialization parameter file for the standby database, start the standby instance without mounting the control file, and perform any Oracle Net setup required before performing the creation of the standby. Also, you must have RMAN backups of all datafiles available as well as a control file backup that is usable as a standby control file.

Pre-requisites

Please refer the below link for the pre-requisites required for the creation of standby database using RMAN

Steps Required

Step 1: Create Password File for Standby Database

Login to the standby database server and create a password file:
$ orapwd file=/u01/app/oracle/product/9.2.0/dbs/orapwORA920
OR
Copy the primary database password file to the standby $ORACLE_HOME/dbs location.

Step 2: Create a Standby Controlfile

There are several ways in which to create a standby control file to be used with the standby database instance. In most cases, the easiest way is to perform this is within RMAN. Keep in mind that RMAN will need to have a copy of the standby control file within the catalog before RMAN can use it with the duplicate ... for standby command. From the target (primary) database server, use the following:
$ ORACLE_SID=ORA920; export ORACLE_SID
$ rman target /
RMAN> backup current controlfile for standby format='/orabackup/rman/ORA920/stby_cfile.%U';

Step 3: Record Last Log Sequence

You will need to specify a point in time after the creation of the standby control file. To do this, perform a few log switches and then record the last log sequence number from the v$archived_log view. From the target (primary) database instance:
SQL> alter system switch logfile;
SQL> alter system switch logfile;
SQL> select max(sequence#) from v$archived_log;
MAX(SEQUENCE#)
--------------
           208
     

Step 4: Backup New Archive Log Files

After creating the standby control file, you will need to backup the newly created archive redo logs (created from the alter system switch logfile; command above):
$ rman target /
RMAN> backup archivelog all delete input;

Step 5: Create Directory Structure on Standby (Auxiliary) Server

On the standby database server, create all needed directories for the standby database

Step 6: Create an Initialization Parameter for the Standby Database

Now, copy a version of the text initialization parameter from the target database to the standby database server and make the necessary changes for the standby database:
From the target (primary) database server:
$ export ORACLE_SID=ORA920
$ sqlplus "/ as sysdba"
SQL> create pfile='/u01/app/oracle/product/9.2.0/dbs/initORA920.ora' from spfile;
After creating and copying the initialization parameter for the standby database, change the following parameters for the standby database:
fal_client                  =
fal_server                  =
log_archive_dest_2          =
log_archive_dest_state_2    =
standby_file_management     = AUTO
 
NOTE: Keep in mind that the db_name initialization parameter of the standby database must match the db_name parameter for the primary database. This is required whether the standby database is on the same or different host from the primary database.
If you were to attempt to start two databases on the same host with the same db_name parameter, you will get the following error:
ORA-01102: Cannot mount database in exclusive mode
To get around this, you will need to modify the init.ora file of the standby database and add the parameter lock_name_space. You would set this parameter to a value different from the db_name parameter. Oracle will then use this name to lock memory segments without changing the db_name. For example,
lock_name_space=


Step 7: Start the Standby (Auxiliary) Instance

On the standby database server, start the Oracle instance in nomount mode:
$ ORACLE_SID=ORA920; export ORACLE_SID
$ sqlplus "/ as sysdba"
SQL> startup nomount
 

Step 8: Ensure Oracle Net Connectivity to Standby (Auxiliary) Database

Modify both the listener.ora and tnsnames.ora file to be able to connect to the standby (auxiliary) database.
Once the Oracle networking files are configured for the primary & the standby (auxiliary) database host, ensure to start the TNS listener with the latest (valid) listener.ora file:
$ lsnrctl stop
$ lsnrctl start
 

Step 9: Mount or Open the Target Database

As mentioned in the pre-requisites section of this article, the target database must be either opened or mounted.
$ ORACLE_SID=ORA920; export ORACLE_SID
$ sqlplus "/ as sysdba"
SQL> startup open
 

Step 10: Ensure You Have the Necessary Backups and Archived Redo Log Files

As mentioned in the pre-requisites section of this article, ensure that you have a current backup that you wish to use to create the standby database. Login to query the RMAN catalog.
RMAN> list backup summary
 

Step 11: Create Standby Database

Login to target (primary) and (standby) auxiliary database using RMAN. All of this should be performed from the target database server
Note: Notice that the parameter NOFILENAMECHECK must be used when you are duplicating a database to a different host with the same file system (directory structure)
Run the following:
$ ## primary & standby are net service names below
$ rman target sys/sys@primary auxiliary sys/sys@standby
RMAN> -- The following RUN block can be used to fully duplicate the target database from the latest full backup. 
RMAN> -- This will create the standby database:
RMAN> run {
    # Set the last log sequence number
    set until sequence = 208 thread = 1;
    # Allocate the channel for the duplicate work
    allocate auxiliary channel ch1 type disk;
    # Duplicate the database to ORA920
    duplicate target database for standby dorecover nofilenamecheck ;
}
RMAN> exit
 

Step 12: Place the Standby in Managed Recovery Mode

On the standby database, run the following:
$ sqlplus "/ as sysdba"
SQL> recover standby database;
SQL> alter database recover managed standby database disconnect;
Database altered
 
Happy Standby!! 

No comments:

Post a Comment