You are on page 1of 17

Dataguard Implementation

and Failover

Step by Step Guide : Data Guard


Implementation

Author Gareth Jones

Date of Issue 25/01/07

Version 1.0

Updated

Reference No.

Page 1
Table of Contents

DATAGUARD OVERVIEW..................................................................................... 4

Document Outline ........................................................................................................................................... 4

What is Data Guard?...................................................................................................................................... 4

About this Guide ............................................................................................................................................. 4

STEP BY STEP GUIDE .......................................................................................... 5

Step 1................................................................................................................................................................ 5

Step 2................................................................................................................................................................ 5

Step 3................................................................................................................................................................ 5

Step 4................................................................................................................................................................ 5

Step 5................................................................................................................................................................ 6

Step 6................................................................................................................................................................ 6

Step 7................................................................................................................................................................ 6

Step 8................................................................................................................................................................ 6

Step 9................................................................................................................................................................ 7

Step 10.............................................................................................................................................................. 7

Step 11.............................................................................................................................................................. 8

Step 12.............................................................................................................................................................. 8

Step 13.............................................................................................................................................................. 9

Step 14.............................................................................................................................................................. 9

Step 15.............................................................................................................................................................. 9

Step 16............................................................................................................................................................ 10

Step 17............................................................................................................................................................ 10

FAILOVER PROCESS .......................................................................................... 11

Failover Step 1............................................................................................................................................... 11

Page 2
Failover Step 2............................................................................................................................................... 11

Failover Step 3............................................................................................................................................... 12

Failover Step 4............................................................................................................................................... 12

Failover Step 5............................................................................................................................................... 12

Failover Step 6............................................................................................................................................... 13

Failover Step 7............................................................................................................................................... 13

Failover Step 8............................................................................................................................................... 13

Failover Step 8............................................................................................................................................... 14

Failover Step 9............................................................................................................................................... 14

Failover Step 10............................................................................................................................................. 14

APPENDIX A ......................................................................................................... 15
DB_FILE_NAME_CONVERT.................................................................................................................... 16

DOCUMENT INFORMATION ............................................................................... 17

Page 3
Dataguard Overview
Document Outline

This document will provide the reader with step-by-step instructions on how to create a Data Guard
environment. This document has been developed with Egg specifics in mind.

This document assumes that the standby database has already been built.

What is Data Guard?

Oracle Data Guard ensures high availability, data protection, and disaster recovery for enterprise
data. Data Guard provides a comprehensive set of services that create, maintain, manage, and
monitor one or more standby databases to enable production Oracle databases to survive
disasters and data corruptions. Data Guard maintains these standby databases as transactionally
consistent copies of the production database. Then, if the production database becomes
unavailable because of a planned or an unplanned outage, Data Guard can switch any standby
database to the production role, thus minimizing the downtime associated with the outage. Data
Guard can be used with traditional backup, restoration, and cluster techniques to provide a high
level of data protection and data availability.

About this Guide

The example given is for database ACC2. You will need to change the database name (SID) for
each database

Page 4
Step By Step Guide
Step 1

Enable database in FORCE LOGGING mode

Place primary database in FORCE LOGGING mode using following SQL statement:

SQL> alter database force logging;


Database altered.

Step 2

Identify the primary database Datafiles

SQL> select name from v$datafile;

NAME
---------------------------------------------------------------------
/u107/oradata/ACC2/ACC2_system01.dbf
/u107/oradata/ACC2/ACC2_undo_rbs1.dbf
/u107/oradata/ACC2/ACC2_users01.dbf
/u107/oradata/ACC2/ACC2_tools01.dbf
/u109/oradata/ACC2/ACC2_ACCURATE_DATA01.dbf
/u108/oradata/ACC2/ACC2_ACCURATE_INDEX01.dbf
/u109/oradata/ACC2/ACC2_ACCURATE_DATA02.dbf
/u109/oradata/ACC2/ACC2_ACCURATE_DATA03.dbf
/u108/oradata/ACC2/ACC2_ACCURATE_INDEX02.dbf

