You are on page 1of 8

Step by step guide to create physical standby database

 
Following are the assumptions for this dataguard configuration:

Primary:

hostname: machine_prim
DB_NAME: ORCL10G
DB_UNIQUE_NAME: ORCL10G
SERVICE_NAMES: ORCL10G

Standby:

hostname: machine_stand
DB_NAME: ORCL10G
DB_UNIQUE_NAME: STDBY10G
SERVICE_NAMES: STDBY10G

1 - Prerequisites for setting up Data Guard

Oracle software release must be same for both primary and standby databases. The
operating system running on primary and standby locations must be same but operating
system release can be different.

The Primary Database must be running in ARCHIVELOG mode.

If primary and standby databases are on the same system, initialization parameters must
be adjusted correctly. Parameter lock_name_space should be used until 9i and
db_unique_name should be used from 10g onwards.

It is highly recommended that Primary database must be in FORCE LOGGING mode.

2 - Ensure that the primary database is in ARCHIVELOG mode. Check it by issuing

SQL> archive log list;


Database log mode Archive Mode
Automatic archival Enabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 68
Next log sequence to archive 68
Current log sequence 69

3 - Enable database in FORCE LOGGING mode


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

SQL> alter database force logging;

Database altered.

4 - Identify the primary database Datafiles

SQL> select name from v$datafile;

NAME
------------------------------------------------------------------------
--------
E:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL10G1\SYSTEM.DBF
E:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL10G1\UNDO.DBF
E:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL10G1\SYSAUX.DBF
E:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL10G1\DATA.DBF
E:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL10G1\RMAN.DBF
E:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL10G1\TT.DBF

6 rows selected.

5 - Make a copy of Primary Database

Shutdown database cleanly and take cold backup of primary database by issuing:

SQL> shutdown immediate;

6 - Copy the Datafiles to standby location

Copy all the Datafiles returned in above query to standby location.

7 - Start the Primary Database

SQL> startup;

8 - Issue the following command on primary database to create control file for the
standby database.

SQL> ALTER DATABASE CREATE STANDBY CONTROLFILE AS


'E:\oracle\control_stdby10g.ctl';

Database altered.

Make sure that name given to standby controlfile is different than the controlfile name of
primary database controlfile to avoid overwriting primary controlfile by mistake.
9 - If using spfile, then create pfile from spfile for standby database on primary database.
This pfile can be copied to standby location and modified.

SQL> CREATE PFILE='E:\oracle\initstdby10g.ora' from spfile;

File created.

10 – Copy controlfile created in step (8) above and pfile created in step (9) above to the
standby machine. Place pfile in $ORACLE_HOME/database directory for Windows and
$ORACLE_HOME/dbs directory for Unix machines.

11 - Set initialization parameters on physical standby database

Few of the parameters of primary database need to be modified like db_unique_name and
few others to reflect correct path of standby database. Few of the parameters are :

DB_NAME:

This parameter should be same as the primary database.

DB_UNIQUE_NAME: (for 10g and onwards)

This parameter should be different than the value specified in primary database
db_unique_name parameter. If db_unique_name is not specified at primary database, the
parameter should be different than db_name value in primary database.

LOCK_NAME_SPACE: (until 9i databases)

This parameter should have distinct value than the value specified in primary database.

COMPATIBLE:

This parameter should be same as the primary database.

CONTROL_FILES:

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

STANDBY_ARCHIVE_DEST:

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

DB_FILE_NAME_CONVERT:
Syntax:

DB_FILE_NAME_CONVERT: = 'oldstring1', 'newstring1', 'oldstring2', 'newstring2', ...

Specify the location of the primary database datafiles followed by the standby location of
the datafiles. It will convert datafile name of primary database to datafile name of the
standby datafile. If the primary and standby database are on the same system or if the
directory structure of primary and standby database is different then this parameter is
required.

LOG_FILE_NAME_CONVERT:

Syntax:

LOG_FILE_NAME_CONVERT: = 'oldstring1', 'newstring1', 'oldstring2', 'newstring2', ...

Specify the location of the primary database logs followed by the standby location of the
logs. It will convert the filename of the primary database log to the filenames of the
standby log. If the primary and standby database are on the same system or if the
directory structure of primary and standby database is different then this parameter is
required.

STANDBY_FILE_MANAGEMENT:

