Friday 3 October 2014

Setting up a physical standby in Oracle 12C


Setting up a physical standby in Oracle 12C

In our configuration we will have primary database as PROD1 and physical standby as DR1

## Making changes to the primary environment

SQL> alter system set log_archive_config='dg_config=(prod1,dr1)' ;

System altered.

SQL> alter system set log_archive_dest_1='location=USE_DB_RECOVERY_FILE_DEST valid_for=(all_roles,all_logfiles) db_unique_name=prod1' ;

System altered.

SQL> alter system set log_archive_dest_2='service=dr1 valid_for=(primary_roles,online_logfiles) db_unique_name=dr1' ;

System altered.

SQL> alter system set fal_client=prod1;

System altered.

SQL> alter system set fal_server=dr1 ;

System altered.

SQL> alter system set db_file_name_convert='/u01/app/oracle/oradata/dr1','/u01/app/oracle/oradata/prod1' scope=spfile;

System altered.

SQL> alter system set log_file_name_convert='/u01/app/oracle/oradata/dr1','/u01/app/oracle/oradata/prod1' scope=spfile;

System altered.

SQL> alter system set standby_file_management=auto ;

System altered.

## Making changes to the standby environment

SQL> alter system set log_archive_config='dg_config=(prod1,dr1)' ;

System altered.

SQL> alter system set log_archive_dest_1='location=USE_DB_RECOVERY_FILE_DEST valid_for=(all_roles,all_logfiles) db_unique_name=dr1' ;

System altered.

SQL> alter system set log_archive_dest_2='service=prod1 valid_for=(primary_roles,online_logfiles) db_unique_name=prod1' ;

System altered.

SQL> alter system set fal_client=dr1;

System altered.

SQL> alter system set fal_server=prod1 ;

System altered.

SQL> alter system set db_file_name_convert='/u01/app/oracle/oradata/prod1','/u01/app/oracle/oradata/dr1' scope=spfile;

System altered.

SQL> alter system set log_file_name_convert='/u01/app/oracle/oradata/prod1','/u01/app/oracle/oradata/dr1' scope=spfile;

System altered.

SQL> alter system set standby_file_management=auto ;

System altered.

__________________

## Below are tns entries

PROD1 =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = hostname of primary)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = prod1)
    )
  )


DR1 =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = hostname of standby)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = dr1)
    )
  )

## Appropriate directories and Password files are also in place

[oracle@node4 ~]$ ls -ld /u01/app/oracle/oradata/dr1
drwxr-xr-x 2 oracle oinstall 4096 Oct  2 16:49 /u01/app/oracle/oradata/dr1


[oracle@node4 ~]$ ls -ltr /u01/app/oracle/product/12.1.0/dbhome_1/dbs/orapwdr1
-rw-r----- 1 oracle oinstall 7680 Oct  2 16:45 /u01/app/oracle/product/12.1.0/dbhome_1/dbs/orapwdr1

[oracle@node4 ~]$ ls -ltr /u01/app/oracle/product/12.1.0/dbhome_1/dbs/orapwprod1
-rw-r----- 1 oracle oinstall 7680 Oct  2 16:19 /u01/app/oracle/product/12.1.0/dbhome_1/dbs/orapwprod1


[oracle@node4 ~]$ rman target/

Recovery Manager: Release 12.1.0.1.0 - Production on Thu Oct 2 16:44:16 2014

Copyright (c) 1982, 2013, Oracle and/or its affiliates.  All rights reserved.

connected to target database: PROD1 (DBID=2081254351)

RMAN> connect auxiliary sys@dr1

auxiliary database Password:
connected to auxiliary database: PROD1 (not mounted)

RMAN> duplicate target database for standby from active database;

Starting Duplicate Db at 02-OCT-14
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of Duplicate Db command at 10/02/2014 16:44:47
RMAN-05501: aborting duplication of target database
RMAN-05609: Must specify a username for target connection when using active duplicate

RMAN> exit


Recovery Manager complete.
[oracle@node4 ~]$ rman target sys@prod1 auxiliary sys@dr1

Recovery Manager: Release 12.1.0.1.0 - Production on Thu Oct 2 16:44:59 2014

