Saturday, July 7, 2018

Create Oracle Standby using RMAN duplicate command

1. changes on primary

SQL> ALTER DATABASE FORCE LOGGING;

SQL> alter system set remote_login_passwordfile='EXCLUSIVE' scope=spfile;

SQL> alter system set log_archive_config='dg_config=(p1c3d41,p1c3d65)' scope=both;

SQL> alter system set log_archive_dest_2='SERVICE=p1c3d65 ARCH NOAFFIRM ASYNC valid_for=(ONLINE_LOGFILES,PRIMARY_ROLE) db_unique_name=p1c3d65' scope=both;

SQL> alter system set log_archive_dest_state_2='defer' scope=both;

SQL> alter system set db_file_name_convert='/opt/app/p1c3d65/oradata01/p1c3d65','/opt/app/p1c3d41/oradata01/p1c3d41' scope=spfile;

SQL> alter system set log_file_name_convert ='/opt/app/p1c3d65/redo01_ora/p1c3d65','/opt/app/p1c3d41/redo01_ora/p1c3d41','/opt/app/p1c3d65/redo02_ora/p1c3d65','/opt/app/p1c3d41/redo02_ora/p1c3d41' scope=spfile;

SQL> alter system set fal_server='p1c3d65' scope=both;

SQL> alter system set fal_client='p1c3d41' scope=both;

SQL> alter system set STANDBY_FILE_MANAGEMENT=AUTO scope=both;

SQL> ALTER DATABASE ADD STANDBY LOGFILE group 4 ('/opt/app/p1c3d65/redo01_ora/p1c3d65/standby_redo04a.log','/opt/app/p1c3d65/redo02_ora/p1c3d65/standby_redo04b.log') SIZE 50M;

SQL> ALTER DATABASE ADD STANDBY LOGFILE group 5 ('/opt/app/p1c3d65/redo01_ora/p1c3d65/standby_redo05a.log','/opt/app/p1c3d65/redo02_ora/p1c3d65/standby_redo05b.log') SIZE 50M;

SQL> ALTER DATABASE ADD STANDBY LOGFILE group 6 ('/opt/app/p1c3d65/redo01_ora/p1c3d65/standby_redo06a.log','/opt/app/p1c3d65/redo02_ora/p1c3d65/standby_redo06b.log') SIZE 50M;

SQL> ALTER DATABASE ADD STANDBY LOGFILE group 7 ('/opt/app/p1c3d65/redo01_ora/p1c3d65/standby_redo07a.log','/opt/app/p1c3d65/redo02_ora/p1c3d65/standby_redo07b.log') SIZE 50M;

2. add standby tns entry on primary & primary tns entry on standby

3. Parameters on standby in pfile

*.db_file_name_convert='/opt/app/p1c3d41/oradata01/p1c3d41','/opt/app/p1c3d65/oradata01/p1c3d65'

*.db_name='p1c3d41'

*.db_unique_name='p1c3d65'

*.fal_server='p1c3d41'

*.fal_client='p1c3d65'

*.log_archive_config='dg_config=(p1c3d41,p1c3d65)'

*.log_archive_dest_2='SERVICE=p1c3d41 ARCH NOAFFIRM ASYNC valid_for=(ONLINE_LOGFILES,PRIMARY_ROLE) db_unique_name=p1c3d41'

*.log_file_name_convert='/opt/app/p1c3d41/redo01_ora/p1c3d41','/opt/app/p1c3d65/redo01_ora/p1c3d65','/opt/app/p1c3d41/redo02_ora/p1c3d41','/opt/app/p1c3d65/redo02_ora/p1c3d65'

*.remote_login_passwordfile='EXCLUSIVE'

*.standby_file_management='AUTO'

4. Change password of sys user & create password file on primary

orapwd file=orapwp1c3d41 password=testing123 entries=30

copy to /tmp & change permission of /tmp/orapwp1c3d41 to 644

from standby server scp the /tmp/orapwp1c3d41 to $ORACLE_HOME/dbs

rename file to orapwp1c3d65 & change permission to 640

5. standby database startup nomount with pfile

from primary check you can login to standby database as sysdba

$ sqlplus sys/Testing123@p1c3d65.db.att.com as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Wed Nov 25 18:30:38 2017

