1. Enable arch mode on standby db

# On source server 
mkdir -p /oraarch/<source_sid>

ALTER SYSTEM SET log_archive_dest_1='LOCATION=/oraarch/<source_sid>';
shutdown immediate ;
STARTUP MOUNT;
ALTER DATABASE ARCHIVELOG;
ALTER DATABASE OPEN;
ALTER SYSTEM SWITCH LOGFILE;

2. Prepare directories on target server

# on target server
mkdir -p /oracle/admin/<target_sid>/adump
mkdir -p /oracle/admin/<target_sid>/dpdump
mkdir -p /oracle/admin/<target_sid>/pfile
mkdir -p /oracle/control/<target_sid>
mkdir -p /oraarch/<target_sid>
mkdir -p /oraarch/FRA
mkdir -p /oradata/<target_sid>
mkdir -p /oraredo/<target_sid>

3. Prepare listener on both servers

# on source server
cd  /oracle/product/11.2.0/dbhome_11203/network/admin/
vi listener.ora
SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (GLOBAL_DBNAME = <source_sid>)
      (ORACLE_HOME = /oracle/product/11.2.0/dbhome_11203)
      (SID_NAME = <source_sid>)
    )
  )
LISTENER =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = <source_hostname>)(PORT = 1521))
  )
ADR_BASE_LISTENER = /oracle

# on target server
cd  /oracle/product/11.2.0/dbhome_11203/network/admin/
vi listener.ora
SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (GLOBAL_DBNAME = <target_sid>)
      (ORACLE_HOME = /oracle/product/11.2.0/dbhome_11203)
      (SID_NAME = <target_sid>)
    )
  )
LISTENER =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = <target_hostname>)(PORT = 1521))
  )
ADR_BASE_LISTENER = /oracle

4. Prepare tnsnames.ora on both servers

# on source server
vi tnsnames.ora
<SOURCE_SID> =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = <source_hostname>)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = <source_sid>)
    )
  )
<TARGET_SID> =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = <target_hostname>)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = <target_sid>)
    )
  )

# on target server
vi tnsnames.ora
<SOURCE_SID> =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = <source_hostname>)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = <source_sid>)
    )
  )
<TARGET_SID> =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = <target_hostname>)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = <target_sid>)
    )
  )

5. Prepare sqlnet.ora on both servers

# on source server
vi sqlnet.ora
#SQLNET.ALLOWED_LOGON_VERSION=8
SQLNET.ALLOWED_LOGON_VERSION_SERVER=8
SQLNET.ALLOWED_LOGON_VERSION_CLIENT=8

# on target server
vi sqlnet.ora
#SQLNET.ALLOWED_LOGON_VERSION=8
SQLNET.ALLOWED_LOGON_VERSION_SERVER=8
SQLNET.ALLOWED_LOGON_VERSION_CLIENT=8

6. Prepare init & password file for standby db

# on target server
# password file
orapwd file=orapw<target_sid>  password=<sys_pswd>

# init file
# you can generate pfile from source db spfile, and replace sid with new value, pay attention the db_name keep same as the source db.

vi init<target_sid>.ora
*.audit_file_dest='/oracle/admin/<target_sid>/adump'
*.audit_trail='db'
*.compatible='11.2.0.0.0'
*.control_files='/oracle/control/<target_sid>/control01.ctl','/oradata/<target_sid>/control02.ctl'
*.db_block_size=8192
*.db_name='<source_sid>'
*.db_unique_name='<target_sid>'
*.db_recovery_file_dest='/oraarch/FRA'
*.db_recovery_file_dest_size=10737418240
*.diagnostic_dest='/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=<target_sid>XDB)'
*.log_archive_dest_1='LOCATION=/oraarch/<target_sid>'
*.open_cursors=300
*.pga_aggregate_target=536870912
*.processes=500
*.remote_login_passwordfile='EXCLUSIVE'
*.sec_case_sensitive_logon=FALSE
*.sessions=555
*.sga_target=1610612736
*.undo_tablespace='UNDOTBS1'
*.db_file_name_convert=('<source_sid>','<target_sid>')
*.log_file_name_convert=('<source_sid>', '<target_sid>')

startup nomount

7. Create standby redo log for primary db

-- on source server
-- clear existing standby files if it exists 
-- alter database drop standby logfile group <XX>;

-- create N + 1 standby logs with same size

alter database add standby logfile '/oraredo/<source_sid>/stby01.log' size 50M;
alter database add standby logfile '/oraredo/<source_sid>/stby02.log' size 50M;
alter database add standby logfile '/oraredo/<source_sid>/stby03.log' size 50M;
alter database add standby logfile '/oraredo/<source_sid>/stby04.log' size 50M;

8. Create standby db by cloning from primary db online.

