Showing posts with label Dataguard. Show all posts
Showing posts with label Dataguard. Show all posts

Oracle DATAGUARD Broker configuration steps


Prerequisites:
1.       Set the initialization parameter DG_BROKER_START value TRUE on both DB’s, So that DMON process would start automatically.
2.       Create the network configuration files on both primary and stand by sides to incorporate the modification to DB_UNIQUE_NAME.
3.       Add static database registration entry on both database tnsnames.ora configuration file, So that each database could communicate with the Data Guard Broker Management Utility DGMGRL.

Configuration Steps:
Primary] $ dgmgrl
DGMGRL > connect  sys
Password:
Connected.

Create configuration command to initialize the DG broker configuration on primary database side.
DGMGRL> Create configuration ‘PR_ORCL’ as primary database is primary_db 
>connect identifier is orcl;

To check the configuration
DGMGRL> show configuration

Adding the standby database to the DG broker configuration

DGMGRL> Add database ‘ST_ORCL’ As 
>Connect identifier is standby;

Verify the configuration:
DGMGRL> show configuration verbose;
 Configuration
  Name:                PR_ORCL
  Enabled:             NO
  Protection Mode:     MaxPerformance
  Databases:
    primary_db - Primary database
    stdby_db   - Physical standby database
 Fast-Start Failover: DISABLED
 Current status for "PR_ORCL":
DISABLED

 DGMGRL> show database ST_ORCL
 Database
  Name:            ST_ORCL
  Role:            PHYSICAL STANDBY
  Enabled:         NO
  Intended State:  OFFLINE
  Instance(s):
    orcl
 Current status for "ST_ORCL":
DISABLED

Enable the DG Broker configuration:
DGMGRL> enable configuration;
 Enabled.
 DGMGRL> show database PR_ORCL;
 Database
  Name:            PR_ORCL
  Role:            PRIMARY
  Enabled:         YES
  Intended State:  TRANSPORT-ON
  Instance(s):
    orcl
 Current status for "PR_ORCL":
SUCCESS
 DGMGRL> show database ST_ORCL;
 Database
  Name:            ST_ORCL
  Role:            PHYSICAL STANDBY
  Enabled:         YES
  Intended State:  APPLY-ON
  Instance(s):
    orcl
 Current status for "ST_ORCL":
SUCCESS

Performing switchover:
Using Data Guard Broker to Perform a Switchover
DGMGRL> SWITCHOVER TO ST_ORCL;
 Performing switchover NOW, please wait...
New primary database "ST_ORCL" is opening...
Operation requires shutdown of instance "orcl" on database "PR_ORCL"
Shutting down instance "orcl"...
ORA-1109: database not open
Database dismounted.
ORACLE instance shut down.
 Operation requires startup of instance "orcl" on database "ST_ORCL"
Starting instance "orcl"...
ORACLE instance started.
Database mounted.
Switchover succeeded, new primary is "ST_ORCL"

Using Data Guard Broker to Perform a Switchback

DGMGRL> SWITCHOVER TO PR_ORCL;

Performing switchover NOW, please wait...
New primary database "ST_ORCL" is opening...
Operation requires shutdown of instance "orcl" on database "ST_ORCL"
Shutting down instance "orcl"...
ORA-1109: database not open
Database dismounted.
ORACLE instance shut down.
 Operation requires startup of instance "orcl" on database "PR_ORCL"
Starting instance "orcl"...
ORACLE instance started.
Database mounted.
Switchover succeeded, new primary is "PR_ORCL"

How to convert physical standby database to Active Dataguard 11g R2

Active Dataguard:

Oracle Active Data Guard is a separately licensed database option for Oracle Database 11g Enterprise Edition. 

It includes the Real-time Query feature which enables a physical standby database to be open in read-only mode while Redo Apply is active(MRP). 
Users who are connected to a physical standby database can query and report against data that is up-to-date with the primary database.
It also enables you to configure RMAN BCT(Block Change Tracking) for a physical standby database. 
With RMAN BCT, you can offload fast incremental backups from the production database to the physical standby database.

 Step 1: You must have physical standby database configured in your environment.

