Wednesday, November 20, 2024

Step by Step Guide on Creating Physical Standby Using RMAN DUPLICATE...FROM ACTIVE DATABASE

 Step by Step Guide on Creating Physical Standby Using RMAN DUPLICATE...FROM ACTIVE DATABASE 

Alireza Kamrani 

11/21/2024


Step by step guide on how to create a physical standby database using RMAN DUPLICATE FROM ACTIVE DATABASE command without shutting down the primary and using primary active database files (No need to take a backup)


Database Name : Prim
Primary db_unique_name : Prim
standby db_unique_name : Stby


SOLUTION

1. Make the necessary changes to the primary database. 
    a. Enable force logging.
    b. Creating the password file if one does not exist.
    c. Create standby redologs.
    d. Modify the parameter file suitable for Dataguard.

2. Ensure that the sql*net connectivity is working fine.

3. Create the standby database over the network using the active(primary) database files.
    a. Create the password file
    b. Create the initialization parameter file for the standby database (auxiliary database)
    c. Create the necessary mount points or the folders for the database files
    d. Run the standby creation ON STANDBY by connecting to primary as target database.

 

DUPLICATE TARGET DATABASE  

FOR STANDBY

FROM ACTIVE DATABASE

SPFILE

   PARAMETER_VALUE_CONVERT '', ''

   SET DB_FILE_NAME_CONVERT '', ''

   SET LOG_FILE_NAME_CONVERT '', ''

   SET SGA_MAX_SIZE 200M

   SET SGA_TARGET 125M;


4. Check the log shipping and apply.


PROCEDURE:

While creating the standby database we use the active database files i.e., this command will be useful in creating the physical standby database using active database files over the network.


1. Prepare the production database to be the primary database

a. Ensure that the database is in archivelog mode .

SQL> select log_mode from v$database;


LOG_MODE

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

ARCHIVELOG


b. Enable force logging

SQL> ALTER DATABASE FORCE LOGGING;


c. Create standby redologs

SQL> alter database add standby logfile '<name>' size <size>;


d. Modify the primary initialization parameter for dataguard on primary,

SQL> alter system set LOG_ARCHIVE_CONFIG='DG_CONFIG

=(prim,stby)';

System altered.


SQL> alter system set LOG_ARCHIVE_DEST_1='LOCATION=/<path>/prim/redo/ VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=prim';

System altered.


SQL> alter system set LOG_ARCHIVE_DEST_2='SERVICE=stby LGWR ASYNC VALID_FOR=(ONLINE_LOGFILE,PRIMARY_ROLE) DB_UNIQUE_NAME=stby';

System altered.


SQL> alter system set LOG_ARCHIVE_DEST_STATE_1=ENABLE;

System altered.


SQL> alter system set FAL_SERVER=stby;

System altered.


SQL> alter system set FAL_CLIENT=prim;

System altered.

--Previous settings configured for handling log shipping when switchover operation.


SQL> alter system set DB_FILE_NAME_CONVERT='/<path>/stby/data/','/<path>/prim/data' scope=spfile;

System altered.


SQL> alter system set LOG_FILE_NAME_CONVERT='/<path>/stby/redo/','/<path>/prim/redo' scope=spfile;

System altered.


2. Ensure that the sql*net connectivity is working fine.

Insert a static entry for Stby in the listener.ora file of the standby system.


NOTE : For non default port set the REMOTE_LISTENER


SID_LIST_LISTENER =

  (SID_LIST =

    (SID_DESC =

     (GLOBAL_DBNAME = stby.<domain>)

     (ORACLE_HOME = /<oracle_home path>)

     (SID_NAME = stby)

    )

   )


LISTENER =

  (DESCRIPTION =

    (ADDRESS = (PROTOCOL = TCP)(HOST = <auxiliary host>)(PORT = 1521))

  ) 

 

TNSNAMES.ORA for the Primary and Standby should have BOTH entries


PRIM =

  (DESCRIPTION =

    (ADDRESS_LIST =

      (ADDRESS = (PROTOCOL = TCP)(HOST = <target host>)(PORT = 1521))

    )

    (CONNECT_DATA = (SERVICE_NAME = prim.<domain>))

  ) 