Copyright (c) 1982, 2013, Oracle.  All rights reserved.

Connected to:

Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> exit

6. on primary run rman duplicate as below

connect target sys/Testing123@p1c3d41;

connect auxiliary sys/Testing123@p1c3d65;

run {
allocate channel pr1 type disk;
allocate channel pr2 type disk;
allocate channel pr3 type disk;
allocate auxiliary channel st1 type disk;
duplicate target database for standby from active database;
}

output as below (I had not added standby redo logfile on primary so I suppose its not showing for below output, will try next time if its replicated automatically)

$ rman

Recovery Manager: Release 11.2.0.4.0 - Production on Wed Nov 25 19:40:56 2017

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

RMAN> connect target sys/Testing123@p1c3d41;

connected to target database: P1C3D41 (DBID=262096110)

RMAN> connect auxiliary sys/Testing123@p1c3d65;

connected to auxiliary database: P1C3D41 (not mounted)

RMAN> run {
allocate channel pr1 type disk;
allocate channel pr2 type disk;
allocate channel pr3 type disk;
allocate auxiliary channel st1 type disk;
duplicate target database for standby from active database;

}2> 3> 4> 5> 6> 7> 8>

using target database control file instead of recovery catalog
allocated channel: pr1
channel pr1: SID=12 device type=DISK
allocated channel: pr2
channel pr2: SID=25 device type=DISK
allocated channel: pr3
channel pr3: SID=8 device type=DISK
allocated channel: st1
channel st1: SID=50 device type=DISK
Starting Duplicate Db at 25-NOV-17

contents of Memory Script:
{
   backup as copy reuse

   targetfile  '/opt/app/p1c3d41/oracle/product/p1c3d41/dbs/orapwp1c3d41' auxiliary format

'/opt/app/p1c3d65/oracle/product/p1c3d65/dbs/orapwp1c3d65'   ;

}

executing Memory Script

Starting backup at 25-NOV-17

Finished backup at 25-NOV-17

contents of Memory Script:
{
   backup as copy current controlfile for standby auxiliary format  '/opt/app/p1c3d65/redo01_ora/p1c3d65/control_01.ctl';
   restore clone primary controlfile to  '/opt/app/p1c3d65/redo02_ora/p1c3d65/control_02.ctl' from
'/opt/app/p1c3d65/redo01_ora/p1c3d65/control_01.ctl';
   restore clone primary controlfile to  '/opt/app/p1c3d65/redo01_ora/p1c3d65/control_03.ctl' from
'/opt/app/p1c3d65/redo01_ora/p1c3d65/control_01.ctl';
}
executing Memory Script

Starting backup at 25-NOV-17

channel pr1: starting datafile copy

copying standby control file

output file name=/opt/app/p1c3d41/oracle/product/p1c3d41/dbs/snapcf_p1c3d41.f tag=TAG20171125T150110 RECID=1 STAMP=85457842

channel pr1: datafile copy complete, elapsed time: 00:00:15

Finished backup at 25-NOV-17

Starting restore at 25-NOV-17

channel st1: copied control file copy

Finished restore at 25-NOV-17

Starting restore at 25-NOV-17

channel st1: copied control file copy

Finished restore at 25-NOV-17

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
"/opt/app/p1c3d65/oradata01/p1c3d65/temp_01.dbf";
   switch clone tempfile all;
   set newname for datafile  1 to
"/opt/app/p1c3d65/oradata01/p1c3d65/system_01.dbf";
   set newname for datafile  2 to
"/opt/app/p1c3d65/oradata01/p1c3d65/sysaux_01.dbf";
   set newname for datafile  3 to
"/opt/app/p1c3d65/oradata01/p1c3d65/undo_01.dbf";
   set newname for datafile  4 to
"/opt/app/p1c3d65/oradata01/p1c3d65/tools_01.dbf";
   set newname for datafile  5 to
"/opt/app/p1c3d65/oradata01/p1c3d65/users_01.dbf";
   set newname for datafile  6 to
"/opt/app/p1c3d65/oradata01/p1c3d65/linkmanagerts_01.dbf";
   backup as copy reuse
   datafile  1 auxiliary format
"/opt/app/p1c3d65/oradata01/p1c3d65/system_01.dbf"   datafile
2 auxiliary format