NAME      DB_UNIQUE_NAME         DATABASE_ROLE      OPEN_MODE           CONTROL SWITCHOVER_STATUS
--------- ------------------------------ ---------------- -------------------- ------- --------------------
DC      DR                 PHYSICAL STANDBY MOUNTED           STANDBY NOT ALLOWED


MAX(SEQUENCE#)
--------------
       129

SQL> 
SQL> select process,status from v$managed_standby;

PROCESS   STATUS
--------- ------------
ARCH      CONNECTED
ARCH      CONNECTED
ARCH      CONNECTED
ARCH      CONNECTED
MRP0      WAIT_FOR_LOG

Step 2: See your MRP process is active. If you try to open the database, you will get below error. You need to stop the MRP process and then open the database.


SQL> alter database open;
alter database open
*
ERROR at line 1:
ORA-10456: cannot open standby database; media recovery session may be in progress


SQL> alter database recover managed standby database cancel;

Database altered.

SQL> select process,status from v$managed_standby;

PROCESS   STATUS
--------- ------------
ARCH      CONNECTED
ARCH      CONNECTED
ARCH      CONNECTED
ARCH      CONNECTED


SQL> alter database open;

Database altered.

SQL> 

NAME      DB_UNIQUE_NAME         DATABASE_ROLE      OPEN_MODE           CONTROL SWITCHOVER_STATUS
--------- ------------------------------ ---------------- -------------------- ------- --------------------
DC      DR                 PHYSICAL STANDBY READ ONLY           STANDBY NOT ALLOWED


MAX(SEQUENCE#)
--------------
       129

On Primary:

SQL> alter system switch logfile;

System altered.

SQL> alter system switch logfile;

System altered.

SQL> @rd

NAME      DB_UNIQUE_NAME         DATABASE_ROLE      OPEN_MODE           CONTROL SWITCHOVER_STATUS
--------- ------------------------------ ---------------- -------------------- ------- --------------------
DC      DC                 PRIMARY      READ WRITE           CURRENT TO STANDBY


MAX(SEQUENCE#)
--------------
       131


Step 3: Now start MRP process and see the DB status.

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

Database altered.

SQL> 

NAME      DB_UNIQUE_NAME         DATABASE_ROLE      OPEN_MODE           CONTROL SWITCHOVER_STATUS
--------- ------------------------------ ---------------- -------------------- ------- --------------------
DC      DR                 PHYSICAL STANDBY READ ONLY WITH APPLY STANDBY NOT ALLOWED


MAX(SEQUENCE#)
--------------
       131

Standby Database Alert Logfile:
Thu Aug 03 20:05:37 2017
Media Recovery Log /home/oracle/u01/1_129_947265431.arc
Media Recovery Waiting for thread 1 sequence 130 (in transit)
Archived Log entry 130 added for thread 1 sequence 130 rlc 947265431 ID 0x6308ffab dest 2:
RFS[2]: No standby redo logfiles created
RFS[2]: Opened log for thread 1 sequence 131 dbid 1661358039 branch 947265431
Media Recovery Log /home/oracle/u01/1_130_947265431.arc
Media Recovery Waiting for thread 1 sequence 131 (in transit)
Thu Aug 03 20:05:45 2017
Archived Log entry 131 added for thread 1 sequence 131 rlc 947265431 ID 0x6308ffab dest 2:
RFS[2]: No standby redo logfiles created
RFS[2]: Opened log for thread 1 sequence 132 dbid 1661358039 branch 947265431
Thu Aug 03 20:05:48 2017
Media Recovery Log /home/oracle/u01/1_131_947265431.arc
Media Recovery Waiting for thread 1 sequence 132 (in transit)


 You have successfully converted physical standby database into Active Dataguard.


Also convert back it into physical standby database using below method:

Step 1: You need to stop MRP process before converting back into physical standby database otherwise you will get below error message.

SQL> alter database close;
alter database close
*
ERROR at line 1:
ORA-10457: cannot close standby database due to active media recovery


SQL> alter database recover managed standby database cancel;

Database altered.



Step 2: Close the database instead of restarting it and check the database status.


SQL> alter database close;

Database altered.

SQL> 

NAME      DB_UNIQUE_NAME         DATABASE_ROLE      OPEN_MODE           CONTROL SWITCHOVER_STATUS
--------- ------------------------------ ---------------- -------------------- ------- --------------------
DC      DR                 PHYSICAL STANDBY MOUNTED           STANDBY NOT ALLOWED


MAX(SEQUENCE#)
--------------
       131

Step 3: Start the MRP process.

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

Database altered.


Step 4: Switch 2-3 logs from primary database and check logs are getting applied on standby from primary.

On Primary:
SQL> alter system switch logfile;

System altered.

SQL> /

System altered.

SQL> /
/
System altered.

SQL> 

System altered.

Standby Alert Log File:

Thu Aug 03 20:17:16 2017
Media Recovery Log /home/oracle/u01/1_132_947265431.arc
Media Recovery Log /home/oracle/u01/1_133_947265431.arc
Media Recovery Log /home/oracle/u01/1_134_947265431.arc
Media Recovery Log /home/oracle/u01/1_135_947265431.arc
Media Recovery Waiting for thread 1 sequence 136 (in transit)

SQL> 

NAME      DB_UNIQUE_NAME         DATABASE_ROLE      OPEN_MODE           CONTROL SWITCHOVER_STATUS
--------- ------------------------------ ---------------- -------------------- ------- --------------------
DC      DR                 PHYSICAL STANDBY MOUNTED           STANDBY NOT ALLOWED


MAX(SEQUENCE#)
--------------
       135

Convert the physical standby to snapshot standby database in oracle dataguard

A Snapshot Standby database still receives redo data from the primary but it does not apply the redo data until after it converted back to a physical standby. Keep in mind that a snapshot standby database cannot be the target of a switchover or failover. A snapshot must be converted back to a physical standby prior to performing a role transition. Flashback Database technology is used in the conversion process so the Fast (Flash) Recovery area must be configured.

This document will detail the steps to manually convert a physical standby to a snapshot standby.

Convert the Physical Standby Database into a Snapshot Standby Database

On the standby database stop redo apply.

SQL> alter database recover managed standby database cancel;

Database altered.

SQL> 
Next convert the standby database to a snapshot standby.


SQL> alter database convert to snapshot standby;

Database altered.

SQL> 
Once the conversion is complete all that is left is to open the database.


SQL> alter database open;

Database altered.

SQL> 
You can verify the role change by querying the DATABASE_ROLE from V$DATABASE.


SQL> select database_role from v$database;

DATABASE_ROLE
----------------
SNAPSHOT STANDBY

SQL> 
While the standby is in snapshot standby mode you are free to run transactions against the snapshot standby.

While the standby is in snapshot mode it still continues to receive redo data from the primary but it does not apply the redo data. You verify the transport by switching logs on the primary and looking at the alert log on the standby.


Thu Jun 17 11:15:41 2010
RFS[6]: Selected log 5 for thread 1 sequence 981 dbid 459961910 branch 719914169
Thu Jun 17 11:15:41 2010
Archived Log entry 1513 added for thread 1 sequence 980 ID 0x1b7c5492 dest 2:
RFS[6]: Selected log 4 for thread 1 sequence 982 dbid 459961910 branch 719914169
Thu Jun 17 11:15:42 2010
When the standby was converted to a snapshot a guaranteed restore point was created. You can see this in the alert log for the standby.


Thu Jun 17 09:44:44 2010
RVWR started with pid=30, OS id=9171
Allocated 3981120 bytes in shared pool for flashback generation buffer
Created guaranteed restore point SNAPSHOT_STANDBY_REQUIRED_06/17/2010 09:44:44
krsv_proc_kill: Killing 3 processes (all RFS)
Begin: Standby Redo Logfile archival
End: Standby Redo Logfile archival

When the snapshot standby is converted back into a physical standby this restore point will be used to flashback the standby to its original state prior to the conversion. If any operation is performed on the snapshot that cannot be reversed with Flashback Database will prevent the snapshot standby from being converted back to a physical standby.

Convert the Snapshot Standby Database back to a Physical Standby Database

Shutdown the snapshot standby database and bring it back up in the mount state.


SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount 
ORACLE instance started.

Total System Global Area  830930944 bytes
Fixed Size                  2217912 bytes
Variable Size             603981896 bytes
Database Buffers          222298112 bytes
Redo Buffers                2433024 bytes
Database mounted.
SQL> 

Next convert the snapshot to a physical standby.

SQL> alter database convert to physical standby;

Database altered.

SQL>

In the standby alert log you can see that Flashback restore completed and the restore point was dropped.


Thu Jun 17 11:48:29 2010
alter database convert to physical standby
ALTER DATABASE CONVERT TO PHYSICAL STANDBY (standby)
krsv_proc_kill: Killing 4 processes (all RFS)
Flashback Restore Start
Flashback Restore Complete
Stopping background process RVWR
Deleted Oracle managed file /u01/app/flash_recovery_area/STANDBY/flashback/o1_mf_61nf6w8g_.flb
Deleted Oracle managed file /u01/app/flash_recovery_area/STANDBY/flashback/o1_mf_61ngk05r_.flb
Guaranteed restore point  dropped
Clearing standby activation ID 461943091 (0x1b88b133)
The primary database controlfile was created using the
'MAXLOGFILES 16' clause.
There is space for up to 13 standby redo logfiles
Use the following SQL commands on the standby database to create
standby redo logfiles that match the primary database:
ALTER DATABASE ADD STANDBY LOGFILE 'srl1.f' SIZE 52428800;
ALTER DATABASE ADD STANDBY LOGFILE 'srl2.f' SIZE 52428800;
ALTER DATABASE ADD STANDBY LOGFILE 'srl3.f' SIZE 52428800;
ALTER DATABASE ADD STANDBY LOGFILE 'srl4.f' SIZE 52428800;
Completed: alter database convert to physical standby

Shutdown the database and bring it back to the mount state.


SQL> shutdown immediate
ORA-01507: database not mounted


ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.

Total System Global Area  830930944 bytes
Fixed Size                  2217912 bytes
Variable Size             603981896 bytes
Database Buffers          222298112 bytes
Redo Buffers                2433024 bytes
Database mounted.
SQL> 
If you take a look in the alert log you will see that the archive logs shipped when the standby was a snapshot standby are now applied.


Media Recovery Log /u01/app/oracle/oradata/standby/arch/1_970_719914169.dbf
Media Recovery Log /u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_971_719914169.dbf
Media Recovery Log /u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_972_719914169.dbf
Media Recovery Log /u01/app/oracle/oradata/standby/arch/1_973_719914169.dbf
Media Recovery Log /u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_974_719914169.dbf
Media Recovery Log /u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_975_719914169.dbf
Media Recovery Log /u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_976_719914169.dbf
Media Recovery Log /u01/app/oracle/oradata/standby/arch/1_977_719914169.dbf

Using Snapshot Standby you can leverage your standby for testing or other special purposes temporarily will still protecting your primary database.

Oracle data guard switch over and fail over

1. [PRIMARY] Switch log file on primary database.

SQL>alter system switch logfile;
2. [PRIMARY] Check switchover status before switching database.

SQL>select switchover_status from v$database;
You must see “TO_STANDBY” as result.

3. [PRIMARY] Switch primary database to standby database.

SQL>alter database commit to switchover to physical standby with session shutdown;

SQL>shutdown immediate;

SQL>startup nomount;

SQL>alter database mount standby database;
4. [PRIMARY] Defer for archive log apply. Because I didn’t set  my standby database as primary yet.

SQL>alter system set log_archive_dest_state_2=defer;
5. [Standby] Switch standby database to primary. Check switchover status before switching database.

SQL>select switchover_status from v$database;
You must see “TO_PRIMARY” as result. Now let’s swtich

SQL>alter database commit to switchover to primary;

SQL>shutdown immediate;

SQL>startup;
Our switchover process is successfully completed .
6. [PRIMARY] Start real-time recovery process..

SQL>recover managed standby database using current logfile disconnect;
Finally let’s open our database with “Read Only with Apply”.

SQL>recover managed standby database cancel;

SQL>alter database open;

SQL>recover managed standby database using current logfile disconnect;
FAILOVER:

In short, the failover is the deformation of the production (primary) database and activating standby database as the primary. It is not reversible. When enabled, re-create the standby database. What to do in case of failover:

(Important note: PRIMARY is the primary server and Standby is the standby server)

1. [PRIMARY] If the primary database is accessible and running, then it must provided  to send redo buffer to the standby database.

SQL> alter system flush redo to standby_db_name;

SQL>alter system archive log current;
If you don’t receive an error, you can continue with step 5th. In this case, the system can be opened by zero data loss. If you receive an error, We continue with step 2 to open the system at least data loss.

2. [Standby] We must run the following query to learn last applied archive log sequence number.

SQL> SELECT UNIQUE THREAD# AS THREAD, MAX(SEQUENCE#) OVER (PARTITION BY thread#) AS LAST from V$ARCHIVED_LOG;
3. [PRIMARY’dan Standby’ye] If you can access archive logs which are not copied to standby then copy archives to standby. After copy archive log files we must register them to standby database. This operation must be done for every thread.

SQL> alter database register physical logfile '/oracle/ora11g/dbs/arch/ TALIP_991834413_1_102.arc ';
4. [Standby] Check the standby database for redo gap. If there is a gap then we must copy archive log files and register.

SQL> SELECT THREAD#, LOW_SEQUENCE#, HIGH_SEQUENCE# FROM V$ARCHIVE_GAP;

SQL> alter database register physical logfile '/oracle/ora11g/dbs/arch/ TALIP_991834413_1_101.arc ';
As a result of the above query until it returns to zero.

5. [Standby] Stop the redo apply process in standby database.

SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;
6. [Standby] Finish to apply archive logs copied from primary.

SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE FINISH;
If you get an error, it means there are redo logs not applied. Consider 2th and 4th steps. You can also continue with following command;

SQL> ALTER DATABASE ACTIVATE PHYSICAL STANDBY DATABASE;
In this situation you can open database in 8th step.  If you get no error, continue with 7th step.

7. [Standby] Switch standby database to primary database.

SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY WITH SESSION SHUTDOWN;
8. [Standby] Open database.

SQL> ALTER DATABASE OPEN;
After opening standby database as primary with failover you must take full backup.

Oracle Dataguard background process, log apply service internals

Dataguard Background process:
1.       Logwriter process
2.       Archiver process
3.       Logwriter network server (LNS)
4.       Fetch archive logs (FAL) For client server mechanism
5.       Remote file server
6.       Managed recovery process for physical standby
7.       Logical standby process for logical standby
8.       Data guard broker monitor (DMON) – If incase dg broker enabled

Apply services at High Level-          Data guard apply services comprises of two parts
o   Redo Apply for physical standby
o   Sql Apply for logical standby

-        The Physical standby and logical standby databases utilize the same redo transport and role management services, only apply service is different.

Redo apply: A physical standby database applies redo data received from the primary database using oracle media recovery process.
  1.    Redo applies uses a specialized process called the managed recovery process.
  2.   As the RFS process is writing redo data to standby redo logs (SRL’s). MRP process reads the redo data and applies it to the physical standby database.
  3.    MRP is started in the physical standby database by mounting the database using below command.
-          Sql > alter database recover managed standby database using current logfile disconnect from the session;

Sql Apply: Sql apply uses a collection of background process that perform the task of applying changes from the primary database to the logical standby database.

 Logical standby database:
  • -          Logical standby database contains the same logical information at standby DB.
  • -          Physical organization and structure of the data can be different.
  • -          Synchronization with the primary database through sql apply.
  • -          Can be used for queries and reporting at any time.

-         Service to be involved for logical standby : Log transport services, Log apply services

Log Transport services:  Transmit the redo data from the primary database to standby. Enforce the data protection modes.

Log apply services: Automatically apply the archived redo logs on the standby database. Maintains transitional synchronization with primary database. Allows transitionally consistent read-only access to the data.