Step 3

Put tablespace in hot backup mode

SQL> select 'alter tablespace '||tablespace_name||' begin backup;'


from dba_tablespaces;

'ALTERTABLESPACE'||TABLESPACE_NAME||'BEGINBACKUP;'
-------------------------------------------------------------
alter tablespace SYSTEM begin backup;
alter tablespace UNDO_RBS1 begin backup;
alter tablespace USERS begin backup;
alter tablespace TOOLS begin backup;
alter tablespace TEMP begin backup;
alter tablespace ACCURATE_DATA begin backup;
alter tablespace ACCURATE_INDEX begin backup;

Step 4

Copy files to standby location

Page 5
scp -p /u107/oradata/ACC2/ACC2_system01.dbf shark-9:/u103/oradata/ACC2/.
scp -p /u107/oradata/ACC2/ACC2_undo_rbs1.dbf shark-9:/u103/oradata/ACC2/.
scp -p /u107/oradata/ACC2/ACC2_users01.dbf shark-9:/u103/oradata/ACC2/.
scp -p /u107/oradata/ACC2/ACC2_tools01.dbf shark-9:/u103/oradata/ACC2/.
scp -p /u109/oradata/ACC2/ACC2_ACCURATE_DATA01.dbf shark-9:/u103/oradata/ACC2/.
scp -p /u108/oradata/ACC2/ACC2_ACCURATE_INDEX01.dbf shark-9:/u103/oradata/ACC2/.
scp -p /u109/oradata/ACC2/ACC2_ACCURATE_DATA02.dbf shark-9:/u103/oradata/ACC2/.
scp -p /u109/oradata/ACC2/ACC2_ACCURATE_DATA03.dbf shark-9:/u103/oradata/ACC2/.
scp -p /u108/oradata/ACC2/ACC2_ACCURATE_INDEX02.dbf shark-9:/u103/oradata/ACC2/.

Step 5

Create Control file for Standby Database

Issue the following command on primary database to create control file for the
standby database.
SQL> ALTER DATABASE CREATE STANDBY CONTROLFILE AS
2 '/opt/app/oracle/<filename>.ctl’;

Database altered.
The filename for newly created standby control file must be different of current
control file of the primary database. Also control file for standby database must
be created after the last timestamp for the backup Datafiles.

Step 6

Copy backup control file to standby server using scp

scp -p /opt/app/oracle/<filename>.ctl shark-9:/<location>/<filename>.ctl

Copy controlfile to controlfile location as specified in init.ora

Step 7

Copy init.ora to standby server

scp -p $ORACLE_HOME/dbs/iniSID.ora shark-9:$ORACLE_HOME/dbs/.

Step 8

Amend init.ora parameters on standby database

Add the following

#=========================================================================
# Dataguard STANDBY config
# ========================================================================
standby_archive_dest='/u104/oradata/ACC2/archive'

Page 6
DB_FILE_NAME_CONVERT =('/u107/oradata/ACC2/' , '/u103/oradata/ACC2/' ,
'/u109/oradata/ACC2/' , '/u103/oradata/ACC2/' ,
'/u108/oradata/ACC2/' , '/u103/oradata/ACC2/' )
log_file_name_convert=('/u101/oradata/ACC2/' , '/u103/oradata/ACC2/' ,
'/u102/oradata/ACC2' , '/u103/oradata/ACC2/' ,
'/u104/oradata/ACC2/' , '/u103/oradata/ACC2/')
standby_file_management=AUTO
remote_archive_enable=TRUE
#===========================================================================
# Dataguard LIVE config
# =========================================================================
#log_archive_dest_2 = 'SERVICE=ACC2_SHARK1 reopen=120'
#log_archive_dest_state_1 = enable
#log_archive_dest_state_2 = enable
#remote_archive_enable = true
#log_archive_dest_1 = 'location=/u105/oradata/ACC2/archive'
# standby_file_management=MANUAL