"/opt/app/p1c3d65/oradata01/p1c3d65/sysaux_01.dbf"   datafile

3 auxiliary format

"/opt/app/p1c3d65/oradata01/p1c3d65/undo_01.dbf"   datafile

4 auxiliary format

"/opt/app/p1c3d65/oradata01/p1c3d65/tools_01.dbf"   datafile

5 auxiliary format

"/opt/app/p1c3d65/oradata01/p1c3d65/users_01.dbf"   datafile

6 auxiliary format

"/opt/app/p1c3d65/oradata01/p1c3d65/linkmanagerts_01.dbf"   ;
   sql 'alter system archive log current';
}

executing Memory Script

executing command: SET NEWNAME

renamed tempfile 1 to /opt/app/p1c3d65/oradata01/p1c3d65/temp_01.dbf in control file

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

Starting backup at 25-NOV-17

channel pr1: starting datafile copy

input datafile file number=00006 name=/opt/app/p1c3d41/oradata01/p1c3d41/linkmanagerts_01.dbf

channel pr2: starting datafile copy

input datafile file number=00001 name=/opt/app/p1c3d41/oradata01/p1c3d41/system_01.dbf

channel pr3: starting datafile copy

input datafile file number=00002 name=/opt/app/p1c3d41/oradata01/p1c3d41/sysaux_01.dbf

channel pr1: starting datafile copy

input datafile file number=00003 name=/opt/app/p1c3d41/oradata01/p1c3d41/undo_01.dbf

output file name=/opt/app/p1c3d65/oradata01/p1c3d65/sysaux_01.dbf tag=TAG20171125T150220

channel pr3: datafile copy complete, elapsed time: 00:00:35

channel pr3: starting datafile copy

input datafile file number=00004 name=/opt/app/p1c3d41/oradata01/p1c3d41/tools_01.dbf

output file name=/opt/app/p1c3d65/oradata01/p1c3d65/undo_01.dbf tag=TAG20171125T150220

channel pr2: datafile copy complete, elapsed time: 00:00:54

channel pr2: starting datafile copy

input datafile file number=00005 name=/opt/app/p1c3d41/oradata01/p1c3d41/users_01.dbf

output file name=/opt/app/p1c3d65/oradata01/p1c3d65/system_01.dbf tag=TAG20171125T150220

channel pr2: datafile copy complete, elapsed time: 00:00:46

output file name=/opt/app/p1c3d65/oradata01/p1c3d65/tools_01.dbf tag=TAG20171125T150220

channel pr3: datafile copy complete, elapsed time: 00:00:38

output file name=/opt/app/p1c3d65/oradata01/p1c3d65/users_01.dbf tag=TAG20171125T150220

channel pr2: datafile copy complete, elapsed time: 00:00:36

output file name=/opt/app/p1c3d65/oradata01/p1c3d65/linkmanagerts_01.dbf tag=TAG20171125T150220

channel pr1: datafile copy complete, elapsed time: 00:01:35

Finished backup at 25-NOV-17

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=325494913 file name=/opt/app/p1c3d65/oradata01/p1c3d65/system_01.dbf

datafile 2 switched to datafile copy

input datafile copy RECID=2 STAMP=325494913 file name=/opt/app/p1c3d65/oradata01/p1c3d65/sysaux_01.dbf

datafile 3 switched to datafile copy

input datafile copy RECID=3 STAMP=325494913 file name=/opt/app/p1c3d65/oradata01/p1c3d65/undo_01.dbf

datafile 4 switched to datafile copy

input datafile copy RECID=4 STAMP=325494913 file name=/opt/app/p1c3d65/oradata01/p1c3d65/tools_01.dbf

datafile 5 switched to datafile copy

input datafile copy RECID=5 STAMP=325494913 file name=/opt/app/p1c3d65/oradata01/p1c3d65/users_01.dbf

datafile 6 switched to datafile copy

input datafile copy RECID=6 STAMP=325494913 file name=/opt/app/p1c3d65/oradata01/p1c3d65/linkmanagerts_01.dbf

Finished Duplicate Db at 25-NOV-17

released channel: pr1

released channel: pr2

released channel: pr3

released channel: st1

RMAN> exit

Recovery Manager complete.

check on standby that database is mounted

