Tuesday, August 25, 2009

Create Standby Database using RMAN Duplicate

On Primary:
----------

rman target /

CONFIGURE DEFAULT DEVICE TYPE TO DISK;
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/mnt/oracle/backup/%F';
CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT '/mnt/oracle/backup/backup_db_%d_S_%s_P_%p_T_%t';

Take a full backup of the database + archivelogs.

RMAN>
RUN {
ALLOCATE CHANNEL d1 DEVICE TYPE DISK FORMAT '/mnt/oracle/backup/backup_db_%d_S_%s_P_%p_T_%t';
backup database plus archivelog;
}


RMAN>
list backup summary;



1. Create Password File for Standby Database
Login to the standby database server and create a password file:

orapwd file=/apps/oracle/product/DB102/dbs/orapwSRPROD password=xxxxxx


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=SRPRODB; export ORACLE_SID

$ rman target /

RMAN> backup current controlfile for standby format='/mnt/oracle/backup/stby_cfile.%U';


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:

$ sqlplus "/ as sysdba"

SQL> alter system switch logfile;
SQL> alter system switch logfile;
SQL> select max(sequence#) from v$archived_log;

MAX(SEQUENCE#)
--------------
1216


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>
RUN {
ALLOCATE CHANNEL d1 DEVICE TYPE DISK FORMAT '/mnt/oracle/backup/backup_db_%d_S_%s_P_%p_T_%t';
backup archivelog all;
}


5. Make the RMAN Backups Available to Standby Server

/mnt/oracle/backup/


6. Create Directory Structure on Standby (Auxiliary) Server

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

mkdir /apps/oracle/admin/srprod
mkdir /apps/oracle/admin/srprod/adump
mkdir /apps/oracle/admin/srprod/bdump
mkdir /apps/oracle/admin/srprod/cdump
mkdir /apps/oracle/admin/srprod/pfile
mkdir /apps/oracle/admin/srprod/dpdump
mkdir /apps/oracle/admin/srprod/udump


7. 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=SRPROD
$ sqlplus "/ as sysdba"

SQL> create pfile='/apps/oracle/product/DB102/dbs/initSRPRODB.ora' from spfile;

File created.

After creating and copying the initialization parameter for the standby database, change at least the following parameters for the standby database:

fal_server = 'SRPRODB'
fal_client = 'SRPROD'
LOG_ARCHIVE_DEST_1= 'LOCATION=+ARCHIVE/SRPROD VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=SRPROD'
LOG_ARCHIVE_DEST_2= 'SERVICE=SRPRODB LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=SRPRODB'
log_archive_dest_state_1 = 'ENABLE'
log_archive_dest_state_2 = 'defer'
DB_FILE_NAME_CONVERT = '+DATA/SRPRODB','+DATA/SRPROD'
LOG_FILE_NAME_CONVERT= '+ARCHIVE/SRPRODB','+ARCHIVE/SRPROD'



8. Start the Standby (Auxiliary) Instance

On the standby database server, start the Oracle instance in nomount mode:

$ ORACLE_SID=SRPROD; export ORACLE_SID

$ sqlplus "/ as sysdba"

SQL> startup nomount


9. Ensure Oracle Net Connectivity to Standby (Auxiliary) Database


10. 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=SRPROD; export ORACLE_SID
$ sqlplus "/ as sysdba"
SQL> startup open


11. 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. In the following example, you will see that I not only have a full backup of the database, but now also have a backup copy of the current control file (for standby) and all archived redo logs that have been created in the above steps:

RMAN> list backup summary;



12. Create Standby Database

Login to target (primary) and (standby) auxiliary database using RMAN. All of this should be performed from the target database server. In order to perform this section, you will need the last log sequence number you recorded earlier in this article.

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:

$ rman target / auxiliary sys@srprod

OR

Run it from the standby node....

rman target sys/@srprodb AUXILIARY /


The following RUN block can be used to fully duplicate the target database from the latest full backup. This will create the standby database:

RMAN>
run {
# Set the last log sequence number
set until sequence = 1216 thread = 1;

# Allocate the channel for the duplicate work
allocate auxiliary channel ch1 type disk;

# Duplicate the database to SRPRODB
duplicate target database for standby dorecover nofilenamecheck ;
}


13. Put 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.


14. To open standby database you must activate it first:

SQL> alter database activate standby database;

SQL> alter database mount;

SQL> alter database open;


15. Verify the Log apply

SELECT SEQUENCE#, FIRST_TIME, NEXT_TIME FROM V$ARCHIVED_LOG ORDER BY SEQUENCE#;

ALTER SYSTEM SWITCH LOGFILE;

SELECT SEQUENCE#,APPLIED FROM V$ARCHIVED_LOG ORDER BY SEQUENCE#;


16. Shutting Down a Physical Standby Database

To stop Redo Apply before shutting down the database, use the following steps:

1. Issue the following query to find out if the standby database is performing Redo Apply or real-time apply.
If the MRP0 or MRP process exists, then the standby database is applying redo.

SQL> SELECT PROCESS, STATUS FROM V$MANAGED_STANDBY;

2. If Redo Apply is running, cancel it as shown in the following example:

SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;

3. Shut down the standby database.

SQL> SHUTDOWN IMMEDIATE;


17. Startup a Physical Standby Database after a clean shutdown

SQL> startup nomount

SQL> alter database mount standby database;

SQL> alter database recover managed standby database disconnect from session;


-------------------------------------------
Creating the spfile on the standby database
-------------------------------------------

set ORACLE_SID=srprod
sqlplus "/ as sysdba"

create spfile from pfile='/apps/oracle/product/DB102/dbs/initsrprod.ora';

startup nomount
alter database mount standby database;

alter database recover managed standby database disconnect from session;

No comments:

My Blog List

Search This Blog