Sunteți pe pagina 1din 29

Client Connectivity

in a DataGuard
Environment
Harald van Breederode
Oracle University
4-DEC-2007

Copyright 2008, Oracle. All rights reserved.

About Me

Senior Principal DBA Trainer Oracle University


25 years Unix Experience
12 years Oracle DBA Experience
Oracle8i, 9i, 10g and 11g OCP
Oracle10g OCM
DBA Certification Exam Team Reviewer
DBA Curriculum Development Reviewer
Enterprise Linux Certification Exam Global Lead
Visually Impaired (Legally Blind)

Copyright 2008, Oracle. All rights reserved.

Agenda

Introduction
What is DataGuard
Types of DataGuard Databases
Role Management Services
The Client Connection Problem
The Solution
Sample Implementation
Demonstration
Questions & Answers

Copyright 2008, Oracle. All rights reserved.

What is DataGuard

High Availability and DR Solution


One or more additional databases at remote
locations
These are called Standby Databases
They may be local for proof of concept
DataGuard == Standby Database plus extras:
DataGuard Broker
Grid Control Management Interface
CLI Management Interface
Role Management Services

Copyright 2008, Oracle. All rights reserved.

Types of DataGuard Databases

There are four types of DataGuard Databases:

Primary Database
The Database that needs protection
Transports Redo to its Standby Databases

Physical Standby Database


Exact physical copy of primary database
May be opened read only
Real Time Query permits redo apply whilst open
Read Only 11g
Synchronized with primary using Redo Apply

Copyright 2008, Oracle. All rights reserved.

Types of DataGuard Databases


(continued)

Snapshot Standby Database 11g


Physical Standby Database opened temporarily for
Read Write
Used for Real Application Testing (RAT)

Logical Standby Database

Logical copy of primary database


Is Read Write open for normal usage
Synchronized with primary using SQL Apply
Important for Rolling Release Upgrade

Copyright 2008, Oracle. All rights reserved.

Role Management Services


DataGuard Database roles may change dynamically
Switchover

A planned Role change


Primary and One Standby switch roles
Used for maintenance on the Primary
Always Initiated by the DBA

Failover
An unplanned Role change
Used when the Primary is broken or unreachable
due to network issues
Can happen automatically with Fast-Start Failover

Snapshot Standby Activation or Deactivation


RTQ Standby Activation or Deactivation
Copyright 2008, Oracle. All rights reserved.

Question
How do clients connect to databases
generally and what special
considerations exist in DataGuard
configurations?

Note: The term Client is used generically. It can be anything


connecting to a Database Instance: Traditional Client Server
applications or Middle Tiers

Copyright 2008, Oracle. All rights reserved.

General Client Connectivity

Server side:
PMON registers its instance with listeners

Client side:

connect user/password@NetServiceName
NetServiceName gets resolved to a TNS entry
Client sends connection request to a listener
Listener hands connection off to :
Dedicated server process
Dispatcher process

V1110 = (DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = PRUTSER)(PORT = 1521))
(CONNECT_DATA = (SERVICE_NAME = V1110)))

Copyright 2008, Oracle. All rights reserved.

DataGuard Client Connectivity Issues

As there are two or more databases in a DataGuard


configuration, clients must know on which hosts these
databases reside. Therefore TNS Entries must have a
CONNECTION_LIST section containing all hosts
participating in the DataGuard configuration

V1110 = (DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = PRUTSER)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = EL5)(PORT = 1521))
(CONNECT_DATA = (SERVICE_NAME = V1110)))

10

Copyright 2008, Oracle. All rights reserved.

Question
What happens if connection requests
go to the wrong host or Database?

11

Copyright 2008, Oracle. All rights reserved.

Connecting to the Wrong Database


If Clients send connection requests to the wrong host
they may be connected to the wrong database or
connection errors may occur.
Possible Connection Error
ORA-01033: ORACLE initialization or shutdown
in progress

Potential Connections to Wrong Databases

12

RTQ instead of Primary


Logical Standby instead of Primary
Snapshot Standby instead of Primary
Primary instead of Snapshot Standby
Primary instead of RTQ
Primary instead of Logical Standby
Plus several other possibilities
Copyright 2008, Oracle. All rights reserved.

Question
How can one prevent clients from
connecting to the wrong Database?

13

Copyright 2008, Oracle. All rights reserved.

Use Database Services

Database Services act as an abstraction layer


between the Client and Database Instances
Primarily used for Workload Management
RAC and Single Instance Databases use them
Services are registered with Listeners
Clients connect to Services instead of Instances
Listeners use registration details to determine
which instance(s) support(s) a particular service
Can be used as a tuning dimension
V$SERVICE_STAT
V$SERVICE_EVENT

Can be used to trace sessions


DBMS_MONITOR package

14

Copyright 2008, Oracle. All rights reserved.

Service Attributes

A Service has several attributes:


A Service Name for Administration purposes
A Network Name for Services that are meant for
external Client Connections
Transparent Application Failover attributes for
Client Connections that should be TAF enabled

15

Copyright 2008, Oracle. All rights reserved.

Managing Services

Services are managed with the DBMS_SERVICE


package. The following actions can be performed:
Create
Start
Modify
Stop
Delete
Note: This discussion is limited to Single Instance usage

16

Copyright 2008, Oracle. All rights reserved.

Creating the Services

The Service for the Primary Database:

DBMS_SERVICE.CREATE_SERVICE( SERVICE_NAME => 'DG_PROD', NETWORK_NAME => 'DG_PROD', FAILOVER_METHOD => 'BASIC', FAILOVER_TYPE => 'SELECT', FAILOVER_RETRIES => 180, FAILOVER_DELAY => 1);

17

Copyright 2008, Oracle. All rights reserved.

Creating the Services


(continued)
The Service for the Real Time Query Database
DBMS_SERVICE.CREATE_SERVICE( SERVICE_NAME => 'DG_RTQ', NETWORK_NAME => 'DG_RTQ');

The Service for the Logical Standby Database


DBMS_SERVICE.CREATE_SERVICE( SERVICE_NAME => 'DG_LSD', NETWORK_NAME => 'DG_LSD');

The Service for the Snapshot Standby Database


DBMS_SERVICE.CREATE_SERVICE( SERVICE_NAME => 'DG_RAT', NETWORK_NAME => 'DG_RAT');
18

Copyright 2008, Oracle. All rights reserved.

Question
How can we control Database
Services so that clients are
guaranteed connections to the
correct database in the DataGuard
Configuration?

19

Copyright 2008, Oracle. All rights reserved.

Use a Database Event Trigger

Event Triggers were introduced in Oracle 8.1.6

We Require the AFTER STARTUP Trigger:

20

Invoked when ALTER DATABASE OPEN occurs


Can check DATABASE_ROLE in V$DATABASE
Can check OPEN_MODE in V$DATABASE
Should use DBMS_SERVICE package to start the
appropriate service

Copyright 2008, Oracle. All rights reserved.

Use a Database Event Trigger


(continued)

Based on Service names defined earlier the


Trigger must start Services as follows:
DG_PROD on the Primary
DG_RTQ when the Physical Standby is opened
Read Only
DG_LSD on a Logical Standby
DG_RAT when a Physical Standby is converted to a
Snapshot Standby

21

Copyright 2008, Oracle. All rights reserved.

Demo AFTER STARTUP Trigger


CREATE TRIGGER MANAGE_SERVICES AFTER STARTUP ON DATABASE
DECLARE
ROLE VARCHAR(30);
OMODE VARCHAR(30);
BEGIN
SELECT DATABASE_ROLE INTO ROLE FROM V$DATABASE;
SELECT OPEN_MODE INTO OMODE FROM V$DATABASE;
IF ROLE = 'PRIMARY' THEN
DBMS_SERVICE. START_SERVICE ('DG_PROD');
ELSIF ROLE = 'PHYSICAL STANDBY' THEN
IF OMODE = 'READ ONLY' THEN
DBMS_SERVICE. START_SERVICE ('DG_RTQ');
END IF;
ELSIF ROLE = LOGICAL STANDBY' THEN
DBMS_SERVICE. START_SERVICE ('DG_LSD');
ELSIF ROLE = 'SNAPSHOT STANDBY' THEN
DBMS_SERVICE. START_SERVICE ('DG_RAT');
END IF;
END;
/
22

Copyright 2008, Oracle. All rights reserved.

Question
Now that we can control which
services are started in which
database instances, how do we
guarantee that clients can connect?

23

Copyright 2008, Oracle. All rights reserved.

Use Appropriate TNS Entries


PROD = (DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = prutser)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = el5)(PORT = 1521))
(CONNECT_DATA = (SERVICE_NAME = DG_PROD)))
RTQ = (DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = prutser)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = el5)(PORT = 1521))
(CONNECT_DATA = (SERVICE_NAME = DG_RTQ)))
RAT = (DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = prutser)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = el5)(PORT = 1521))
(CONNECT_DATA = (SERVICE_NAME = DG_RAT)))
LSD = (DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = prutser)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = el5)(PORT = 1521))
(CONNECT_DATA = (SERVICE_NAME = DG_LSD)))

24

Copyright 2008, Oracle. All rights reserved.

Demonstration

The demo environment consists of:


Virtual Machine PRUTSER OEL4
Virtual Machine EL5 OEL5
Oracle Database 11g 11.1.0.6.0
Database Name V1110
DataGuard is already configured
All demos are scripted

To request these demo scripts please Email me at:


Harald.van.Breederode@Oracle.com

25

Copyright 2008, Oracle. All rights reserved.

Scenario #1 and #2

Connecting to a DataGuard configuration without


using Database Services
Based on randomness we either get:
The connection we desire or
An ORA-01033: init or shutdown in progress

Connecting to the Primary in a DataGuard


configuration using a TAF Enabled Database
Service
Once connected we perform a switchover

26

Copyright 2008, Oracle. All rights reserved.

Scenario #3 and #4

Connecting to a Snapshot Standby in a DataGuard


configuration using a Database Service
First without a Snapshot Standby
Second with a Snapshot Standby

Connecting to a Physical Standby opened Read


Only in a DataGuard configuration using a
Database Service
First without a Read Only opened Physical Standby
Second with a Read Only opened Physical Standby

27

Copyright 2008, Oracle. All rights reserved.

Q U E S T I O N S

&

ANSWERS

28

Copyright 2008, Oracle. All rights reserved.

Final words

Thank You for your kind attention!


I will be at the Oak Table from time to time during the
conference for further discussion.
Please Email any feedback to:
Harald.van.Breederode@Oracle.com

29

Copyright 2008, Oracle. All rights reserved.

S-ar putea să vă placă și