Copyright (c) 1982, 2013, Oracle and/or its affiliates.  All rights reserved.

target database Password:
connected to target database: PROD1 (DBID=2081254351)
auxiliary database Password:
connected to auxiliary database: PROD1 (not mounted)

RMAN> duplicate target database for standby from active database;

Starting Duplicate Db at 02-OCT-14
using target database control file instead of recovery catalog
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=22 device type=DISK

contents of Memory Script:
{
   backup as copy reuse
   targetfile  '/u01/app/oracle/product/12.1.0/dbhome_1/dbs/orapwprod1' auxiliary format
 '/u01/app/oracle/product/12.1.0/dbhome_1/dbs/orapwdr1'   ;
}
executing Memory Script

Starting backup at 02-OCT-14
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=52 device type=DISK
Finished backup at 02-OCT-14

contents of Memory Script:
{
   restore clone from service  'prod1' standby controlfile;
}
executing Memory Script

Starting restore at 02-OCT-14
using channel ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service prod1
channel ORA_AUX_DISK_1: restoring control file
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:03
output file name=/u01/app/oracle/oradata/dr1/control01.ctl
output file name=/u01/app/oracle/fast_recovery_area/dr1/control02.ctl
Finished restore at 02-OCT-14

contents of Memory Script:
{
   sql clone 'alter database mount standby database';
}
executing Memory Script

sql statement: alter database mount standby database

contents of Memory Script:
{
   set newname for tempfile  1 to
 "/u01/app/oracle/oradata/dr1/temp01.dbf";
   switch clone tempfile all;
   set newname for datafile  1 to
 "/u01/app/oracle/oradata/dr1/system01.dbf";
   set newname for datafile  2 to
 "/u01/app/oracle/oradata/dr1/example01.dbf";
   set newname for datafile  3 to
 "/u01/app/oracle/oradata/dr1/sysaux01.dbf";
   set newname for datafile  4 to
 "/u01/app/oracle/oradata/dr1/undotbs01.dbf";
   set newname for datafile  6 to
 "/u01/app/oracle/oradata/dr1/users01.dbf";
   restore
   from service  'prod1'   clone database
   ;
   sql 'alter system archive log current';
}
executing Memory Script

executing command: SET NEWNAME

renamed tempfile 1 to /u01/app/oracle/oradata/dr1/temp01.dbf in control file

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

Starting restore at 02-OCT-14
using channel ORA_AUX_DISK_1

channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service prod1
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00001 to /u01/app/oracle/oradata/dr1/system01.dbf
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:36
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service prod1
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00002 to /u01/app/oracle/oradata/dr1/example01.dbf
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:16
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service prod1
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/dr1/sysaux01.dbf
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:35
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service prod1
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/dr1/undotbs01.dbf
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:03
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: using network backup set from service prod1
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00006 to /u01/app/oracle/oradata/dr1/users01.dbf
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 02-OCT-14

sql statement: alter system archive log current

contents of Memory Script:
{
   switch clone datafile all;
}
executing Memory Script

datafile 1 switched to datafile copy
input datafile copy RECID=1 STAMP=859913214 file name=/u01/app/oracle/oradata/dr1/system01.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=2 STAMP=859913214 file name=/u01/app/oracle/oradata/dr1/example01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=3 STAMP=859913214 file name=/u01/app/oracle/oradata/dr1/sysaux01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=4 STAMP=859913214 file name=/u01/app/oracle/oradata/dr1/undotbs01.dbf
datafile 6 switched to datafile copy
input datafile copy RECID=5 STAMP=859913214 file name=/u01/app/oracle/oradata/dr1/users01.dbf
Finished Duplicate Db at 02-OCT-14

RMAN> exit


Recovery Manager complete.

## Login to the standby database

SQL>  recover managed standby database disconnect;
Media recovery complete.

SQL> @arch

 SEQUENCE# ARCHIVED APPLIED   COMPLETION_TIME
---------- ------------ --------------------
         7 YES YES       02-oct-2014 16:50:14
         8 YES YES       02-oct-2014 16:50:17


No comments:

Post a Comment