Tuesday 15 August 2017

Configure Oracle 11gR2 Data Guard Physical Standby

Synopsis

In this exercise we will configure Oracle Data Guard for Oracle 11gR2 database. We have two virtual machines configured where we have built Linux machines and installed Oracle 11gR2 database. Please refer below mentioned link to build Linux virtual machine and install Oracle 11gR2 database software
  • Primary Database
    • hostname : prim.localdomain
    • db_name : PRODPRIM
    • db_unique : PRODPRIM
  • Standby Database
    • hostname : stby.localdomain
    • db_name : PRODPRIM
    • db_unique : PRODSTBY

Configuration on the Primary Database :-

Step 1 :- Enable archivelog mode

SQL> SHUTDOWN IMMEDIATE
SQL> STARTUP MOUNT
SQL> ALTER DATABASE ARCHIVELOG;
SQL> ALTER DATABASE OPEN;
SQL> archive log list;
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     1
Next log sequence to archive   2
Current log sequence           2

Step 2 :- Enable force logging

SQL> ALTER DATABASE FORCE LOGGING;

Database altered.

Step 3 :- Set database parameters to configure the data guard

Here are the list of parameters to be set to configure the dataguard
  • db_unique_name
  • log_archive_config  
  • log_archive_dest_2  
  • remote_login_passwordfile
  • fal_server
  • fal_client
  • standby_file_management
SQL> ALTER SYSTEM SET LOG_ARCHIVE_CONFIG='DG_CONFIG=(PRODPRIM,PRODSTBY)';

System altered.

SQL> ALTER SYSTEM SET LOG_ARCHIVE_DEST_2='SERVICE=PRODSTBY NOAFFIRM ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=PRODSTBY';

System altered.

SQL> alter system set log_archive_dest_state_2=enable;

System altered.

SQL> alter system set log_archive_format='%t_%s_%r.arc' scope=spfile;

System altered.

SQL> alter system set remote_login_passwordfile=exclusive scope=spfile;

System altered.

SQL> alter system set fal_server=PRODSTBY;

System altered.

SQL> alter system set fal_client='PRODPRIM';

System altered.

SQL> alter system set standby_file_management=auto;

System altered.

Step 4 :- Create and start the Listener

We need to create and start the listener on both primary and standby servers 

Step 5 :- Add tnsnames for services of primary and standby database

This step has to be performed on both primary and standby database servers. You can update the tnsnames.ora file to add service or service can be added using netca utility. Go to $ORACLE_HOME/network/admin/tnsnames.ora add the below mentioned line to the file
In case you want to add service using netca utility refer this link 

PRODPRIM =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = prim.localdomain)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = PRODPRIM)
    )
  )

PRODSTBY =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = stby.localdomain)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = PRODSTBY)
    )
  )

Step 6 :- Check the services if its been configured properly using tnsping on both the servers

[oracle@prim dbhome_1]$ tnsping PRODPRIM

TNS Ping Utility for Linux: Version 11.2.0.1.0 - Production on 15-AUG-2017 14:17:41

Copyright (c) 1997, 2009, Oracle.  All rights reserved.

Used parameter files:

Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = prim.localdomain)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = PRODPRIM)))
OK (0 msec)

[oracle@prim dbhome_1]$ tnsping PRODSTBY

TNS Ping Utility for Linux: Version 11.2.0.1.0 - Production on 15-AUG-2017 14:18:51

Copyright (c) 1997, 2009, Oracle.  All rights reserved.

Used parameter files:

Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = stby.localdomain)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = PRODSTBY)))
OK (20 msec)

Step 7 :- Backup primary database using RMAN utility

[oracle@prim dbhome_1]$ rman target /

Recovery Manager: Release 11.2.0.1.0 - Production on Tue Aug 15 14:20:28 2017

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

connected to target database: PRODPRIM (DBID=881986728)

RMAN> backup database plus archivelog;

Step 8 :- Create standby control file 

SQL> alter database create standby controlfile as '/u01/app/oracle/oradata/PRODPRIM/stbycontrol1.ctl';

Database altered.

Step 9 :- Create pfile of primary database

SQL> create pfile from spfile;

File created.

Step 10 :- Update the newly created pfile with below mentioned changes

  • log_archive_dest_2 = 'SERVICE=PRODPRIM ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=PRODPRIM'
  • fal_client = PRODSTBY
  • fal_server = PRODPRIM
  • db_unique_name = PRODSTBY

Step 11 :- Copy newly created pfile, standby controlfile, password file and RMAN backup pieces to standby database server

[oracle@prim dbs]$ scp initPRODPRIM.ora oracle@stby.localdomain:/u01/app/oracle/product/11.2.0/dbhome_1/dbs
The authenticity of host 'stby.localdomain (192.168.10.2)' can't be established.
RSA key fingerprint is a3:a6:ed:66:82:ad:bf:9b:6b:a7:59:4d:27:f6:f0:a0.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'stby.localdomain,192.168.10.2' (RSA) to the list of known hosts.
oracle@stby.localdomain's password:
initPRODSTBY.ora                                                                                                                                                   100% 1286     1.3KB/s   00:00
--------------------------------------------------------------------
[oracle@prim PRODPRIM]$ scp stbycontrol1.ctl oracle@STBY.localdomain:/u01/app/oracle/oradata/PRODSTBY/control01.ctl
oracle@stby.localdomain's password:
stbycontrol1.ctl                                                                                                                                                   100% 9520KB   9.3MB/s   00:00
--------------------------------------------------------------------
 [oracle@prim PRODPRIM]$ scp stbycontrol1.ctl oracle@STBY.localdomain:/u01/app/oracle/flash_recovery_area/PRODSTBY/control02.ctl