NB the live config is hashed out. This is used for failover


NOTE see appendix A for details on initialization parameters

Step 9

Configure Listener.ora on Standby

#Installation Generated Net V2 Configuration


# Version Date: Sep-16-97
# Filename: Listener.ora
#
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))
)
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = shark-9)(PORT = 1521))
)
)
)
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = /opt/app/oracle/product/9.2.0)
(PROGRAM = extproc)
)
(SID_DESC =
(GLOBAL_DBNAME = ACC2)
(ORACLE_HOME = /opt/app/oracle/product/9.2.0)
(SID_NAME = ACC2)
)
)

Step 10

Bounce listener on standby

ACC2 on shark-9 $ lsnrctl stop


ACC2 on shark-9 $ lsnrctl start

Page 7
Step 11

Add entry to primary server tnsnames.ora


ACC2_SHARK9.WORLD=
(DESCRIPTION=
(ADDRESS=
(PROTOCOL=tcp)
(HOST=shark-9)
(PORT=1521)
)
(CONNECT_DATA=
(SID=ACC2)
(SERVER=DEDICATED)
)
)
And add this entry to the standby tnsnames

ACC2_SHARK1.WORLD=
(DESCRIPTION=
(ADDRESS=
(PROTOCOL=tcp)
(HOST=shark-9)
(PORT=1521)
)
(CONNECT_DATA=
(SID=ACC2)
(SERVER=DEDICATED)
)
)

Step 12

Start Physical standby database

ACC2 on shark-9 $ sqlplus '/as sysdba'

SQL*Plus: Release 9.2.0.6.0 - Production on Thu Jan 25 13:24:43 2007

Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.

Connected to an idle instance.

SQL> startup nomount


ORACLE instance started.

Total System Global Area 302863704 bytes


Fixed Size 456024 bytes
Variable Size 201326592 bytes
Database Buffers 100663296 bytes
Redo Buffers 417792 bytes
SQL> alter database mount standby database;

Database altered.

SQL>

Page 8
Step 13

Amend Primary init.ora add the following

#===========================================================================
# Dataguard LIVE config
# =========================================================================
log_archive_dest_2 = 'SERVICE=ACC2_SHARK9 reopen=120'
log_archive_dest_state_1 = enable
log_archive_dest_state_2 = enable
remote_archive_enable = true
#===========================================================================
#===========================================================================
# Dataguard STANDBY config
# =========================================================================
#standby_file_management=manual
#remote_archive_enable=TRUE
#standby_archive_dest='/u105/oradata/ACC2/archive'

Make sure the original log_archive destination is set as below

log_archive_dest_1 = 'location=/u105/oradata/ACC2/archive'

and

log_archive_start = TRUE

NB the Standby config is hashed out. This is used for failover

Step 14

Now Bounce Primary database

Step 15

Initiate Log apply services on Standby Server

The example includes the DISCONNECT FROM SESSION option so that log apply
services run in a background session.

SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM


SESSION;

Database altered.

NB this will automatically apply logs to standby

To cancel this

SQL> recover managed standby database cancel;


Media recovery complete.

Page 9
Step 16

Verifying the Standby Database

On standby database query the V$ARCHIVED_LOG view to verify that redo log
received.

SQL> SELECT SEQUENCE#, FIRST_TIME, NEXT_TIME FROM V$ARCHIVED_LOG ORDER BY


SEQUENCE#;

SEQUENCE# FIRST_TIM NEXT_TIME


---------- --------- ---------
500 25-JAN-07 25-JAN-07
501 25-JAN-07 25-JAN-07

On Primary
SQL> alter system switch logfile;

System altered.

On standby
SQL> SELECT SEQUENCE#, FIRST_TIME, NEXT_TIME FROM V$ARCHIVED_LOG ORDER BY
SEQUENCE#;

