Configure An Oracle Physical Standby With Log Shipping
Configure An Oracle Physical Standby With Log Shipping
Introduction
This document will guide you, step by step, through the process of configuring an Oracle Physical
Standby database and ensure log shipping is setup correctly.
A physical standby database is an exact, block-for-block copy of a primary database, that is kept “in-
sync” with primary database by means of either applying redo or archive redo logs. Once the
standby database is configured properly, Oracle automatically ensures that any changes on the
primary database are reflected on the standby.
The main purpose of a standby database is for disaster recovery although the standby database can
be open read only for reporting. It allows for the primary and standby databases to be located in
different server rooms/geographic areas. If a problem happens on the primary site then the standby
database can be opened and no data loss is incurred.
This document assumes you have already created an Oracle 10gR1 database or higher on Linux and
that database resides on the local file system. You should also have another server with the same
operating system (OS) and database version installed. This secondary server will be our Physical
Standby.
The operating system (OS) can actually be any version of Linux, UNIX or even Windows, however
both the servers must be the same.
In this example we have chosen Linux as our OS – see table below for further information.
For more information on how to install Oracle and create a database, please see the documentation
in the appendix section below.
Example Setup
To start with we will make some configuration changes to the primary database so that it can
become aware of the primary-standby setup.
** Perform all the below SQL commands as the SYS Oracle user. Please change filenames to suit
your environment.
On Primary
It is required to place the primary database in FORCE LOGGING mode after database creation. This
forces the Oracle Database to write redo records even when NOLOGGING has been specified in DDL.
Check that the database log mode is Archive Mode – this is essentially for log shipping.
GROUP#
----------
3
2
1
MEMBER
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/test/redo03.log
/u01/app/oracle/oradata/test/redo02.log
/u01/app/oracle/oradata/test/redo01.log
Create 1 more standby redo log files than you have groups, so in our case we will create 4.
SQL> alter database add standby logfile '/u01/app/oracle/oradata/test/stby_redo01.log' size
51200k;
GROUP# TYPE
---------- -------
3 ONLINE
2 ONLINE
1 ONLINE
4 STANDBY
5 STANDBY
6 STANDBY
7 STANDBY
Configure the below log_archive parameters for log transportation to the standby.
Oracle log shipping between a primary and standby database requires SQL*Net connectivity for redo
log transportation. Below we will configure the tnsnames and listener.ora files on BOTH servers
TNSnames.ora
TEST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = serverA)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = test)
)
)
TEST2 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = serverB)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = test2)
)
)
Listener.ora
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = serverA)(PORT = 1521))
)
)
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = test)
(ORACLE_HOME = /u01/oracle_base/product/12.1.0)
)
(SID_DESC =
(SID_NAME = test2 )
(ORACLE_HOME = /u01/oracle_base/product/12.1.0)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = serverB)(PORT = 1521))
)
)
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = test)
(ORACLE_HOME = /u01/oracle_base/product/12.1.0)
)
(SID_DESC =
(SID_NAME = test2 )
(ORACLE_HOME = /u01/oracle_base/product/12.1.0)
)
)
Stop and Start the listeners on each node
lsnrctl stop
lsnrctl start
Ensure you can tnsping the listener remotely and that you can connect using SQLPLUS to the remote
database
On Primary
Tnsping test2
Sqlplus system/oracle@test2
On Standby
Tnsping test
Sqlplus system/oracle@test
3. Create Standby database
I will show 2 different ways to create a standby database. If you are running Oracle 11gR1 or higher
AND have good network speed between your primary and standby servers then use 3.1 otherwise
use 3.2
In Oracle Database 11gR1 and higher the standby database can be created using a new feature
called "active database duplication", that allows us to duplicate a primary database without the
need to take first a backup first. The process reads data directly from primary database.
On Primary
Copy the pfile from the primary server to the standby server using scp
On Standby
Edit the newly copied pfile (inittest2.ora) and add the following parameters
fal_server=test
fal_client=test2
db_file_name_convert='/u01/app/oracle/oradata/test','/u01/app/oracle/oradata/test2/'
log_file_name_convert='/u01/app/oracle/oradata/test','/u01/app/oracle/oradata/test2/'
background_dump_dest='/u01/app/oracle/admin/test2/bdump'
user_dump_dest='/u01/app/oracle/admin/test2/udump'
control_files='/u01/app/oracle/oradata/test2/control01.ctl',
'/u01/app/oracle/oradata/test2/control02.ctl'
db_unique_name='test2'
LOG_ARCHIVE_DEST_1='location=use_db_recovery_file_dest
valid_for=(ALL_LOGFILES,ALL_ROLES) db_unique_name=test'
LOG_ARCHIVE_DEST_2='service=test2 async
valid_for=(ONLINE_LOGFILES,PRIMARY_ROLE) db_unique_name=test2'
standby_archive_dest =/u01/app/oracle/oradata/standby/archive
** Please make sure all the directories in the pfile are pre-created before running the
duplicate command below
cd $ORACLE_HOME/dbs
orapwd file=orapwtest2 password=oracle entries=10
Next we need to NOMOUNT the standby database (test2) using our newly edited pfile.
On Primary
Using RMAN, connect to the primary and standby databases as per below
We can then run the following duplicate command to create our standby database.
RMAN> duplicate target database for standby from active database dorecover;
On standby
The standby database will have changed to mount after successful completion of the duplicate
command. Restart the standby database;
Place the standby database in recovery managed standby mode to allow it to apply logs from the
primary.
Another method for creating a physical standby database is to use RMAN to create an image copy
backup.
On Primary
Copy the pfile from the primary server to the standby server using scp
On Standby
Edit the newly copied pfile (inittest2.ora) and add the following parameters
fal_server=test
fal_client=test2
db_file_name_convert='/u01/app/oracle/oradata/test','/u01/app/oracle/oradata/test2/'
log_file_name_convert='/u01/app/oracle/oradata/test','/u01/app/oracle/oradata/test2/'
background_dump_dest='/u01/app/oracle/admin/test2/bdump'
user_dump_dest='/u01/app/oracle/admin/test2/udump'
control_files='/u01/app/oracle/oradata/test2/control01.ctl',
'/u01/app/oracle/oradata/test2/control02.ctl'
db_unique_name='test2'
LOG_ARCHIVE_DEST_1='location=use_db_recovery_file_dest
valid_for=(ALL_LOGFILES,ALL_ROLES) db_unique_name=test'
LOG_ARCHIVE_DEST_2='service=test2 async
valid_for=(ONLINE_LOGFILES,PRIMARY_ROLE) db_unique_name=test2'
standby_archive_dest =/u01/app/oracle/oradata/standby/archive
** Please make sure all the directories in the pfile are pre-created before running the
duplicate command below
cd $ORACLE_HOME/dbs
orapwd file=orapwtest2 password=oracle entries=10
Next we need to NOMOUNT the standby database (test2) using our newly edited pfile.
On Primary
Connect to RMAN and run the below copy command to create an image copy backup of the files.
rman target /
Copy all of the backed up files to the same directory structure on the standby database server, with
the same file names – THIS IS VITAL. This can be done using scp, an example of which is below;
Scp /u01/app/oracle/oradata/test3/system01.dbf
serverB:/u01/app/oracle/oradata/test3/
On standby
Copy the control file control01.ctl to the other control file location that you specified in the pfile. In
our case;
cd /u01/app/oracle/oradata/test3
cp control01.ctl control02.ctl
Place the standby database in recovery managed standby mode to allow it to apply logs from the
primary.
To ensure that the logs are being transported and applied to the standby database we will run the
below commands.
On standby
The Media Recovery Process (MRP) should be running on the standby database server. This process
is responsible for applying the logs to the standby.
The MRP0 process should be in the WAIT_FOR_LOG state until a log switch is performed on the
primary database.
Below we see that log sequence 17 and 18 have been archived and applied.
On Primary
Perform a couple of log switches. This will cause the logs to transported to the standby and for the
MRP process to apply them.
Check that the 3 logs have been archived and applied on the standby. Here you can see that log
19,20,21 are now applied.
The MRP0 process’ status should change to APPLYING_LOG just after the log switches occur on the
primary database.
List of URL’s to help with the Oracle Database Installation, DB creation and Oracle Physical Standby
configuration.