# on target server
vi cr_adg_<target_sid>.sh
export NLS_LANG='AMERICAN_AMERICA.AL32UTF8'
rman target sys/t1me4chg@<source_sid> trace=cr_adg_<target_sid>.log<<-EOS
connect auxiliary sys/t1me4chg@<target_sid>
run {
   allocate channel prmy1 type disk;
   allocate channel prmy2 type disk;
   allocate channel prmy3 type disk;
   allocate channel prmy4 type disk;
   allocate channel prmy5 type disk;
   allocate auxiliary channel stby1 type disk;
   duplicate target database for standby from active database;
}
EOS
chmod +x cr_adg_<target_sid>.sh
nohup ./cr_adg_<target_sid>.sh &
tail -f nohup

9. Add standby and primary role to standby db

--on standby db
ALTER SYSTEM SET FAL_SERVER=<source_sid>; 
ALTER SYSTEM SET FAL_CLIENT=<target_sid>; 
ALTER SYSTEM SET LOG_ARCHIVE_CONFIG='DG_CONFIG=(<source_sid>,<target_sid>)'; 
ALTER SYSTEM SET STANDBY_FILE_MANAGEMENT=AUTO; 
ALTER SYSTEM SET LOG_ARCHIVE_DEST_2='service=<source_sid> ASYNC DB_UNIQUE_NAME=<source_sid> VALID_FOR=(primary_role,online_logfile)';

10. Start log applying on standby db

--on standby db
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT;

11. Set redo transportation on primary db

--on primary db
ALTER SYSTEM SET LOG_ARCHIVE_CONFIG='DG_CONFIG=(<source_sid>,<target_sid>)'; 
ALTER SYSTEM SET LOG_ARCHIVE_DEST_2='service=<target_sid> ASYNC DB_UNIQUE_NAME=<target_sid> VALID_FOR=(primary_role,online_logfile)'; 
ALTER SYSTEM SWITCH LOGFILE; 
ALTER SYSTEM SET FAL_SERVER=<target_sid>; 
ALTER SYSTEM SET FAL_CLIENT=<source_sid>; 
ALTER SYSTEM SET STANDBY_FILE_MANAGEMENT=AUTO;

12. Open as ADG mode on standby db

--on standby db
RECOVER MANAGED STANDBY DATABASE CANCEL;
ALTER DATABASE OPEN READ ONLY;
RECOVER MANAGED STANDBY DATABASE DISCONNECT USING CURRENT LOGFILE;

13. Update dbstart script on target server

# on target server
cd /oracle/product/11.2.0/dbhome_11203/bin
cp dbstart dbstart.orig
vi dbstart
     80 ORACLE_HOME_LISTNER=$ORACLE_HOME
     81 if [ ! $ORACLE_HOME_LISTNER ] ; then
     82   echo "ORACLE_HOME_LISTNER is not SET, unable to auto-start Oracle Net Listener"
     83   echo "Usage: $0 ORACLE_HOME"
     84 elseā€¦ 
    203   if [ $STATUS -eq 1 ] ; then
    204     if [ -e $SPFILE -o -e $SPFILE1 -o -e $PFILE ] ; then
    205       case $VERSION in
    206         "6")  sqldba command=startup ;;
    207         "internal")  $SQLDBA <<EOF
    208 connect internal
    209 STARTUP MOUNT
    210 ALTER DATABASE OPEN READ ONLY;
    211 RECOVER MANAGED STANDBY DATABASE DISCONNECT USING CURRENT LOGFILE;
    212 EOF
    213           ;;
    214         *)  $SQLDBA <<EOF
    215 connect / as sysdba
    216 STARTUP MOUNT
    217 ALTER DATABASE OPEN READ ONLY;
    218 RECOVER MANAGED STANDBY DATABASE DISCONNECT USING CURRENT LOGFILE;
    219 quit
    220 EOF
    221           ;;
    222       esac

14. Enable auto start on target server

# on target server
vi /etc/oratab
<target_sid>:/oracle/product/11.2.0/dbhome_11203:Y

15. (Optional) Remove ADG on both servers

--on source db
ALTER SYSTEM SET LOG_ARCHIVE_CONFIG='';
ALTER SYSTEM SET LOG_ARCHIVE_DEST_2='';
ALTER SYSTEM SET FAL_SERVER='';
ALTER SYSTEM SET FAL_CLIENT='';
ALTER SYSTEM SWITCH LOGFILE;

--on standby db
ALTER SYSTEM SET LOG_ARCHIVE_CONFIG='';
ALTER SYSTEM SET LOG_ARCHIVE_DEST_2='';
ALTER SYSTEM SET FAL_SERVER='';
ALTER SYSTEM SET FAL_CLIENT='';
-- ALTER SYSTEM SWITCH LOGFILE;