SEQUENCE# FIRST_TIM NEXT_TIME


---------- --------- ---------
500 25-JAN-07 25-JAN-07
501 25-JAN-07 25-JAN-07

Step 17

Finished

Page 10
Failover Process

Failover Step 1

Initiate the switchover operation on the primary database.

To transition the current primary database to a physical standby database role, use the
following SQL statement on the primary database:

SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PHYSICAL STANDBY;

After this statement completes, the primary database is converted into a standby
database. The current control file is backed up to the current SQL session trace file
before the switchover operation. This makes it possible to reconstruct a current
control file, if necessary.

Failover Step 2

Shut down and restart the former primary instance.

Shut down the former primary instance and restart it without mounting the database:

SQL> SHUTDOWN IMMEDIATE;

Page 11
Failover Step 3

Hash out the primary dataguard config and un hash the standby config
in the init.ora

#===========================================================================
# Dataguard LIVE config
# =========================================================================
#log_archive_dest_2 = 'SERVICE=ACC2_SHARK9 reopen=120'
#log_archive_dest_state_1 = enable
#log_archive_dest_state_2 = enable
#remote_archive_enable = true
#===========================================================================
#===========================================================================
# Dataguard STANDBY config
# =========================================================================
standby_file_management=manual
remote_archive_enable=TRUE
standby_archive_dest='/u105/oradata/ACC2/archive'

Failover Step 4

SQL> STARTUP NOMOUNT;

Mount the database as a physical standby database:

SQL> ALTER DATABASE MOUNT STANDBY DATABASE;

At this point in the switchover process, both databases are configured as standby
databases

Failover Step 5

Switch the physical standby database role to the primary role.

You can switch a physical standby database from the standby role to the primary role
when the standby database instance is either mounted in managed recovery mode or
open for read-only access. It must be mounted in one of these modes so that the
primary database switchover operation request can be coordinated.

SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY;

Page 12
Failover Step 6

Shut down the new primary database.

Shut down the target standby instance and restart it using the appropriate initialization
parameters for the primary role:

SQL> SHUTDOWN IMMEDIATE;

Failover Step 7

Amend init.ora
Hash out the primary dataguard config and un hash the standby config
in the init.ora

#=========================================================================
# Dataguard STANDBY config
# ========================================================================
#standby_archive_dest='/u104/oradata/ACC2/archive'
#DB_FILE_NAME_CONVERT =('/u107/oradata/ACC2/' , '/u103/oradata/ACC2/' ,
'/u109/oradata/ACC2/' , '/u103/oradata/ACC2/' ,
'/u108/oradata/ACC2/' , '/u103/oradata/ACC2/' )
#log_file_name_convert=('/u101/oradata/ACC2/' , '/u103/oradata/ACC2/' ,
'/u102/oradata/ACC2' , '/u103/oradata/ACC2/' ,
'/u104/oradata/ACC2/' , '/u103/oradata/ACC2/')
#standby_file_management=AUTO
#remote_archive_enable=TRUE
#===========================================================================
# Dataguard LIVE config
# =========================================================================
log_archive_dest_2 = 'SERVICE=ACC2_SHARK1 reopen=120'
log_archive_dest_state_1 = enable
log_archive_dest_state_2 = enable
remote_archive_enable = true

Failover Step 8

Restart the new primary database.

SQL> STARTUP;

The target physical standby database is now transitioned to the primary database role.

Page 13
Failover Step 8

On the new physical standby database

Start managed recovery operations and log apply services.

Issue the following statement to begin managed recovery operations on the new
physical standby database:

SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM


SESSION;

Failover Step 9

On the new primary database

Begin sending redo data to the standby databases.

Issue the following statement on the new primary database:

SQL> ALTER SYSTEM ARCHIVE LOG CURRENT;

Failover Step 10

Failover Complete

Page 14
Appendix A

initialization parameters on physical standby database

Although most of the initialization parameter settings in the text initialization


