Create a Standby Instance Using RMAN

Use Oracle Recovery Manager (RMAN) to create a standby cloud instance from the primary database.

Create an Archive Log

Check the log mode of your on-premises Oracle server. If it's in NOARCHIVELOG mode, then change it to ARCHIVELOG mode to create an archive log.

  1. View the log mode for the on-premises server.
    SQL> select log_mode from v$database;
    The output will look similar to the following when the log mode is in NOARCHIVELOG mode:
    LOG_MODE
    ------------
    NOARCHIVELOG
  2. Shut down the on-premises instance.
    SQL> shutdown immediate;
    The output will look similar to the following:
    Database closed.
    Database dismounted.
    ORACLE instance shut down.
  3. Mount the on-premises database.
    SQL> startup mount;
    The output will look similar to the following:
    ORACLE instance started.
    
    Total System Global Area 4966054520 bytes
    Fixed Size		    9144952 bytes
    Variable Size		  922746880 bytes
    Database Buffers	 4026531840 bytes
    Redo Buffers		    7630848 bytes
    Database mounted.
  4. Alter the database archive log, then open the database.
    SQL> alter database archivelog;
    SQL> alter database open;
  5. Change the log mode to ARCHIVELOG.
    SQL> select log_mode from v$database;
    LOG_MODE
    ------------
    ARCHIVELOG
  6. Display the archive log list.
    SQL> archive log list;
    The output will look similar to the following:
    Database log mode	       Archive Mode
    Automatic archival	       Enabled
    Archive destination	       /opt/oracle/product/19c/dbhome_1/dbs/arch
    Oldest online log sequence     10
    Next log sequence to archive   12
    Current log sequence	       12
  7. Archive all logs.
    SQL> archive log all;
    ORA-00271:there are no logs that need archiving

Instantiate the Standby Database on OCI