It enables or disables automatic standby file management. When automatic standby file
management is enabled, operating system file additions and deletions on the primary
database are replicated on the standby database if parameter is set to AUTO.

FAL_SERVER:

It specifies the FAL (fetch archive log) server for a standby database. The value is an
Oracle Net service name, which is assumed to be configured properly on the standby
database system to point to the desired FAL server. Will be primary database Net service
name

FAL_CLIENT:

It specifies the FAL (fetch archive log) client name that is used by the FAL service,
configured through the FAL_SERVER parameter, to refer to the FAL client. The value is
an Oracle Net service name, which is assumed to be configured properly on the FAL
server system to point to the FAL client (standby database).

Given the dependency of FAL_CLIENT on FAL_SERVER, the two parameters should


be configured or changed at the same time.
Modify values for parameter BACKGROUND_DUMP_DEST, CORE_DUMP_DEST,
USER_DUMP_DEST according to the standby database.

12 - If database is running on windows, then windows service needs to be created using


oradim utility. Issue following command from the command prompt:

C:\>oradim -new -sid stdby10g

13 - Configure listeners & tnsnames for standby database

Create the following listener.ora file into the directory


$ORACLE_HOME/network/admin/ of the primary machine

LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = machine_prim)(PORT = 1521))
)
)

Also make an entry into tnsnames.ora of primary database for standby database.

Create the following tnsnames.ora file into the directory


$ORACLE_HOME/network/admin/ of the primary machine:

# tnsnames.ora Network Configuration File:

STDBY10G =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = machine_stand)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = STDBY10G)
)
)

14 - Configure listeners & tnsnames for primary database

Create the following listener.ora file into the directory


$ORACLE_HOME/network/admin/ of the standby machine

LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = machine_stand)(PORT = 1521))
)
)
Also make an entry into tnsnames.ora of standby database for primary database.

Create the following tnsnames.ora file into the directory


$ORACLE_HOME/network/admin/ of the standby machine:

# tnsnames.ora Network Configuration File:

ORCL10G =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = machine_prim)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = ORCL10G)
)
)

15 - Start Physical standby database

Startup the standby database using following commands:


E:\>set oracle_sid=stdby10g
E:\>sqlplus “/ as sysdba”

SQL*Plus: Release 10.2.0.4.0 - Production on Thu Sep 11 17:29:10 2008

Copyright (c) 1982, 2007, Oracle. All Rights Reserved.

Connected to an idle instance.

SQL> startup
pfile='e:\oracle\product\10.2.0\db_2\database\initstdby10g.ora' nomount;

ORACLE instance started.

Total System Global Area 612368384 bytes


Fixed Size 1298184 bytes
Variable Size 167772408 bytes
Database Buffers 440401920 bytes
Redo Buffers 2895872 bytes

SQL> alter database mount standby database;


Database altered.

16 - Enabling archiving to Physical Standby Database

To configure archive logging from the primary database to the standby site the
LOG_ARCHIVE_DEST_n and LOG_ARCHIVE_DEST_STATE_n parameters must be
defined.
Issue following commands from primary database session:

SQL> ALTER SYSTEM SET LOG_ARCHIVE_DEST_2='SERVICE=stdby10g' SCOPE=BOTH;


System altered.

SQL> ALTER SYSTEM SET LOG_ARCHIVE_DEST_STATE_2=ENABLE SCOPE=BOTH;


System altered.

17 - Initiate Log apply services

SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM


SESSION;
Database altered.

Open the standby database in read-only once to check if everything is setup correctly

SQL> recover managed standby database cancel;


Media recovery complete.

SQL> alter database open read only;


Database altered.

SQL> shutdown immediate;

SQL>startup mount;

SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM


SESSION;
Database altered.

Standby is now mounted and functional. Check alert log file to see if the standby
database is receiving archivelogs properly. Can also query V$ARCHIVED_LOG view to
verify that redo logs are received.

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


BY SEQUENCE#;

Archive the current log on the primary database using following statement.

SQL> ALTER SYSTEM ARCHIVE LOG CURRENT;


 

Again check on standby database if the archivelog is received

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


BY SEQUENCE#;
If archivelog(s) are received, means standby has been created successfully.

To check if the archive logs are successfully applied on standby, use the below query :

select max(al.sequence#) "Last Seq Received", max(lh.sequence#) "Last Seq Applied"


from v$archived_log al, v$log_history lh;

You might also like