36
7/17/2019 OraFAQ Forum http://slidepdf.com/reader/full/orafaq-forum 1/36  Setting Up a Hot Standby Database Chris Lawson Database Specialists, Inc. www.dbspecialists.com [email protected]

OraFAQ Forum

Embed Size (px)

DESCRIPTION

OraFAQ Forum

Citation preview

Page 1: OraFAQ Forum

7/17/2019 OraFAQ Forum

http://slidepdf.com/reader/full/orafaq-forum 1/36

 

Setting Up a HotStandby Database

Chris Lawson

Database Specialists, Inc.

www.dbspecialists.com

[email protected]

Page 2: OraFAQ Forum

7/17/2019 OraFAQ Forum

http://slidepdf.com/reader/full/orafaq-forum 2/36

 

Hot Standby Overview

DB1Primary

DB2Standby

Client Client   Read-onlyClient

Read-onlyClient

rchive Logs

Hot Standby provides a way !or a seconddatabase to automatically trac" a primary

database.

Page 3: OraFAQ Forum

7/17/2019 OraFAQ Forum

http://slidepdf.com/reader/full/orafaq-forum 3/36

 

Hot Standby Overview

#continued $% &rior to 'i, a standby database co(ld be created, b(t

witho(t the a(tomated !eat(res in the 'i version.

% hot standby database starts as a clone o! the primary, (sing any hot or cold bac"(p.

% In order to )"eep (p* with the primary, the standby

 per!orms two separate, ongoing tas"s+

   -eceive and store archive logs !rom the primary over

 et'.

   pply archive logs in proper order.

Page 4: OraFAQ Forum

7/17/2019 OraFAQ Forum

http://slidepdf.com/reader/full/orafaq-forum 4/36

 

/odes o! Operation

0he standby database has two

main modes o! operation+

 Recovery or Read-only

Page 5: OraFAQ Forum

7/17/2019 OraFAQ Forum

http://slidepdf.com/reader/full/orafaq-forum 5/36

 

/odes o! Operation+ Recovery

%  Managed Recovery is the normal mode o! operation. In this mode, the

standby database loo"s !or and applies each archive log as it is

received. Once started, no D1 intervention is re2(ired.

%  Manual Recovery may also be activated (nder some circ(mstances33

namely whenever an archive log has been man(ally trans!erred to the

standby server and needs to be applied. In man(al recovery, the D1

starts database recovery.

DB1Primary

DB2Standby

 et '

rchive logs#dest 4$

rchive logsrchive logs#dest 5$

Page 6: OraFAQ Forum

7/17/2019 OraFAQ Forum

http://slidepdf.com/reader/full/orafaq-forum 6/36

 

/odes o! Operation+ Read-only

% In read3only mode, the database is act(ally open to all (sers !or in2(iries.

% 0he archive logs contin(e to be trans!erred over et', b(t are not yet

applied.

% 6henever the mode is changed bac" to recovery, log application res(mes

as the standby )catches (p.*

%   Note: rchive logs contin(e to be sent !rom the primary to the standby,

regardless o! which mode is in e!!ect.

DB1Primary

DB2Standby

Client Client

rchive Logs

Read-onlyClient

Read-onlyClient

Page 7: OraFAQ Forum

7/17/2019 OraFAQ Forum

http://slidepdf.com/reader/full/orafaq-forum 7/36

 

dvantages o! Hot Standby% It really wor"s7 Doc(mentation is reasonably good.% 8airly easy to set (p33no special operating system or database options

re2(ired.

%  o special D1 training is re2(ired #in contrast to O&S$.

% ctivation o! standby is not complicated33b(t be s(re to doc(ment and test a

 proced(re speci!ic !or yo(r site.

% Standby database can act(ally be opened !or 2(eries, then ret(rn to recovery

mode. 0his may !acilitate o!!3loading large reports or other batch 9obs, so that

 per!ormance on primary database is not degraded.

% Standby database will trac" act(al prod(ction very closely33it will typically

)lag* by only one archive log !ile, perhaps a delay o! only 5: min(tes or so.

• Standby database is typically on a completely separate server and !ile system,

 providing sa!ety i! disaster stri"es.

Page 8: OraFAQ Forum

7/17/2019 OraFAQ Forum

http://slidepdf.com/reader/full/orafaq-forum 8/36

 

Disadvantages o! Hot Standby

% Hot standby only provides limited load3balancing beca(se

all (sers #e;cept !or read3only (sers$ m(st contin(e to (se

the primary.

% In contrast, O&S #Oracle &arallel Server$ or replicationallow (se o! m(ltiple instances sim(ltaneo(sly.

% 8or databases with heavy transaction activity, there will be

increased networ" tra!!ic d(e to log trans!er.

% I! primary server crashes, and standby database needs to beactivated, it may be impossible to access the last archive

log on the primary. These transactions will be lost .

% Smaller redo logs will minimi<e this loss by increasing the

!re2(ency o! log trans!ers.

Page 9: OraFAQ Forum

7/17/2019 OraFAQ Forum

http://slidepdf.com/reader/full/orafaq-forum 9/36

 

&reliminary Set(p

% =ns(re primary database is in archive mode, and

correctly writes archive logs.

% =ns(re temp tablespace is mar"ed as temporary% /a"e a standby control !ile to (se as the starting

 point !or the standby database. e.g.,

alter database create standby controlfile as '/path';

% Copy over all .db! !iles, standby control !ile and redologs !rom D15 server to D14.

Page 10: OraFAQ Forum

7/17/2019 OraFAQ Forum

http://slidepdf.com/reader/full/orafaq-forum 10/36

 

Set(p &rimary init.ora 8ile

% dd entries to write second set o! archive logs> the

destination is not a directory, b(t a tns alias that

matches the standby connection.log_archive_dest_2='SERVICE=!IS optional reopen= "#$'

log_archive_dest_state_2=E%&!E

%   Note: 

   reopen=180  means wait 5'? seconds be!ore re3attempting!ailed archive.

   optional  means contin(e even i! archival to seconddestination !ails.

Page 11: OraFAQ Forum

7/17/2019 OraFAQ Forum

http://slidepdf.com/reader/full/orafaq-forum 11/36

 

Standby Control 8ile =;planation

% 0he primary control !ile cannot be (sed as3is, beca(se the

control !ile has .db! and redo !ile locations !or primary.

% Instead o! creating a new control !ile, the primary control

!ile is adapted !or (se by the standby.

% 6itho(t some type o! correction, the standby will loo" in the

wrong location !or the redo and .db! !iles.

DB1Primary

DB2Standby

Controlfle

Controlfle

/u01/ datafles

/u02/ datafles

Standby expects data fles to beon /u01, but they

aren’t !

Page 12: OraFAQ Forum

7/17/2019 OraFAQ Forum

http://slidepdf.com/reader/full/orafaq-forum 12/36

 

Standby Control 8ile =;planation

% Several new init.ora parameters allow the standby database

to translate directory paths !rom where !iles were locatedon the primary, to where they are on the standby.

Standby

control

fle

.dblocation

redo log

location db_file_name_convert

log_file_name_convert  new .db

pat

new .dbpat

Page 13: OraFAQ Forum

7/17/2019 OraFAQ Forum

http://slidepdf.com/reader/full/orafaq-forum 13/36

 

Standby Control 8ile =;planation

#continued $8or e;ample, i! the .db! !iles are on (?5 on primary,

then they co(ld be translated to (?4 on standby+

db_file_nae_convert=('/)$"'*'/)$2'+

0he path !or redo logs is similarly translated+ 

log_file_nae_convert=('/oradata"'*'/oradata2'+

Page 14: OraFAQ Forum

7/17/2019 OraFAQ Forum

http://slidepdf.com/reader/full/orafaq-forum 14/36

 

Con!ig(re Standby init.ora

db_name=,sae as priary-

lock_name_space=standby1  eeded i! primary A secondary share same host

log_archive_dest_1=.location=/)$$/app/oracle/adin/sec/arch. 

Used !or man(al recovery o! archive logs

standby_archive_dest = /)$$/app/oracle/adin/sec/arch 

0ypically set same as previo(s parameter 

db_file_name_convert = ('/)$"/oradata/prie'*'/)$2/oradata/sec'+ 

log_file_name_convert = ('/)$"/prie'*'/)$2/sec'+ Corrects !ile locations since control !ile originated !rom primary

Copy primary init.ora to standby and set(p !ollowingspecial parameters+

Page 15: OraFAQ Forum

7/17/2019 OraFAQ Forum

http://slidepdf.com/reader/full/orafaq-forum 15/36

 

&repare Standby Database

% I! (sing password3!ile a(thentication, create password !ile !orstandby+ orapd file=orap,SI0-

Note: Database Con!ig(ration ssistant will create init.ora !ile with

RE13E_!4I%_5SS6R07I!E=E8C!9SIVE, which implies need

!or the above password !ile.

% Connect internal, then per!orm start)p noo)nt;

% &er!orm alter database o)nt standby database;

% Set standby database in /anaged #a(tomatic$ -ecovery /oderecover anaged standby database;

Note: &rompt will not ret(rn> doc(mentation s(ggests )r(n on the

main console.*

% S(ggestion+ &(t last command above in script and r(n as noh(p.

Page 16: OraFAQ Forum

7/17/2019 OraFAQ Forum

http://slidepdf.com/reader/full/orafaq-forum 16/36

 

Chec"ing 0rans!er o!

rchive Logs

% 6hen the hot standby is wor"ing properly, two things are

happening+

5. rchive logs are being trans!erred> and

4. 0hese logs are being a(tomatically applied

% On the primary database, per!ormalter syste sitch log file;

% new archive log sho(ld appear within a !ew min(tes in the

standby database archive location.% I! no log appears, chec" the alert.log !or the primary database

to chec" !or problems connecting to the standby.

% lso chec" vBarchivedest to con!irm that all log

destinations are enabled.

Page 17: OraFAQ Forum

7/17/2019 OraFAQ Forum

http://slidepdf.com/reader/full/orafaq-forum 17/36

 

Chec"ing pplication o!

rchive LogsOn the standby database, review the last portion o! the

alert.log. s each log is applied, there sho(ld be a new

entry listing the log n(mber 1edia Recovery Start: 1anaged Standby Recovery

1edia Recovery !og

1edia Recovery 6aiting for thread " se< >?

6ed @)n 2" "$:#:$> 2$$$

1edia Recovery !og /)$$/app/oracle/adin/db2/arch/arch_"_>?Aarc1edia Recovery 6aiting for thread " se< >>

6ed @)n 2" "$:#:22 2$$$

1edia Recovery !og /)$$/app/oracle/adin/db2/arch/arch_"_>>Aarc

1edia Recovery !og /)$$/app/oracle/adin/db2/arch/arch_"_>BAarc

1edia Recovery 6aiting for thread " se< >#

Page 18: OraFAQ Forum

7/17/2019 OraFAQ Forum

http://slidepdf.com/reader/full/orafaq-forum 18/36

 

Chec"ing pplication o!

rchive Logs #continued $• I! logs are not being applied, be s(re that the

e;pected archive log e;ists on the standby.

• I! there is a )gap,* then the log sho(ld be

man(ally copied to the standby server, and manual  

recovery per!ormed.

• Once the gap is )pl(gged,* then the a(tomatic

recovery can be restarted.

Page 19: OraFAQ Forum

7/17/2019 OraFAQ Forum

http://slidepdf.com/reader/full/orafaq-forum 19/36

 

/ode Change

0he standby database mode can be switched bac" and

!orth at will+

Switch to -ead3Only /ode

% 8irst, cancel managed recovery+ recover anagedstandby database cancel;

% 0hen, set to read3only+ alter database open read only;

Switch bac" to /anaged -ecovery#0his restarts the archive log application$

% 8irst, con!irm there are no sessions active>

% 0hen, res(me a(tomatic recovery+ recover anaged

standby database;

Page 20: OraFAQ Forum

7/17/2019 OraFAQ Forum

http://slidepdf.com/reader/full/orafaq-forum 20/36

 

6hen Disaster Stri"es+

ctivating Standby Database% Important7 Opening standby database will terminate the

 standby recovery process.

% -eversal bac" to recovery processing is O0 possible, as an

implicit r esetlogs is per!ormed (pon activation.% 0his is very similar to what is done in a database )clone*,

r(nning alter database open resetlogs;

% I! primary still operational, e"e o(t last archive log (sing

alter syste archive log c)rrent;% /an(ally trans!er archive log i! necessary, p(tting in archive

destination.

% pply as many logs as are available (sing manual  recovery+recover standby database;

Page 21: OraFAQ Forum

7/17/2019 OraFAQ Forum

http://slidepdf.com/reader/full/orafaq-forum 21/36

 

ctivating Standby Database

#continued $% ctivate standby+

alter database activate standby database;

sh)tdon iediate;

start)p o)nt;

alter database open read rite;

% &repare the new database !or the archive mode#pres(mably$.

% 0a"e physical bac"(p o! the newly activated database.% Set (p new standby database, (sing the new physical

 bac"(p.

Page 22: OraFAQ Forum

7/17/2019 OraFAQ Forum

http://slidepdf.com/reader/full/orafaq-forum 22/36

 

-estarting Interr(pted Log 0rans!er 

% Con!irm standby database is once again in startup

nomount state.

% On primary, con!irm error in trans!er stat(s. ote

!ailing dest_id +select dest_id* stat)s* target* error fro varchive_dest;

I! the standby database is brie!ly stopped, the archive

log trans!er !rom the primary may be interr(pted, and

the trans!er error may need to be man(ally reset.

Page 23: OraFAQ Forum

7/17/2019 OraFAQ Forum

http://slidepdf.com/reader/full/orafaq-forum 23/36

 

-estarting Interr(pted Log 0rans!er

#continued $

% On primary, reset archiving error #replace n with

n(mber o! !ailing destination$.

Note: =ven tho(gh reopen is speci!ied, log trans!erappears to re2(ire resetting the error+

alter syste set log_archive_dest_state_n = enable;

0ES3_I0 S339S 3R4E3 0ES3I%3I% ERRR

DDDDDDD DDDDDD DDDDDD DDDDDDDDDDD DDDDDDD

  " V!I0 5RI1R /db"/arch

  2 ERRR S3%0& db2 RDFFFF

Page 24: OraFAQ Forum

7/17/2019 OraFAQ Forum

http://slidepdf.com/reader/full/orafaq-forum 24/36

 

-estarting Interr(pted Log

0rans!er #continued $% &er!orm log switch on primary and con!irm that a

new archive log appears at standby.

% /an(ally trans!er any missing archive logs !rom

 primary to standby. /an(ally apply these logs+

recover standby database;

% -et(rn to a(tomatic recovery+ 

recover anaged standby database;

Page 25: OraFAQ Forum

7/17/2019 OraFAQ Forum

http://slidepdf.com/reader/full/orafaq-forum 25/36

 

Client Set(p !or (tomatic 8ailover 

% In tnsnames.ora, (se 8ILOE=- parameter. 6hen set

to O, instr(cts et', at connect time, to !ail over to a

di!!erent address i! the !irst address !ails. 6hen set to

O88, instr(cts et' to try one address.

net_service_nae=

(description=

(failover=on+(address=(protocol=tcp+(host=server"+(port="?2"++

(address=(protocol=tcp+(host=server2+(port="?2"++

(connect_data=(service_nae=db"AaceAco+++

Page 26: OraFAQ Forum

7/17/2019 OraFAQ Forum

http://slidepdf.com/reader/full/orafaq-forum 26/36

 

Client Set(p !or (tomatic 8ailover 

#continued $%   Important: Do not set the FLO1LD1/=

 parameter in the SIDLIS0listenername section

o! the listener.ora. statically con!ig(red globaldatabase name disables connect3time !ailover.

% Only m(ltiple addresses #not connectdata$ are

speci!ied, thereby re2(iring that the standby

database#s$ has the same SID or servicename.

Page 27: OraFAQ Forum

7/17/2019 OraFAQ Forum

http://slidepdf.com/reader/full/orafaq-forum 27/36

 

0ranslation Complications

% -emember how the .db! and log pathnames need

to be translated (sing two )special* init.ora

 parameters.% 0he standby database will loo" in a di!!erent

directory (sing the new parameters as a

)translator.*

Page 28: OraFAQ Forum

7/17/2019 OraFAQ Forum

http://slidepdf.com/reader/full/orafaq-forum 28/36

 

0ranslation Complications

#continued $Problem:

8iles are typically not all in the same !ile system, b(t the

)translation* parameter can only translate !rom one directory to one 

directory. How can !iles in the )other* directories be )!i;edG*Primary   Standby

/u0!/ data

/u01/ data

/u0"/ data

/u02/ data ew parameter tells

Standby to to loo" in (?4

Standby will still be

loo"ing in (? !or these

!iles

8or e;ample+ db_file_nae_convert = ('/)$"'*'/)$2'+

Page 29: OraFAQ Forum

7/17/2019 OraFAQ Forum

http://slidepdf.com/reader/full/orafaq-forum 29/36

 

0ranslation Complications

#continued $Solution:

% On the #mo(nted$ standby database, prior to beginning

recovery, manually correct the !ile names that are not

covered by the two init.ora parameters.

Primary Standby

/u01/ data /u02/ data

/u0!/ data /u0"/ data

&arameter corrects these !iles

/an(ally rename to (?JK

Page 30: OraFAQ Forum

7/17/2019 OraFAQ Forum

http://slidepdf.com/reader/full/orafaq-forum 30/36

 

0ranslation Complications

#continued $

% 8or .db! !ile, simply rename> !or redo log, drop the

gro(p, then add gro(p bac" into desired directory+

.dbf file: alter database renae file '/)$G/)ser$"Adbf'

to '/)$/)ser$"Adbf';

redo log: alter database drop logfile gro)p ?;

alter database add logfile gro)p ?

'/)$?/redo$?Alog' siHe 2$;

Page 31: OraFAQ Forum

7/17/2019 OraFAQ Forum

http://slidepdf.com/reader/full/orafaq-forum 31/36

 

dding Data!iles to &rimary Database

% dding a data!ile to the primary database generates

redo that adds the data!ile name only to the standby

control !ile> the data!ile m(st still be e;plicitly added

to the standby database.

% 0he sol(tion is simple, b(t not intuitive> so care!(lly

review and test these special cases.

% 8irst, add data!ile to primary database as (s(al.% 0hen, switch redo logs on the primary database to

initiate redo archival to the standby database.

Page 32: OraFAQ Forum

7/17/2019 OraFAQ Forum

http://slidepdf.com/reader/full/orafaq-forum 32/36

 

dding Data!iles to &rimary Database

#continued $% -ecovery on the standby database will stop beca(se the

data!ile does not e;ist. Standby alert log +6-IF7 -ecovering data!ile 4 !rom a !(<<y !ile. I! not the c(rrent !ile it

might be an online bac"(p ta"en witho(t entering the begin bac"(p command.S(ccess!(lly added data!ile 4 K

% 0o resolve, create the data!ile on the standby database+alter database

create datafile '/)$2/oradata/testAdbf'as '/)$2/oradata/testAdbf';

% &lace the standby database in managed recovery mode+recover anaged standby database;

Page 33: OraFAQ Forum

7/17/2019 OraFAQ Forum

http://slidepdf.com/reader/full/orafaq-forum 33/36

 

Other 0ips A 0ric"s

% 0he doc(mented method o! connecting to standby appears

to be impossible. Resolution: (st (se the (s(al way to

connect to an idle instance+

connect internal or  connect / as sysdba

% =ns(re that the init.ora parameter,

O1MU=U=&-OC=SS=S N ?

#0his implies con!lict with the dvanced -eplication

Option, which typically sets parameter to J. I! parameter isnon3<ero, then standby mode change !rom read-only bac" to

recover  will !ail.$

Page 34: OraFAQ Forum

7/17/2019 OraFAQ Forum

http://slidepdf.com/reader/full/orafaq-forum 34/36

 

Other 0ips A 0ric"s

#continued $% 8inding which archive logs are need to !ill the )gaps*

seems to be (nd(ly complicated. Upon starting

recovery, the standby database will re2(est a partic(larlog, so why bother !ig(ring it o(tG

% I&C networ" connection parameters !or tnsnames.ora

!ile are )pic"ier* in 'i. ow the )"ey* val(e m(st

match on client and server. -elevant only to where

 primary and standby are on the same serverP

Page 35: OraFAQ Forum

7/17/2019 OraFAQ Forum

http://slidepdf.com/reader/full/orafaq-forum 35/36

 

Use!(l -e!erences

% Oracle /aga<ine, /ay(ne 5QQQ, )Implementing

an (tomated Standby Database,* by -oby

Sherman.% Oracle Corporation, racle 8i !tandby "atabase

#oncepts and $dministration Release % #'.5.R$

Page 36: OraFAQ Forum

7/17/2019 OraFAQ Forum

http://slidepdf.com/reader/full/orafaq-forum 36/36

Contact In!ormation

Chris Lawson

[email protected]

http://www.dbspecialists.com

Database Specialists, Inc.

'' /ar"et Street, S(ite J??

San 8rancisco, C QJ555