Use Oracle Recovery Manager (RMAN) to duplicate the active primary database on Oracle Cloud Infrastructure (OCI). Alternatively, you can duplicate from a backup of the primary database.

  1. Stop the database using the srvctl utility or shutdown the database using SQL*Plus.
    • $ srvctl stop database -d standby DB_UNIQUE_NAME -o immediate
    • Shutdown immediate;
  2. Connect to the database.
    $ rman target /
    RMAN> startup nomount;
  3. Restore the standby control file from the primary service.
    In this example, ORCLCDB is the primary, on-premises database.
    RMAN> restore standby controlfile from service 'ORCLCDB';
  4. If the following error messages appear, then reconnect to the database.
    RMAN-00571: ===========================================================
    RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
    RMAN-00571: ===========================================================
    RMAN-03002: failure of restore command at 09/24/2020 21:10:13
    RMAN-06496: must use the TO clause when the database is mounted or open
    1. Shut down the database
      RMAN> shutdown;
    2. Connect to the database
      RMAN> startup nomount;
  5. Restore using the database control file instead of the recovery catalog.
    RMAN> restore standby controlfile from service 'ORCLCDB';
    The output will look similar to the following:
    Starting restore at DD-MM-YY
    using target database control file instead of recovery catalog
    allocated channel: ORA_DISK_1
    channel ORA_DISK_1: SID=182 device type=DISK 
    channel ORA_DISK_1: starting datafile backup set restore
    channel ORA_DISK_1: using network backup set from service ORCLCDB
    channel ORA_DISK_1: restoring control file
    channel ORA_DISK_1: restore complete, elapsed time: 00:00:02
    output file name=/u02/app/oracle/oradata/ORCLCDB_iad1s3/control01.ctl
    output file name=/u03/app/oracle/fast_recovery_area/ORCLCDB_IAD1S3/control02.ctl
    Finished restore at DD-MM-YY
  6. Mount the database.
    RMAN> alter database mount;
  7. If an error messages similar to the following appears, then reconnect to the database.
    If you don't get an error message, go to Step 8.
    Released channel: ORA_DISK_1
    RMAN-00571: ===========================================================
    RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
    RMAN-00571: ===========================================================
    RMAN-03002: failure of sql statement command at 09/24/2020 21:13:41
    RMAN-06189: current DBID 2822997440 does not match target mounted database (2823031995)
    1. Shut down the database
      RMAN> shutdown immediate;
      The output will look similar to the following:
      database dismounted
      Oracle instance shutdown
    2. Connect to the database
      RMAN> startup nomount;
      The output will look similar to the following:
      connected to target database (not started)
      Oracle instance startedTotal System Global Area 14495511760 bytesFixed Size 9151696 bytes
      Variable Size 1912602624 bytes
      Database Buffers 12549357568 bytes
      Redo Buffers 24399872 bytes
    3. Set the database identifier.
      RMAN> set DBID=2823031995;
      The output will look similar to the following:
      executing command: SET DBID
  8. As root on the OCI instance, change the permissions of the Oracle directory to open (chmod 777).
    [root@drdb opc]# sudo su
    [root@drdb opc]# cd /opt/
    [root@drdb opt]# ls -lrt
    total 8
    drwx------ 7 root root 4096 Sep 12 00:39 zookeeper
    drwxr-xr-x 6 root root 4096 Sep 12 00:51 oracle
    [root@drdb opt]# chmod 777 oracle/
    [root@drdb opt]# ls -lrt
    total 8
    drwx------ 7 root root 4096 Sep 12 00:39 zookeeper
    drwxrwxrwx 6 root root 4096 Sep 12 00:51 oracle
  9. Restore the database from the primary database (ORCLCDB).
    RMAN> restore database from service 'ORCLCDB' section size 5G;
    After the crosscheck backup and crosscheck copy are completed, a list of cataloged files appears in the output, similar to the following:
    Starting restore at 01-SEP-20
    Starting implicit crosscheck backup at 01-SEP-20
    allocated channel: ORA_DISK_1
    channel ORA_DISK_1: SID=184 device type=DISK
    Finished implicit crosscheck backup at 01-SEP-20
    
    Starting implicit crosscheck copy at 01-SEP-20
    using channel ORA_DISK_1
    Finished implicit crosscheck copy at 01-SEP-20
    
    searching for all files in the recovery area
    cataloging files...
    cataloging done
    
    List of Cataloged Files
    =======================
    File Name: /u03/app/oracle/fast_recovery_area/ORCLCDB_IAD1S3/archivelog/2020_08_27/o1_mf_1_3_hngo1gl6_.arc
    File Name: /u03/app/oracle/fast_recovery_area/ORCLCDB_IAD1S3/archivelog/2020_08_27/o1_mf_1_1_hngnvtgb_.arc
    File Name: /u03/app/oracle/fast_recovery_area/ORCLCDB_IAD1S3/archivelog/2020_08_27/o1_mf_1_2_hngnwdfd_.arc
    
    using channel ORA_DISK_1
    
    channel ORA_DISK_1: starting datafile backup set restore
    channel ORA_DISK_1: using network backup set from service ORCLCDB
    channel ORA_DISK_1: specifying datafile(s) to restore from backup set
    channel ORA_DISK_1: restoring datafile 00001 to /opt/oracle/oradata/ORCLCDB/system01.dbf
    channel ORA_DISK_1: restoring section 1 of 1
    channel ORA_DISK_1: restore complete, elapsed time: 00:00:26
    channel ORA_DISK_1: starting datafile backup set restore
    channel ORA_DISK_1: using network backup set from service ORCLCDB
    channel ORA_DISK_1: specifying datafile(s) to restore from backup set
    channel ORA_DISK_1: restoring datafile 00003 to /opt/oracle/oradata/ORCLCDB/sysaux01.dbf
    channel ORA_DISK_1: restoring section 1 of 1
    channel ORA_DISK_1: restore complete, elapsed time: 00:00:15
    channel ORA_DISK_1: starting datafile backup set restore
    channel ORA_DISK_1: using network backup set from service ORCLCDB
    channel ORA_DISK_1: specifying datafile(s) to restore from backup set
    channel ORA_DISK_1: restoring datafile 00004 to /opt/oracle/oradata/ORCLCDB/undotbs01.dbf
    channel ORA_DISK_1: restoring section 1 of 1
    channel ORA_DISK_1: restore complete, elapsed time: 00:00:08
    channel ORA_DISK_1: starting datafile backup set restore
    channel ORA_DISK_1: using network backup set from service ORCLCDB
    channel ORA_DISK_1: specifying datafile(s) to restore from backup set
    channel ORA_DISK_1: restoring datafile 00005 to /opt/oracle/oradata/ORCLCDB/pdbseed/system01.dbf
    channel ORA_DISK_1: restoring section 1 of 1
    channel ORA_DISK_1: restore complete, elapsed time: 00:00:07
    channel ORA_DISK_1: starting datafile backup set restore
    channel ORA_DISK_1: using network backup set from service ORCLCDB
    channel ORA_DISK_1: specifying datafile(s) to restore from backup set
    channel ORA_DISK_1: restoring datafile 00006 to /opt/oracle/oradata/ORCLCDB/pdbseed/sysaux01.dbf
    channel ORA_DISK_1: restoring section 1 of 1
    channel ORA_DISK_1: restore complete, elapsed time: 00:00:08
    channel ORA_DISK_1: starting datafile backup set restore
    channel ORA_DISK_1: using network backup set from service ORCLCDB
    channel ORA_DISK_1: specifying datafile(s) to restore from backup set
    channel ORA_DISK_1: restoring datafile 00007 to /opt/oracle/oradata/ORCLCDB/users01.dbf
    channel ORA_DISK_1: restoring section 1 of 1
    channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
    channel ORA_DISK_1: starting datafile backup set restore
    channel ORA_DISK_1: using network backup set from service ORCLCDB
    channel ORA_DISK_1: specifying datafile(s) to restore from backup set
    channel ORA_DISK_1: restoring datafile 00008 to /opt/oracle/oradata/ORCLCDB/pdbseed/undotbs01.dbf
    channel ORA_DISK_1: restoring section 1 of 1
    channel ORA_DISK_1: restore complete, elapsed time: 00:00:04
    channel ORA_DISK_1: starting datafile backup set restore
    channel ORA_DISK_1: using network backup set from service ORCLCDB
    channel ORA_DISK_1: specifying datafile(s) to restore from backup set
    channel ORA_DISK_1: restoring datafile 00009 to /opt/oracle/oradata/ORCLCDB/ORCLPDB1/system01.dbf
    channel ORA_DISK_1: restoring section 1 of 1
    channel ORA_DISK_1: restore complete, elapsed time: 00:00:07
    channel ORA_DISK_1: starting datafile backup set restore
    channel ORA_DISK_1: using network backup set from service ORCLCDB
    channel ORA_DISK_1: specifying datafile(s) to restore from backup set
    channel ORA_DISK_1: restoring datafile 00010 to /opt/oracle/oradata/ORCLCDB/ORCLPDB1/sysaux01.dbf
    channel ORA_DISK_1: restoring section 1 of 1
    channel ORA_DISK_1: restore complete, elapsed time: 00:00:08
    channel ORA_DISK_1: starting datafile backup set restore
    channel ORA_DISK_1: using network backup set from service ORCLCDB
    channel ORA_DISK_1: specifying datafile(s) to restore from backup set
    channel ORA_DISK_1: restoring datafile 00011 to /opt/oracle/oradata/ORCLCDB/ORCLPDB1/undotbs01.dbf
    channel ORA_DISK_1: restoring section 1 of 1
    channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
    channel ORA_DISK_1: starting datafile backup set restore
    channel ORA_DISK_1: using network backup set from service ORCLCDB
    channel ORA_DISK_1: specifying datafile(s) to restore from backup set
    channel ORA_DISK_1: restoring datafile 00012 to /opt/oracle/oradata/ORCLCDB/ORCLPDB1/users01.dbf
    channel ORA_DISK_1: restoring section 1 of 1
    channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
    Finished restore at 01-SEP-20
  10. Shut down the database.
    RMAN> Shutdown immediate;
  11. Restart the standby database by using either the Server Control (srvctl) utility or SQL*Plus.
    • Use the srvctl utility to start the database:
      srvctl start instance -d standby DB_UNIQUE_NAME -i standby instance name -o mount
    • Use SQL*Plus to start the database:
      $ ./sqlplus / as sysdba
  12. Mount the database.
    SQL> startup mount
    The output will look similar to the following:
    ORACLE instance started.
    
    Total System Global Area 1.4496E+10 bytes
    Fixed Size		    9151696 bytes
    Variable Size		 1912602624 bytes
    Database Buffers	 1.2549E+10 bytes
    Redo Buffers		   24399872 bytes
    Database mounted.
  13. Alter database.
    SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;
    Database altered.
  14. View the role, thread number, sequence number and action for the database.
    SQL> SELECT ROLE, THREAD#, SEQUENCE#, ACTION FROM V$DATAGUARD_PROCESS;
    The output will look similar to the following:
    ROLE			    THREAD#  SEQUENCE# ACTION
    ------------------------ ---------- ---------- ------------
    post role transition		  0	     0 IDLE
    recovery apply slave		  0	     0 IDLE
    recovery apply slave		  0	     0 IDLE
    recovery apply slave		  0	     0 IDLE
    recovery apply slave		  0	     0 IDLE
    recovery logmerger		  1	     7 WAIT_FOR_LOG
    managed recovery		  0	     0 IDLE
    archive redo			  0	     0 IDLE
    archive local			  0	     0 IDLE
    redo transport timer		  0	     0 IDLE
    gap manager			  0	     0 IDLE
    archive redo			  0	     0 IDLE
    archive redo			  0	     0 IDLE
    redo transport monitor	0	     0 IDLE
    log writer			  0	     0 IDLE
    
    15 rows selected.
  15. (Optional) View the database name and role.
    SQL> select name, database_role from v$database;
    The output will look similar to the following:
    NAME	  DATABASE_ROLE
    --------- ----------------
    ORCLCDB   PHYSICAL STANDBY
  16. As the sysdba, clear all online standby redo logs
    $ sqlplus “/ as sysdba” 
    SQL> alter system set db_create_online_log_dest_1=<DATA Disk group>; 
    SQL> set pagesize 0 feedback off linesize 120 trimspool on 
    SQL> spool /tmp/clearlogs.sql 
    SQL> select distinct 'alter database clear logfile group '||group#||';' from v$logfile; 
    SQL> spool off 
    SQL> @/tmp/clearlogs.sql 
    SQL> select member from v$logfile;