SQL> select name,open_mode,database_role from v$database;


NAME      OPEN_MODE            DATABASE_ROLE

--------- -------------------- ----------------

P1C3D41   MOUNTED              PHYSICAL STANDBY

7. On primary enable log_archive_dest_2 & switch logfile to check that standby is receiving the archivelogs.

SQL> alter system set log_archive_dest_state_2='enable' scope=both;

System altered.

SQL> alter system switch logfile;

System altered.

8. check on standby & then start managed recovery

SQL>  SELECT PROCESS, STATUS, SEQUENCE#, BLOCK#, BLOCKS FROM V$MANAGED_STANDBY;

PROCESS   STATUS        SEQUENCE#     BLOCK#     BLOCKS

--------- ------------ ---------- ---------- ----------

ARCH      CONNECTED             0          0          0

ARCH      CONNECTED             0          0          0

ARCH      CONNECTED             0          0          0

ARCH      CONNECTED             0          0          0

RFS       IDLE                  0          0          0

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

Database altered.

SQL> SELECT PROCESS, STATUS, SEQUENCE#, BLOCK#, BLOCKS FROM V$MANAGED_STANDBY;

PROCESS   STATUS        SEQUENCE#     BLOCK#     BLOCKS

--------- ------------ ---------- ---------- ----------

ARCH      CONNECTED             0          0          0

ARCH      CONNECTED             0          0          0

ARCH      CONNECTED             0          0          0

ARCH      CONNECTED             0          0          0

RFS       IDLE                  0          0          0

RFS       IDLE                  0          0          0

RFS       IDLE                  0          0          0

MRP0      WAIT_FOR_LOG         39          0          0

switch 4-5 logfiles on primary to check standby is receiving & applying.

9. stop managed recovery on standby & add standby redo logfiles if not added in 1st step or not recreated on standby database as below.

SQL> alter database recover managed standby database cancel;

SQL> ALTER DATABASE ADD STANDBY LOGFILE group 4 ('/opt/app/p1c3d65/redo01_ora/p1c3d65/standby_redo04a.log','/opt/app/p1c3d65/redo02_ora/p1c3d65/standby_redo04b.log') SIZE 50M;

SQL> ALTER DATABASE ADD STANDBY LOGFILE group 5 ('/opt/app/p1c3d65/redo01_ora/p1c3d65/standby_redo05a.log','/opt/app/p1c3d65/redo02_ora/p1c3d65/standby_redo05b.log') SIZE 50M;

SQL> ALTER DATABASE ADD STANDBY LOGFILE group 6 ('/opt/app/p1c3d65/redo01_ora/p1c3d65/standby_redo06a.log','/opt/app/p1c3d65/redo02_ora/p1c3d65/standby_redo06b.log') SIZE 50M;

SQL> ALTER DATABASE ADD STANDBY LOGFILE group 7 ('/opt/app/p1c3d65/redo01_ora/p1c3d65/standby_redo07a.log','/opt/app/p1c3d65/redo02_ora/p1c3d65/standby_redo07b.log') SIZE 50M;

10. open standby database & start managed recovery using current logfile

SQL> alter database open;

Database altered.

SQL> select name,open_mode,database_role from v$database;

NAME      OPEN_MODE            DATABASE_ROLE

--------- -------------------- ----------------

P1C3D41   READ ONLY            PHYSICAL STANDBY

SQL> alter database recover managed standby database using current logfile disconnect;

Database altered.

SQL> SELECT PROCESS, STATUS, SEQUENCE#, BLOCK#, BLOCKS FROM V$MANAGED_STANDBY;

PROCESS   STATUS        SEQUENCE#     BLOCK#     BLOCKS

--------- ------------ ---------- ---------- ----------

ARCH      CONNECTED             0          0          0

ARCH      CONNECTED             0          0          0

ARCH      CONNECTED             0          0          0

ARCH      CONNECTED             0          0          0

RFS       IDLE                  0          0          0

RFS       IDLE                  0          0          0

RFS       IDLE                  0          0          0

MRP0      WAIT_FOR_LOG         42          0          0

8 rows selected.

switch 4-5 logfiles on primary to check they are applying.

create spfile for standby and startup standby with spfile

Dataguard configuration is complete.
All the best!

No comments:

Post a Comment