We have seen preparing Primary Database for Dataguard and creating Oracle network service on both sides.

In this article, we will see Physical Standby database creation and configuration using RMAN backup and restore.

Step 1: Connect to the Primary database and check if recovery area has enough space configured or not.

SQL> show parameter db_recovery

NAME				     TYPE	 VALUE
------------------------------------ ----------- ------------------------------
db_recovery_file_dest		     string	 /u01/oracle/fast_recovery_area
db_recovery_file_dest_size	     big integer 4182M
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

Step 2: Connect to RMAN and take backup :

[oracle@test1 oradata]$ rman target /

Recovery Manager: Release 11.2.0.4.0 - Production on Wed Apr 18 17:54:27 2018

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

connected to target database: TESTDB (DBID=2756866105)

RMAN> backup database plus archivelog;
Starting backup at 18-APR-18
current log archived
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=1 device type=DISK
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=2 RECID=1 STAMP=973538201
input archived log thread=1 sequence=3 RECID=2 STAMP=973791335
input archived log thread=1 sequence=4 RECID=3 STAMP=973791681
input archived log thread=1 sequence=5 RECID=4 STAMP=973791684
input archived log thread=1 sequence=6 RECID=5 STAMP=973792480
channel ORA_DISK_1: starting piece 1 at 18-APR-18
channel ORA_DISK_1: finished piece 1 at 18-APR-18
piece handle=/u01/oracle/fast_recovery_area/TESTDB/backupset/2018_04_18/o1_mf_annnn_TAG20180418T175441_ffgg8b13_.bkp tag=TAG20180418T175441 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:08
Finished backup at 18-APR-18

Starting backup at 18-APR-18
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=/u01/oracle/oradata/testdb/system01.dbf
input datafile file number=00002 name=/u01/oracle/oradata/testdb/sysaux01.dbf
input datafile file number=00003 name=/u01/oracle/oradata/testdb/undotbs01.dbf
input datafile file number=00004 name=/u01/oracle/oradata/testdb/users01.dbf
channel ORA_DISK_1: starting piece 1 at 18-APR-18
channel ORA_DISK_1: finished piece 1 at 18-APR-18
piece handle=/u01/oracle/fast_recovery_area/TESTDB/backupset/2018_04_18/o1_mf_nnndf_TAG20180418T175449_ffgg8kob_.bkp tag=TAG20180418T175449 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:05
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 18-APR-18
channel ORA_DISK_1: finished piece 1 at 18-APR-18
piece handle=/u01/oracle/fast_recovery_area/TESTDB/backupset/2018_04_18/o1_mf_ncsnf_TAG20180418T175449_ffggbswc_.bkp tag=TAG20180418T175449 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 18-APR-18

Starting backup at 18-APR-18
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=7 RECID=6 STAMP=973792563
channel ORA_DISK_1: starting piece 1 at 18-APR-18
channel ORA_DISK_1: finished piece 1 at 18-APR-18
piece handle=/u01/oracle/fast_recovery_area/TESTDB/backupset/2018_04_18/o1_mf_annnn_TAG20180418T175603_ffggbvmn_.bkp tag=TAG20180418T175603 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 18-APR-18

RMAN>

Step 3: Create standby control file from the primary database and create pfile from spfile.

SQL> ALTER DATABASE CREATE STANDBY CONTROLFILE AS '/u01/std_testdb.ctl';

Database altered.

SQL> CREATE PFILE FROM SPFILE;

File created.

Step 4: Change following parameter in pfile.

CHANGE FOLLOWING PARAMETER IN PFILE :
*.db_unique_name='std_testdb'
*.fal_server='testdb'
*.log_archive_dest_2='SERVICE=testdb ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=testdb'

Step 5: Connect to Standby database server and create necessary directories.

[oracle@localhost ~]$ mkdir -p /u01/oracle/oradata/testdb/
[oracle@localhost ~]$ mkdir -p /u01/oracle/fast_recovery_area/TESTDB/
[oracle@localhost ~]$ mkdir -p /u01/oracle/admin/testdb/adump
[oracle@localhost ~]$ mkdir -p /u01/arc/testdb/stdby

Step 6: Transfer standby control file to standby database and rename it as defined in control_files initialization parameter.

[oracle@localhost ~]$ scp 192.168.1.16:/u01/std_testdb.ctl /u01/oracle/oradata/testdb/
oracle@192.168.1.16's password: 
std_testdb.ctl                                     100% 9520KB   9.3MB/s   00:01    
[oracle@localhost ~]$ cd /u01/oracle/oradata/testdb/
[oracle@localhost testdb]$ ll
total 9520
-rw-r----- 1 oracle oinstall 9748480 Apr 18 18:11 std_testdb.ctl
[oracle@localhost testdb]$ cp std_testdb.ctl control01.tl
[oracle@localhost testdb]$ cp std_testdb.ctl control02.tl

Step 7: Transfer backup to Standby database server :

[oracle@localhost testdb]$ rsync -azvrh --progress 192.168.1.16:/u01/oracle/fast_recovery_area/TESTDB/
 /u01/oracle/fast_recovery_area/TESTDB/