parameter file that you copied from the primary system are also appropriate for
the physical standby database, some modifications need to be made. Edit created
pfile from primary database.

db_name - Not modified. The same name as the primary database.

compatible - Not modified. The same as the primary database, 9.2.0.0.0.

control_files - Specify the path name and filename for the standby control file.

log_archive_start - Not modified. The same as the setting for the primary
database, TRUE

standby_archive_dest - Specify the location of the archived redo logs that will be
received from the primary database.

db_file_name_convert - Specify the location of the primary database datafiles


followed by the standby location of the datafiles. This parameter will convert the
filename of the primary database datafiles to the filename of the standby datafile
filenames. If the standby database is on the same system as the primary
database or if the directory structure where the datafiles are located on the
standby site is different from the primary site then this parameter is required.

log_file_name_convert - Specify the location of the primary database logs


followed by the standby location of the logs. This parameter will convert the
filename of the primary database log to the filenames of the standby log. If the
standby database is on the same system as the primary database or if the
directory structure where the logs are located on the standby site is different
from the primary site then this parameter is required.

log_archive_dest_1 - Specify the location where the redo logs are to be archived
on the standby system. (If a switchover occurs and this instance becomes the
primary database, then this parameter will specify the location where the online
redo logs will be archived.)

standby_file_management - Set to AUTO.

remote_archive_enable - Set to TRUE.

instance_name - If this parameter is defined, specify a different value for the


standby database than the primary database when the primary and standby
databases reside on the same host.

lock_name_space - Specify the standby database instance name. Use this


parameter when you create the physical standby database on the same system
as the primary database. Change the INSTANCE_NAME parameter to a value
other than its primary database value, and set this LOCK_NAME_SPACE
initialization parameter to the same value that you specified for the standby

Page 15
database INSTANCE_NAME initialization parameter.

Also change the values of the parameters background_dump_dest,


core_dump_dest and user_dump_dest to specify location of the standby
database.

(Refer Annexure for initialization parameter settings for primary and standby
database.)

DB_FILE_NAME_CONVERT

Parameter String
type
Syntax DB_FILE_NAME_CONVERT = [(]'string1' , 'string2' ,
'string3' , 'string4' , ...[)]

Where:

• string1 is the pattern of the primary database filename


• string2 is the pattern of the standby database filename
• string3 is the pattern of the primary database filename
• string4 is the pattern of the standby database filename

You can use as many pairs of primary and standby replacement strings
as required. You can use single or double quotation marks. The
parentheses are optional.

Following are example settings that are acceptable:

DB_FILE_NAME_CONVERT = ('/dbs/t1/','/dbs/t1/s_','dbs/t2/
','dbs/t2/s_')
Default None
value
Parameter Static
class

DB_FILE_NAME_CONVERT is useful for creating a duplicate database for recovery


purposes. It converts the filename of a new datafile on the primary database to a
filename on the standby database. If you add a datafile to the primary database, you
must add a corresponding file to the standby database. When the standby database is
updated, this parameter converts the datafile name on the primary database to the
datafile name on the standby database. The file on the standby database must exist and
be writable, or the recovery process will halt with an error.

If you specify an odd number of strings (the last string has no corresponding
replacement string), an error is signalled during startup. If the filename being
converted matches more than one pattern in the pattern/replace string list, the first
matched pattern takes effect. There is no limit on the number of pairs that you can

Page 16
specify in this parameter (other than the hard limit of the maximum length of
multivalue parameters).

Set the value of this parameter to two strings. The first string is the pattern found in
the datafile names on the primary database. The second string is the pattern found in
the datafile names on the standby database.

You can also use DB_FILE_NAME_CONVERT to rename the datafiles in the clone
controlfile when setting up a clone database during tablespace point-in-time recovery

Document Information
Document Modification History:

Vers. Date Author Description of Change


1.00 G.Jones Initial release. No changes.

Document Storage Location:

Server:

Page 17

You might also like