You are on page 1of 13

1

Quick Guide to configuring


Oracle 11gR2 Data Guard
Physical Standby
Part I
Author: Jed Walker is the Manager of Database Operations for the Comcast Media Center in Centennial
Colorado. He has been orking ith Oracle Database since 1!!" and is an Oracle Certified #rofessional for !i$
1%g$ and 11g Database.
Table of Contents
Table of Contents
&ntroduction..............................................................................................................................................................'
Wh( )se Data *uard+.............................................................................................................................................'
,(stem ,etup............................................................................................................................................................'
-he .asic ,tuff$ that & shouldn/t ha0e to mention...................................................................................................1
#reparing the #rimar( for Data *uard.....................................................................................................................1
)se 2lashback Database..........................................................................................................................................3
,er0er ,45678- Configuration.............................................................................................................................9
Configuring :edo -ransport...................................................................................................................................."
#reparing the ,tandb( en0ironment.........................................................................................................................;
Creating the ,tandb( Database..............................................................................................................................1%
,tarting :edo Appl( on the ,tandb(.....................................................................................................................11
<erif(ing that :edo Appl( is orking...................................................................................................................1=
Conclusion.............................................................................................................................................................1'
=
'
Introduction
Data *uard is an Oracle feature that primaril( pro0ides database redundanc(. -his is done b( ha0ing a standb(
>ph(sical cop(? database$ preferabl( in another location and on separate disk. -his standb( database is
maintained b( appl(ing the changes from the primar( database to it. ,tandb( databases can be maintained ith
either :edo >#h(sical standb(? or ,45 >5ogical standb(?.
M( intention ith this paper is primaril( to sho that configuring Data *uard is not comple@$ and does not
reAuire an( special skills or training to accomplish. &t ill step the reader Auickl( through the process of
configuring a #h(sical ,tandb( database for database redundanc( of the primar( s(stem. M( hope is that if
(ou/re ne to Data *uard$ Bust considering it$ or orried that it is too hard to setup$ this paper ill help (ou
Auickl( through the process and get (ou up and running.
&f (ou find mistakes$ additional important notes or considerations$ please let me kno.
hy !se Data Guard"
8ach Oracle High A0ailabilit( tool has its purpose. -he reasons e are used Data *uard for the s(stem that
prompted this paper$ are:
2ull database redundanc(
2ast reco0er( in the case of a failure
Abilit( for clients to automaticall( reconnect after a failure
Abilit( to offload the backup process to another ser0er
#ro0ides 0er( good Mean -ime -o :epair
7ot o0erl( comple@
Syste# Setu$
2or this particular e@ample$ & ill detail the en0ironment a bit so (ou kno hat &/m orking ith. After
riting the paper & used D.)A to create a brandCne database called J8D and reCran these steps to ensure that
on a basic Oracle 11g database this ould ork. -he #rimar( database is called J8D and resides on a ser0er
called de0Cdb1. -he ph(sical standb( ill be called J8D= and reside on a ser0er called de0Cdb=.
1
The %asic Stuff& that I shouldn't ha(e to #ention
2or an( production database there are some basics (ou should ha0e in place. One of these is to run in
A:CH&<85O* mode. -his should be an ob0ious configuration for a production database. &f (ou aren/t alread(
in A:CH&<85O* mode then (ou either need to start doing some reading and planning no$ or ha0e a 0er(
<8:D good reason >&/m not sure there is one$ but there is ala(s an e@ception to e0er( rule?. -o place (our
database in A:CH&<85O* mode:
SQL> archive log list;
&f (ou see
Database log mode Archive Mode
then (ou are fine$ otherise do the folloing:
SQL> shutdown immediate
SQL> startup mount
SQL> alter database archivelog;
SQL> alter database open;
SQL> archive log list;
Dou should see
Database log mode Archive Mode
Pre$aring the Pri#ary for Data Guard
Dou must no do some preparation on (our #rimar( database so that it is read( for Data *uard.
2irst$ for a #h(sical ,tandb( to be an e@act cop( it must recei0e redo for the changes made to the primar(. With
Oracle a database user can instruct the database to not log redo >e.g. the 7O5O**&7* clause?. 2or a ph(sical
standb( database this is a big problem$ so (ou must make sure that redo is logged regardless of hat a user tells
the database to do. -o do this (ou can turn on 2orced 5ogging. Here is ho:
SQL> alter database force logging;
SQL> select name, force_logging from vdatabase;
&n the 2O:C8E5O**&7* column (ou should no see D8,.
7e@t e/ll make sure that hen e add or drop datafiles on our primar( database$ that those files are also added
or dropped on the standb(. -his is done ith:
3
SQL> alter s!stem set standb!_file_management " #A$%&#;
Once this is done$ e need to make sure the primar( database has ,tandb( 5og 2iles. ,tandb( 5og 2iles are
used b( a standb( database to store the redo it recei0es from the primar( database. & create these on the primar(
for to reasons$ 1? it ma( become a standb( later and ould then need them$ =? hen e create the standb(
the( ill be created as part of that process. ,tandb( log files should be created the same siFe as the online
logfiles. #referabl( (ou should ha0e as man($ or more$ standb( logfile groups as online logfile groups. -o easil(
differentiate them in the <G 0ies$ & like to number m( standb( logfile groups so the( are in a different range
from online logfiles >e.g. online logfile groups ould be 1C9$ standb( logfile groups ould be 11C19?. -o create
a standb( logfile group:
alter database add standb! logfile group ''
(#)oradata)*+D)g''m,'-sdo#,#)oradata)*+D)g''m,.-sdo#/ si0e 1.2.33,,,;
&f (ou are not using ,,5 for :edo -ransport >likel( (ou aren/t?$ then (ou ill need to use Oracle passord file
authentication. 2or this (ou must create a passord file and ha0e :8MO-8E5O*&7E#A,,WO:D2&58 set to
8HC5),&<8 or ,HA:8D. &t is likel( this is alread( done so check first$ but if not:
SQL> alter s!stem set remote_login_passwordfile"e4clusive scope"spfile; >and bounce?
&S> orapwd password"5the s!s password>
Dou should also make sure (our primar( database has the dbEuniAueEname parameter set for consistenc(.
SQL> show parameter db_uni6ue_name
&f it isn/t set correctl( for some reason$ (ou can change it 0ia the A5-8: ,D,-8M command.
!se )lashback Database
-he ne@t thing & highl( recommend is to setup 2lashback Database. 2lashback Database allos (ou to
IflashbackJ (our database to a pre0ious point in time. -his is 0er( useful hen a failo0er occurs because (ou
can use it to flashback (our old primar( database and then acti0ate it as a ,tandb(. &f (ou don/t ha0e flashback
correctl( configured across (our Data *uard configuration then (ou ha0e to rebuild the ,tandb( hich means
cop(ing all those datafiles again. &n addition to this use$ 2lashback Database can (ou sa0e (ou from ha0ing to
restoreKreco0er (our database in some situations.
-o setup 2lashback Database (ou need to configure the 2ast :eco0er( Area first. -o do this set the
D.E:8CO<8:DE2&58ED8,- and D.E:8CO<8:DE2&58ED8,-E,&L8 parameters. -o configure these:
SQL> alter s!stem set db_recover!_file_dest"78!our_9:A_base_director!7;
SQL> alter s!stem set db_recover!_file_dest_si0e"2,,g;
7o that (ou ha0e the 2ast :eco0er( Area configured (ou need to turn on 2lashback 5ogging. -o do this:
SQL> alter database flashbac; on;
9
SQL> select flashbac;_on from vdatabase;
<erif( that the 25A,H.ACMEO7 column is D8,. &f (ou got the error J O:AC%113': an incompatible media
reco0er( is acti0eJ then (ou are likel( doing this on a standb( and need to cancel managed reco0er( and tr(
again. Don/t forget to restart managed reco0er( hen (ou/re done.
DO 7O- *8- .):78DN & disco0ered after a failo0er$ that turning flashback on 0ia Ialter databaseJ does not
propagate to (our standb( databases ith the redo >like man( other things?. Dou M),- run the alter database
command on each of (our standb( databases. &f (ou ha0en/t done this (ou/ll find later that (ou can/t flashback
after a failo0er and ill ha0e to completel( rebuild (our old primar( to make it a standb(.
Ser(er SQ*+,-T Configuration
.efore e create the standb( database$ e need to ensure the databases in our configuration ill be able to talk
to each other. -his is reAuired before creating the database if e ant to use the :MA7 Iduplicate from acti0e
databaseJ feature. -o do this e configure both the listener and -7,7ames. Dou can do these b( hand or b(
using the netork configurations tools. &/m old school and these files are not complicated$ so & prefer to do this
b( hand.
2irst (ou need to configure (our primar( and standb( database in (our listener. -he reason for this is that hile
the databases can selfCregister$ if (ou ant to create the standb( using :MA7 it ill need to be in 7OMO)7-
initiall(. &n 7OMO)7- the database instance ill not selfCregister ith the listener$ so (ou must tell the
listener it is there. Another item to note is that (ou must use dedicated ser0er to connect hen it is in
7OMO)7-.
-he -7, 7ames file on each ser0er ill need to be configured so that the databases can locate each other using
the ,er0ice 7ames configured in the 5O*EA:CH&<8ED8,-E7 and 2A5E,8:<8: parameters >e/ll get to
this later?. Configure (our files in a similar fashion to these e@amples.
#rimar( >de0Cdb1 O ser0er for J8D? ,tandb( >de0Cdb= O ser0er for J8D=?
5istener
S<D_L<S%_L<S%+=+: "
(S<D_L<S% "
(S<D_D+S> "
(?L&@AL_D@=AM+ " *+D/
(&:A>L+_A&M+ " )oracle)product)''-.-,/
(S<D_=AM+ " *+D/
/
/
S<D_L<S%_L<S%+=+: "
(S<D_L<S% "
(S<D_D+S> "
(?L&@AL_D@=AM+ " *+D./
(&:A>L+_A&M+ " )oracle)product)''-.-,/
(S<D_=AM+ " *+D./
/
/
-7,
7ames
*+D. "
(D+S>:<B%<&= "
*+D "
(D+S>:<B%<&= "
"
(ADD:+SS_L<S% "
(ADD:+SS " (B:&%&>&L " %>B/(A&S% " devCdb./
(B&:% " '1.'//
/
(>&==+>%_DA%A "
(S+:D<>+_=AM+ " *+D./
(S+:D+: " D+D<>A%+D/
/
/
(ADD:+SS_L<S% "
(ADD:+SS " (B:&%&>&L " %>B/(A&S% " devC
db'/(B&:% " '1.'//
/
(>&==+>%_DA%A "
(S+:D<>+_=AM+ " *+D/
(S+:D+: " D+D<>A%+D/
/
/
-esting
&S> lsnrctl reload
&S> tnsping *+D.
5should return &E>
&S> lsnrctl reload
&S> tnsping *+D
5should return &E>
Configuring Redo Trans$ort
7o that the databases ha0e the abilit( to talk to each other$ our ne@t step is to ensure that :edo is archi0ed and
transported appropriatel(. We/ll configure this on the e@isting primar( and then modif( the standb( after it is
created.
-o enable archi0ing of redo on our primar( e use the folloing command:
SQL> alter s!stem set log_archive_dest_' " #location"use_db_recover!_file_dest
valid_for"(all_logfiles, all_roles/ db_uni6ue_name"*+D#;
-his statement sa(s to use the D.E:8CO<8:DE2&58ED8,- as the location to archi0e to$ that it should be
used to archi0e all logfiles in an( >all? roles$ and that this is for the database J8D. -he manual sa(s to use
onlineElogfilesP hoe0er$ this ill result in the ,tandb( being unable to archi0e the standb( logfiles because
the( are not online logfiles. &f (ou use allElogfiles both the primar( and standb( ill be able to archi0e logfiles
hether the( are online or standb(. Dou/ll ant this if (ou/re backing up on the standb( and ant to ha0e
archi0ed logfiles backed up there too. Dou could configure this to archi0e onl( on the primar( or onl( on the
standb( if (ou/d like.
7e@t e configure the transport of the redo to the ,tandb( database.
SQL> alter s!stem set log_archive_dest_. " #service"*+D. as!nc
valid_for"(online_logfile,primar!_role/ db_uni6ue_name"*+D.#;
-his statement sa(s that if it is the primar( database$ it should transport online logfiles using the ser0ice name
J8D= and that the target is the database J8D=.
;
At this point$ & should note that the ,-A7D.DEA:CH&<8ED8,- parameter is deprecated and not needed.
While troubleshooting & had man( ellCintentioned suggestions to add this parameter$ but about all (ou/ll get
from it is IO:AC'=%%1: obsolete or deprecated parameter>s? specified for :D.M, instanceJ hen (ou start
(our database.
-he ne@t parameter is 2A5E,8:<8:. -his specifies here the database should look for missing archi0e logs if
there is a gap in the logs. &t is used hen the database is in the standb( role and has a gap in the redo it has
recei0ed. -his t(pe of situation occurs hen redo transport is interrupted$ for e@ample hen (ou do
maintenance on the standb( ser0er. During that maintenance no logs ould ha0e been transported and a gap
ould e@ist. ,etting this parameter allos the standb( to find the missing redo and ha0e it transported.
SQL> alter s!stem set fal_server " #*+D.#;
7ote that the 2A5EC5&87- parameter is deprecated in 11g and not needed.
We then need to let the database kno hat other databases are in the Data *uard configuration.
SQL> alter s!stem set log_archive_config " #dg_config"(*+D,*+D./#;
Once this is done$ e are read( to prepare the en0ironment for the standb( and create the standb(.
Pre$aring the Standby en(iron#ent
We are no read( to setup the standb( en0ironment for creation of the ,tandb( database. -here are man(
different a(s to perform man( of these steps. What & am shoing here is the a( & found orked best for me.
Dou should e@periment ith other options to see hat orks best for (ou.
2irst$ e need to create a passord file and ser0er parameter file >spfile? for the ne standb( database. -he
passord file can be copied directl( o0er$ and onl( needs it name changed. 2or e@ample$ on the primar( the
files is GO:AC58EHOM8KdbsKorapJ8D. We can cop( it o0er to the standb( ser0er and place it in the same
location$ but ith the standb( ,&D instead of the primar( ,&D$ i.e. GO:AC58EHOM8KdbsKorapJ8D=.
-o create the standb( spfile$ on the primar( create an initialiFation parameter file >pfile?:
SQL> create pfile from spfile;
7o$ before & continue & ant to discuss a seemingl( nice feature O creation of the ,#2&58 0ia :MA7. -his
feature is designed to allo (ou to let :MA7 create (our spfile for (ou on (our standb( location. Here is h( &
don/t use it.
1. & ha0e to cop( the passord file o0er to the standb( an(a($ so it doesn/t sa0e me ha0ing to cop( files
o0er.
=. -o use this feature (ou still ha0e to do a lot of replacement ork b( setting the parameterE0alueEcon0ert
parameter and the ,#2&58 clause and the 0arious ,8- statements to make sure e0er(thing is correct.
!
& find it easier to cop( a pfile o0er >(ou can e0en Bust cut and paste?$ rename it$ and then change the parameters
in it. -his is eas( to do and (ou/ll learn a lot b( re0ieing e0er(thing and making sure it is correct. & spend less
time doing this and fi@ing things than going through the :MA7 ,#2&58 creation. ,o$ ith that saidQ
After creating (our primar( pfile$ cop( it o0er to the standb( ser0er in the same location$ but change the name
to ha0e the standb( ,&D >e.g. initJ8D.ora ill become initJ8D=.ora?. Dou ill no need to make the folloing
changes to it >and note that in (our situation there might be others$ re0ie (our pfile carefull(?:
Depending on (our configuration and file locations on the standb( (ou might needed to change the
A)D&-E2&58ED8,-$ CO7-:O5E2&58, and D&,#A-CH8:, parameters >there ma( be others$ but be
careful$ not e0er(thing should be changed this a(?.
&n 5O*EA:CH&<8ED8,-E1 change dbEuniAueEname to the standb( ,&D >in this case J8D=?.
&n 5O*EA:CH&<8ED8,-E= change the ser0ice and dbEuniAueEname to the primar( ,&D >in this case
J8D?.
Change 2A5E,8:<8: to the primar( ,&D >J8D?.
Add the folloing parameters:
o dbEuniAueEnameRJ8D=
o dbEfileEnameEcon0ert and logEfileEnameEcon0ert if (ou are changing the location of the
datafiles andKor logfiles. & like to do this to make it ob0ious hose datafiles the( are >e.g.
KoradataKJ8D 0ersus KoradataKJ8D= b( using
dbEfileEnameEcon0ertRKoradataKJ8D/$/KoradataKJ8D=/?
7o$ on (our standb( ser0er create the director( structures and modif( files to support the ne database. -hese
should at least be:
GO:AC58E.A,8KadminKGO:AC58E,&D
GO:AC58E.A,8KadminKGO:AC58E,&DKadump >or hate0er (our auditEfileEdest is?
Datafile directories
Controlfile directories
5ogfile directories
D. :eco0er( 2ile Destination >2ast :eco0er( Area?
Add (our standb( to the KetcKoratab file.
Dou should no be read( to startup (our standb( instance for creation of the database. Dou also ant to make
sure (ou create an spfile in the process. -o do this:
1%
SQL> startup nomount pfile"5&:A>L+_A&M+>)dbs)init*+D.-ora
SQL> create spfile from pfile;
SQL> shutdown
SQL> startup nomount
SQL> show parameter spfile
SQL> e4it
-he Isho parameter spfileJ should sho the location of (our spfile$ and (our standb( should be in
7OMO)7-.
Creating the Standby Database
,imilar to the pre0ious section there are man( different a(s (ou can create the standb( database. With 11g &
use :MA7 duplication to do the creation because it is eas(. &n the pre0ious section e copied o0er the
passord file and the pfile$ modified it$ and created the spfile. -his makes the creation command ith :MA7
simplerP hoe0er$ (ou could also skip manual creation of the passord and spfile and ha0e :MA7 do it using
the ,#2&58$ #A:AM8-8:E<A5)8ECO7<8:-$ and ,8- s(nta@.
-he command to create the ,tandb( ith :MA7 is Auite simple. &t instructs :MA7 to perform a duplication to
the Au@iliar( >standb(? database for creation of a standb( b( making the cop( directl( from the acti0e database.
-his is nice because (ou do not need to ha0e backups staged on the standb( ser0er. With storage technologies
a0ailable toda( the cop( can be done in much faster and sometimes simpler a(s$ but for the purpose of
shoing this 11g feature and because it is Auite simple & like to use it hen possible.
:MA=> connect target s!sF*+D
:MA=> connect catalog 5catalogowner>F5catalogdb>
:MA=> connect au4iliar! s!sF*+D.
:MA=> duplicate target database for standby from active database;
As of 11.=.%.=.% (ou can connect to the target ith Iconnect targetJP hoe0er$ if (ou don/t specif( the
username a duplication to standb( ill fail later ith Iin0alid usernameKpassordJ.
While this command is running & like to tail the standb( alert log and see hat is going and atch for errors.
7ote that it is normal and OM to get IO:AC="%'": unable to obtain file statusJ on the online and standb( log
files.
-o perform the duplication in parallel to impro0e performance (ou can allocate primar( and standb( channels
and then run the duplicate command.
11
run
G
allocate channel chan' t!pe dis;;
allocate channel chan. t!pe dis;;
allocate channel chanH t!pe dis;;
allocate channel chan2 t!pe dis;;
allocate au4iliar! channel au4' t!pe dis;;
allocate au4iliar! channel au4. t!pe dis;;
allocate au4iliar! channel au4H t!pe dis;;
allocate au4iliar! channel au42 t!pe dis;;
duplicate target database for standb! from active database
;
I
&f e0er(thing orks (ou should see something similar to the folloing in :MA7:
9inished Duplicate Db at ,JCMAKC',
&t is at this point that & like to turn on flashback logging for the standb(:
SQL> alter database flashbac; on;
Starting Redo .$$ly on the Standby
,tarting and stopping :edo Appl( on the standb( is 0er( eas(. Oracle Data *uard pro0ides the abilit( for the
standb( to appl( the redo itself. -o start appl(:
SQL> AL%+: DA%A@AS+ :+>&D+: MA=A?+D S%A=D@K DA%A@AS+ $S<=? >$::+=% L&?9<L+
D<S>&==+>% 9:&M S+SS<&=;
-his starts the reco0er( process using the standb( logfiles that the primar( is riting the redo to. &t also tells the
standb( to return (ou to the ,45 command line once the command is complete. &f (ou ant to stop the
reco0er( (ou do:
SQL> AL%+: DA%A@AS+ :+>&D+: MA=A?+D S%A=D@K DA%A@AS+ >A=>+L;
1=
/erifying that Redo .$$ly is 0orking
OM$ so e/d like to think all e ha0e to do is atch it ork$ but sometimes things aren/t that perfect. Dou
should no 0erif( that the redo is being applied on (our standb(. 2irst e ant to make sure our destinations
are all 0alid on both the primar( and the standb(:
SQL> select D+S%_<D, S%A%$S, D+S%<=A%<&=, +::&: from DA:>A<D+_D+S% where D+S%_<D
5".;
-he destinations should sho as <A5&D.
7o$ e/ll see if the redo is actuall( being applied. 2rom the primar( run:
SQL> select S+Q$+=>+L, 9<:S%_%<M+, =+M%_%<M+, ABBL<+D, A:>A<D+D from
DA:>A<D+D_L&? where name " #*+D.# order b! 9<:S%_%<M+;
Dou should see D8, for the A##5&8D and A:CH&<8D columns if both archi0ing and redo appl( are orking
correctl(. Man( e@amples of this Auer( use Iorder b( ,84)87C8SJ$ but & don/t recommend this. &f (ou order
b( ,84)87C8S and then do a failo0er the seAuence numbers ill start again at 1 and (ou on/t see (our latest
records at the end of the resultCset. -he first time & did this & could not figure out h( & asn/t getting an( ne
ros for archi0ed redo. &n fact$ & as$ but & Bust asn/t seeing them. As a result$ & ala(s order this Auer( b(
2&:,-E-&M8.
&f (ou notice that logs aren/t appl(ing$ it is possible (ou might ha0e a gap in (our redo$ in hich case the
standb( cannot appl(. &f (ou ha0e the 2A5E,8:<8: parameter set correctl($ this shouldn/t be a problem. Dou
can check to see if there are an( gaps in the redo$ b( running the folloing Auer( on the primar(:
SQL> select S%A%$S, ?AB_S%A%$S from DA:>A<D+_D+S%_S%A%$S where D+S%_<D " .;
&t should return <A5&D and 7O *A# if e0er(thing is OM. &f (ou ant to pla( around ith this and see ho the
2A5E,8:<8: orks (ou can shutdon (our standb($ sitch out se0eral logs$ ait a bit$ bring (our standb(
back up$ and sitch another log out. Dou should soon see a *A# appear. &f (our 2A5E,8:<8: parameter is
correct on the standb( and points to the ser0ice name of the primar($ then the logs should be brought o0er and
applied.
-he <GDA-A*)A:DE,-A-), 0ie is 0er( useful for looking for errors or Bust seeing hat has happened.
Dou can Auer( it on the primar( and standb( to see status for that database.
SQL> select N from DDA%A?$A:D_S%A%$S order b! %<M+S%AMB;
All of this is good$ but sometimes (ou ant to reall( kno the data is there. A more reassuring a( to 0erif( is
to actuall( check the standb( and 0erif( that the ne data is there. Dou can do this b( changing the standb(/s
role to readonl(. 2irst (ou/ll need to stop managed reco0er( and then run:
SQL> AL%+: DA%A@AS+ &B+= :+AD &=LK;
1'
Dou can no run (our Auer( to see that the changes ha0e come across. When (ou/re done$ do not forget to take
(our database back to MO)7- and restart reco0er(. &n #art &&$ (ou/ll find out ho (ou can do this t(pe of
check more easil( ith Oracle 11g Acti0e Data *uard.
Conclusion
At this point (ou no ha0e a Data *uard Configuration orking and therefore a redundant cop( of (our
database a0ailable. & don/t ant to lea0e (ou ithout going through sitcho0er$ failo0er$ rebuilding$ and other
items$ but that ill ha0e to ait until #art && of this paper. .esides$ if (ou got this done then & need some a( to
bring (ou back for moreN
& hope this paper helps (ou get (our Data *uard configuration set up easil( and Auickl(.

You might also like