oracle@192.168.1.16's password: 
receiving incremental file list
./
backupset/
backupset/2018_04_18/
backupset/2018_04_18/o1_mf_annnn_TAG20180418T175441_ffgg8b13_.bkp
      90.85M 100%    9.48MB/s    0:00:09 (xfer#1, to-check=3/8)
backupset/2018_04_18/o1_mf_annnn_TAG20180418T175603_ffggbvmn_.bkp
     494.59K 100%    2.09MB/s    0:00:00 (xfer#2, to-check=2/8)
backupset/2018_04_18/o1_mf_ncsnf_TAG20180418T175449_ffggbswc_.bkp
       9.83M 100%   18.86MB/s    0:00:00 (xfer#3, to-check=1/8)
backupset/2018_04_18/o1_mf_nnndf_TAG20180418T175449_ffgg8kob_.bkp
       1.06G 100%    8.36MB/s    0:02:01 (xfer#4, to-check=0/8)
onlinelog/

sent 102 bytes  received 275.61M bytes  1.78M bytes/sec
total size is 1.17G  speedup is 4.23
[oracle@localhost testdb]$

Step 8: Transfer pfile to standby database :

[oracle@localhost testdb]$ scp 192.168.1.16:$ORACLE_HOME/dbs/inittestdb.ora $ORACLE_HOME/dbs/
oracle@192.168.1.16's password: 
inittestdb.ora                            100% 1291     1.3KB/s   00:00    

Step 9: Transfer password file to standby database.

[oracle@localhost testdb]$ scp 192.168.1.16:$ORACLE_HOME/dbs/orapwtestdb $ORACLE_HOME/dbs/
oracle@192.168.1.16's password: 
orapwtestdb                                    100% 1536     1.5KB/s   00:00    

Step 10: Connect to Standby database and create spfile from pfile.

[oracle@localhost testdb]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Wed Apr 18 18:26:04 2018

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

Connected to an idle instance.

SQL> create spfile from pfile;

File created.

Step 11: In standby database connect to RMAN and start the database in mount stage.

[oracle@localhost testdb]$ rman target /

Recovery Manager: Release 11.2.0.4.0 - Production on Wed Apr 18 18:29:16 2018

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

connected to target database (not started)

RMAN> startup mount

Oracle instance started
database mounted

Total System Global Area     663908352 bytes

Fixed Size                     2256192 bytes
Variable Size                465568448 bytes
Database Buffers             192937984 bytes
Redo Buffers                   3145728 bytes

RMAN>

Step 12: Restore database using restore database command.

RMAN> restore database;

Starting restore at 18-APR-18
Starting implicit crosscheck backup at 18-APR-18
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=51 device type=DISK
Crosschecked 4 objects
Finished implicit crosscheck backup at 18-APR-18

Starting implicit crosscheck copy at 18-APR-18
using channel ORA_DISK_1
Finished implicit crosscheck copy at 18-APR-18

searching for all files in the recovery area
cataloging files...
no files cataloged

using channel ORA_DISK_1

channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00001 to /u01/oracle/oradata/testdb/system01.dbf
channel ORA_DISK_1: restoring datafile 00002 to /u01/oracle/oradata/testdb/sysaux01.dbf
channel ORA_DISK_1: restoring datafile 00003 to /u01/oracle/oradata/testdb/undotbs01.dbf
channel ORA_DISK_1: restoring datafile 00004 to /u01/oracle/oradata/testdb/users01.dbf
channel ORA_DISK_1: reading from backup piece /u01/oracle/fast_recovery_area/TESTDB/backupset/2018_04_18/o1_mf_nnndf_TAG20180418T175449_ffgg8kob_.bkp
channel ORA_DISK_1: piece handle=/u01/oracle/fast_recovery_area/TESTDB/backupset/2018_04_18/o1_mf_nnndf_TAG20180418T175449_ffgg8kob_.bkp tag=TAG20180418T175449
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:01:15
Finished restore at 18-APR-18

RMAN>

Step 13: Connect to SQL prompt of standby database and create redo log files.

SQL> alter system set standby_file_management=manual;

System altered.
SQL> alter database add logfile ('/u01/oracle/oradata/testdb/redo01.log') size 512m;

Database altered.

SQL> alter database add logfile ('/u01/oracle/oradata/testdb/redo02.log') size 512m;

Database altered.

SQL> alter database add logfile ('/u01/oracle/oradata/testdb/redo03.log') size 512m;

Database altered.

SQL> alter system set standby_file_management=AUTO;

System altered.

SQL>

Check Standby database synchronization with the Primary database

Step 14: Connect to the Primary database and check the role of the primary database.

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

NAME	  OPEN_MODE	       DATABASE_ROLE
--------- -------------------- ----------------
TESTDB	  READ WRITE	       PRIMARY

Step 15: Connect to Standby database and check the role of the database.

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

NAME	  OPEN_MODE	       DATABASE_ROLE
--------- -------------------- ----------------
TESTDB	  MOUNTED	       PHYSICAL STANDBY

Step 16: Check maximum archive log sequence from the primary.

SQL> select max(sequence#) from v$thread;

MAX(SEQUENCE#)
--------------
	    96

Step 17: Check maximum archive log sequence from standby database.

SQL> select max(sequence#) from v$thread;

MAX(SEQUENCE#)
--------------
	    96

Step 18: Switch logfile at primary database :

SQL> alter system switch logfile;

System altered.

Step 19: Again check max archive log sequence at the standby database.

SQL> select max(sequence#) from v$thread;

MAX(SEQUENCE#)
--------------
	    97

Physical standby database using RMAN backup restore is successfully created.

 

Stay tuned for More articles on Oracle DataGuard

Thank you for giving your valuable time to read the above information.

If you want to be updated with all our articles send us the Invitation or Follow us:

Telegram Channel: https://t.me/helporacle

Skant Gupta’s LinkedIn: www.linkedin.com/in/skantali/

Joel Perez’s LinkedIn: Joel Perez’s Profile

LinkedIn Group: Oracle Cloud DBAAS

Facebook Page: OracleHelp

About The Author

Comments

  1. Pingback: Controlfile For Standby - Manually Creating A Standby Database Using Rman €“ Dbvisit ...

  2. Pingback: Backup Controlfile For Standby - SecuredGuide

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.