oracle@stby.localdomain's password:
stbycontrol1.ctl                                                                                                                                                   100% 9520KB   9.3MB/s   00:00
--------------------------------------------------------------------
[oracle@prim dbs]$ scp orapwPRODPRIM oracle@stby.localdomain:/u01/app/oracle/product/11.2.0/dbhome_1/dbs
oracle@stby.localdomain's password:
orapwPRODPRIM                                                                                                                                                      100% 1536     1.5KB/s   00:00
--------------------------------------------------------------------
[oracle@prim 2017_08_15]$ scp * oracle@stby.localdomain:/u01/app/oracle/flash_recovery_area/PRODSTBY/backup
oracle@stby.localdomain's password:
o1_mf_annnn_TAG20170815T142041_ds5fh218_.bkp                                                                                                                       100%   29MB  29.4MB/s   00:00
o1_mf_annnn_TAG20170815T142204_ds5fknfn_.bkp                                                                                                                       100%   23KB  22.5KB/s   00:00
o1_mf_ncsnf_TAG20170815T142045_ds5fklmm_.bkp                                                                                                                       100% 9600KB   9.4MB/s   00:00
o1_mf_nnndf_TAG20170815T142045_ds5fh5fc_.bkp                                                                                                                       100%  921MB  31.8MB/s   00:29

Configuration on the Standby Database :-

Step 1 :- Set the environment variables and start the database in mount state

$export ORACLE_HOME = /u01/app/oracle/product/11.2.0/dbhome_1
$export ORACLE_SID = PRODPRIM
$export PATH = $ORACLE_SID/bin:$PATH
Create the necessary directories before starting the database
$mkdir -p /u01/app/oracle/admin/PRODSTBY/adump

SQL> startup mount
ORACLE instance started.

Total System Global Area  839282688 bytes
Fixed Size                  2217992 bytes
Variable Size             494929912 bytes
Database Buffers          339738624 bytes
Redo Buffers                2396160 bytes
Database mounted.

SQL> create spfile from pfile;

File created.

Step 2 :- Restore and recover the database using RMAN

[oracle@stby dbs]$ rman target /

Recovery Manager: Release 11.2.0.1.0 - Production on Tue Aug 15 14:54:22 2017

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

connected to target database: PRODPRIM (DBID=881986728, not open)

RMAN> list backup of database summary;

using target database control file instead of recovery catalog

List of Backups
===============
Key     TY LV S Device Type Completion Time #Pieces #Copies Compressed Tag
------- -- -- - ----------- --------------- ------- ------- ---------- ---
2       B  F  A DISK        15-AUG-17       1       1       NO         TAG20170815T142045

RMAN> restore database;

......

Finished restore at 15-AUG-17

RMAN> recover database;

Starting recover at 15-AUG-17
using channel ORA_DISK_1

starting media recovery
......
unable to find archived log
archived log thread=1 sequence=7
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 08/15/2017 14:56:46
RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 7 and starting SCN of 980859

Here in this step recovery will fail, it would expect for a archivelog file, this can be ignored

Step 3 :- Add standby redolog file on primary database (one additional redolog group to be created)

SQL> ALTER DATABASE ADD STANDBY LOGFILE('/u01/app/oracle/oradata/PRODPRIM/stndby1.log') size 51M;

Database altered.

SQL> ALTER DATABASE ADD STANDBY LOGFILE('/u01/app/oracle/oradata/PRODPRIM/stndby2.log') size 51M;

Database altered.

SQL> ALTER DATABASE ADD STANDBY LOGFILE('/u01/app/oracle/oradata/PRODPRIM/stndby3.log') size 51M;

Database altered.

SQL> ALTER DATABASE ADD STANDBY LOGFILE('/u01/app/oracle/oradata/PRODPRIM/stndby4.log') size 51M;

Database altered.

Step 4 :- Add standby redolog file on standby database (one additional redolog group to be created)

SQL> ALTER DATABASE ADD STANDBY LOGFILE('/u01/app/oracle/oradata/PRODPRIM/stndby1.log') size 51M;

Database altered.

SQL>  ALTER DATABASE ADD STANDBY LOGFILE('/u01/app/oracle/oradata/PRODPRIM/stndby2.log') size 51M;

Database altered.

SQL> ALTER DATABASE ADD STANDBY LOGFILE('/u01/app/oracle/oradata/PRODPRIM/stndby3.log') size 51M;

Database altered.

SQL> ALTER DATABASE ADD STANDBY LOGFILE('/u01/app/oracle/oradata/PRODPRIM/stndby4.log') size 51M;

Database altered.

Step 5 :- Start apply process on standby database

SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE nodelay DISCONNECT FROM SESSION;

Database altered.

If you want to cancel the apply process use below mentioned command
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;

After successful execution of apply process we have completed configuration of physical standby database

Step 6 :- Verify if dataguard is working fine

Switch logs multiple times on primary database using below mentioned command
SQL> alter system switch logfile;

System altered.

Compare the archivelog sequence in primary and standby database 
Primary Database
SQL> select max(sequence#) from v$archived_log;
Standby Database
SQL> select max(sequence#) from v$archived_log;

You can also verify the database role on both primary and standby database
SQL> select name,open_mode,database_role from v$database;

NAME      OPEN_MODE            DATABASE_ROLE
--------- -------------------- ----------------
PRODPRIM  READ WRITE           PRIMARY

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

NAME      OPEN_MODE            DATABASE_ROLE
--------- -------------------- ----------------
PRODPRIM  MOUNTED              PHYSICAL STANDBY

No comments:

Post a Comment