Add RAC Instances to tnsnames.ora Files

For Oracle Real Application Clusters (Oracle RAC), add the Oracle RAC instances to tnsnames.ora and restart your listeners. The scan name cannot be resolved in either direction in a hybrid configuration, which makes it necessary to configure the address list to provide high availability.

  1. Edit the TNSNAMES.ORA file on the on-premises database host.
    Primary db_unique_name = (DESCRIPTION = 
    (SDU=65536) (RECV_BUF_SIZE=134217728) 
    (SEND_BUF_SIZE=134217728) 
    (ADDRESS_LIST = 
    		   (FAILOVER=on)
    (CONNECT_TIMEOUT=3)(RETRY_COUNT=3)
    (ADDRESS = (PROTOCOL = TCP)(HOST = PrimaryDB Node 1IP address)(PORT = {1521|port#})) 
    (ADDRESS = (PROTOCOL = TCP)(HOST = StandbyDB Node 2IP address)(PORT = {1521|port#})) 
    ) 
    (CONNECT_DATA = 
    (SERVER = DEDICATED) 
    (SERVICE_NAME = Primary_db_SID) 
    (UR=A) 
    )) 
    
    Standby db_unique_name = (DESCRIPTION = 
    (SDU=65536) (RECV_BUF_SIZE=134217728) 
    (SEND_BUF_SIZE=134217728) 
    (ADDRESS_LIST = 
    		   (FAILOVER=on)
    (CONNECT_TIMEOUT=3)(RETRY_COUNT=3)
    (ADDRESS = (PROTOCOL = TCP)(HOST = StandbyDB Node 1IP address)(PORT = {1521|port#})) 
    (ADDRESS = (PROTOCOL = TCP)(HOST = StandbyDB Node 2IP address)(PORT = {1521|port#})) 
    ) 
    (CONNECT_DATA = 
    (SERVER = DEDICATED) 
    (SERVICE_NAME = Primary_db_SID) 
    (UR=A) 
    )) 
  2. Edit the TNSNAMES.ORA file on the standby database host in Oracle Cloud Infrastructure (OCI).
    Standby db_unique_name = (DESCRIPTION = 
    (SDU=65536) (RECV_BUF_SIZE=134217728) 
    (SEND_BUF_SIZE=134217728) 
    (ADDRESS_LIST = 
    		   (FAILOVER=on)
    (CONNECT_TIMEOUT=3)(RETRY_COUNT=3)
    (ADDRESS = (PROTOCOL = TCP)(HOST = StandbyDB Node 1IP address)(PORT = {1521|port#})) 
    (ADDRESS = (PROTOCOL = TCP)(HOST = StandbyDB Node 2IP address)(PORT = {1521|port#})) 
    ) 
    (CONNECT_DATA = 
    (SERVER = DEDICATED) 
    (SERVICE_NAME = Primary_db_SID) 
    (UR=A) 
    )) 
    
    <Primary db_unique_name> = (DESCRIPTION = 
    (SDU=65536) (RECV_BUF_SIZE=134217728) 
    (SEND_BUF_SIZE=134217728) 
    (ADDRESS_LIST = 
    		   (FAILOVER=on)
    (CONNECT_TIMEOUT=3)(RETRY_COUNT=3)
    (ADDRESS = (PROTOCOL = TCP)(HOST = PrimaryDB Node 1IP address)(PORT = {1521|port#})) 
    (ADDRESS = (PROTOCOL = TCP)(HOST = StandbyDB Node 2IP address)(PORT = {1521|port#})) 
    ) 
    (CONNECT_DATA = 
    (SERVER = DEDICATED) 
    (SERVICE_NAME = Primary_db_SID) 
    (UR=A) 
    ))