STBY =

  (DESCRIPTION =

    (ADDRESS_LIST =

      (ADDRESS = (PROTOCOL = TCP)(HOST = <auxiliary host>)(PORT = 1521))

    )

    (CONNECT_DATA = (SERVICE_NAME = stby.<domain>))

  )


Check with the SQL*Net configuration using the following commands on the Primary AND Standby


% tnsping prim

% tnsping stby


3. Create the standby database

a. Copy the password file from the primary $ORACLE_HOME/dbs and rename it to the standby database name.

The username is required to be SYS and the password needs to be the same on the Primary and Standby. 

The best practice for this is to copy the password file as suggested. 

The password file name must match the instance name/SID used at the standby site, not the DB_NAME.

b. Create a initialization parameter with only belo parameters.


DB_NAME=prim

DB_UNIQUE_NAME=stby

DB_BLOCK_SIZE=<same as primary>


c. Create the necessary directories in the standby location to place database files and trace files ($ADR_HOME).

d. Set the environment variable ORACLE_SID to the standby service and start the standby-instance.

% export ORACLE_SID=stby

% sqlplus "/ as sysdba"


SQL> startup nomount pfile=$ORACLE_HOME/dbs/initSTBY.ora


NOTE : Use either PFILE or SPFILE 

# If DUPLICATE without TARGET connection is used you cannot use SPFILE 

# else getting


RMAN-05537: DUPLICATE without TARGET connection when auxiliary instance is started with spfile cannot use SPFILE clause


e. Verify if the connection 'AS SYSDBA' is working


% sqlplus /nolog


SQL> connect sys/<passwd>@stby AS SYSDBA

SQL> connect sys/<passwd>@prim AS SYSDBA


f. On the primary system invoke the RMAN executable and connect to the primary and the auxiliary database ( i.e., the standby)


$ rman target sys/<password>@prim auxiliary sys/<password>@stby


connected to target database: Prim(DBID=640112753)

connected to auxiliary database: Stby (not mounted)


RMAN> run {

allocate channel prmy1 type disk;

allocate channel prmy2 type disk;

allocate channel prmy3 type disk;

allocate channel prmy4 type disk;

allocate auxiliary channel stby type disk;


duplicate target database for standby from active database

spfile

  parameter_value_convert 'prim','stby'

  set db_unique_name='stby'

  set db_file_name_convert='/prim/','/stby/'

  set log_file_name_convert='/prim/','/stby/'

  set control_files='/<path>/control01.ctl'

  set log_archive_max_processes='5'

  set fal_client='stby'

  set fal_server='prim'

  set standby_file_management='MANUAL'

  set log_archive_config='dg_config=(prim,stby)'

  set log_archive_dest_2='service=prim ASYNC valid_for=(ONLINE_LOGFILE,PRIMARY_ROLE) db_unique_name=prim';

}


4. Start managed recovery

Connect to standby using SQL*Plus and start the MRP (Managed Recovery Process). Compare the primary last sequence and MRP (Managed Recovery Process) applying sequence.

Example :

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


5. Open standby database in Read Only (active dataguard)

If you are licensed to use Active Dataguard (ADG) than open the Standby Database in READ ONLY and start the recovery.


SQL> alter database recover managed standby database cancel;


SQL> alter database open;


SQL> alter database recover managed standby database disconnect;


 6. DGMGRL,

From standby server, Connect to Standby,

DGMGRL>connect sys/<password>@<standby connect string>


If Standby is already in mount mode and MRP is running (NOTE : DG broker automatically start the MRP if standby DB in mount mode)


DGMGRL>edit database <standby> set state=apply-off;

DGMGRL>shutdown

DGMGRL>edit database <standby> set state=apply-on;


DGMGRL>startup  <<<<MRP will get started automatically


Please note if standby_file_management was set to manual. Ensure you set it back to Auto on the standby database once the standby creation is completed.



Alireza Kamrani 

11/21/2024

Step by Step Guide on Creating Physical Standby Using RMAN DUPLICATE...FROM ACTIVE DATABASE

  Step by Step Guide on Creating Physical Standby Using RMAN DUPLICATE...FROM ACTIVE DATABASE   Alireza Kamrani  11/21/2024 Step by step gui...