DataGuard Setup Step by Step

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

DataGuard Setup Step by Step

Primary Server Setup

Logging
Check that the primary database is in archivelog mode.

SELECT log_mode FROM v$database;

LOG_MODE
------------
NOARCHIVELOG

SQL>

If it is noarchivelog mode, switch is to archivelog mode.

SHUTDOWN IMMEDIATE;
STARTUP MOUNT;
ALTER DATABASE ARCHIVELOG;
ALTER DATABASE OPEN;

Enabled forced logging by issuing the following command.

ALTER DATABASE FORCE LOGGING;


-- Make sure at leat one logfile is present.
ALTER SYSTEM SWITCH LOGFILE;

Create standby redo logs on the primary database (in case of switchovers). The
standby redo logs should be at least as big as the largest online redo log and there
should be one extra group per thread compared the online redo logs. In my case, the
following standby redo logs must be created on both servers.

ALTER DATABASE ADD STANDBY LOGFILE THREAD 1 GROUP 10


('/u01/app/oracle/oradata/db11g/standby_redo01.log') SIZE 50M;
ALTER DATABASE ADD STANDBY LOGFILE THREAD 1 GROUP 11
('/u01/app/oracle/oradata/db11g/standby_redo02.log') SIZE 50M;
ALTER DATABASE ADD STANDBY LOGFILE THREAD 1 GROUP 12
('/u01/app/oracle/oradata/db11g/standby_redo03.log') SIZE 50M;
ALTER DATABASE ADD STANDBY LOGFILE THREAD 1 GROUP 13
('/u01/app/oracle/oradata/db11g/standby_redo04.log') SIZE 50M;

If you want to use flashback database, enable it on the primary now, so it will be
enabled on the standby also. It's very useful as you will see below.

ALTER DATABASE FLASHBACK ON;


Initialization Parameters
Check the setting for the DB_NAME and DB_UNIQUE_NAME parameters. In this case they
are both set to "db11g" on the primary database.

SQL> show parameter db_name

NAME TYPE VALUE


------------------------------------ -----------
------------------------------
db_name string db11g

SQL> show parameter db_unique_name

NAME TYPE VALUE


------------------------------------ -----------
------------------------------
db_unique_name string db11g

SQL>

The DB_NAME of the standby database will be the same as that of the primary, but it
must have a different DB_UNIQUE_NAME value. For this example, the standby database
will have the value "db11g_stby".

Set suitable remote archive log destinations. In this case I'm using the fast recovery
area for the local location, but you could specify a location explicitly if you prefer.
Notice the SERVICE and the DB_UNIQUE_NAME for the remote location reference the
standby location.

ALTER SYSTEM SET LOG_ARCHIVE_DEST_2='SERVICE=db11g_stby NOAFFIRM ASYNC


VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=DB11G_STBY';
ALTER SYSTEM SET LOG_ARCHIVE_DEST_STATE_2=ENABLE;

Make sure the STANDBY_FILE_MANAGEMENT parameter is set.

ALTER SYSTEM SET STANDBY_FILE_MANAGEMENT=AUTO;

Service Setup
Entries for the primary and standby databases are needed in the
"$ORACLE_HOME/network/admin/tnsnames.ora" files on both servers. You can
create these using the Network Configuration Utility (netca) or manually. The
following entries were used during this setup. Notice the use of the SID, rather than
the SERVICE_NAME in the entries. This is important as the broker will need to connect
to the databases when they are down, so the services will not be present.
db11g =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = ol7-112-dg1)(PORT = 1521))
)
(CONNECT_DATA =
(SID = db11g)
)
)

db11g_stby =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = ol7-112-dg2)(PORT = 1521))
)
(CONNECT_DATA =
(SID = db11g)
)
)

The "$ORACLE_HOME/network/admin/listener.ora" file on the primary server


contains the following configuration. Since the broker will need to connect to the
database when it's down, we can't rely on auto-registration with the listener, hence
the explicit entry for the database.

LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = ol7-112-dg1)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)

SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = db11g_DGMGRL)
(ORACLE_HOME = /u01/app/oracle/product/11.2.0.4/db_1)
(SID_NAME = db11g)
)
)

ADR_BASE_LISTENER = /u01/app/oracle

The "$ORACLE_HOME/network/admin/listener.ora" file on the standby server


contains the following configuration.

LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = ol7-112-dg2)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
)

SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = db11g_stby_DGMGRL)
(ORACLE_HOME = /u01/app/oracle/product/11.2.0.4/db_1)
(SID_NAME = db11g)
)
)

ADR_BASE_LISTENER = /u01/app/oracle

Once the listener.ora changes are in place, restart the listener on both servers.

lsnrctl stop
lsnrctl start

Standby Server Setup

Prepare for Duplicate


Create a parameter file for the standby database called "/tmp/initdb11g_stby.ora"
with the following contents.

*.db_name='db11g'

Create the necessary directories on the standby server.

$ mkdir -p /u01/app/oracle/oradata/db11g
$ mkdir -p /u01/app/oracle/fast_recovery_area/db11g
$ mkdir -p /u01/app/oracle/admin/db11g/adump

Create a password file, with the SYS password matching that of the primary database.

$ orapwd file=/u01/app/oracle/product/11.2.0.4/db_1/dbs/orapwdb11g
password=Password1 entries=10

Create Standby Using DUPLICATE


Start the auxiliary instance on the standby server by starting it using the temporary
"init.ora" file.

$ export ORACLE_SID=db11g
$ sqlplus / as sysdba
SQL> STARTUP NOMOUNT PFILE='/tmp/initdb11g_stby.ora';

Connect to RMAN, specifying a full connect string for both the TARGET and
AUXILIARY instances. Do not attempt to use OS authentication.

$ rman TARGET sys/Password1@db11g AUXILIARY sys/Password1@db11g_stby

Now issue the following DUPLICATE command.

DUPLICATE TARGET DATABASE


FOR STANDBY
FROM ACTIVE DATABASE
DORECOVER
SPFILE
SET db_unique_name='DB11G_STBY' COMMENT 'Is standby'
NOFILENAMECHECK;

If you need to convert file locations, or alter any initialisation parameters, you can do
this during the DUPLICATE using the SET command.

DUPLICATE TARGET DATABASE


FOR STANDBY
FROM ACTIVE DATABASE
DORECOVER
SPFILE
SET db_unique_name='DB11G_STBY' COMMENT 'Is standby'
SET
db_file_name_convert='/original/directory/path1/','/new/directory/path1/','/or
iginal/directory/path2/','/new/directory/path2/'
SET
log_file_name_convert='/original/directory/path1/','/new/directory/path1/','/o
riginal/directory/path2/','/new/directory/path2/'
SET job_queue_processes='0'
NOFILENAMECHECK;

A brief explanation of the individual clauses is shown below.

 FOR STANDBY: This tells the DUPLICATE command is to be used for a standby, so


it will not force a DBID change.
 FROM ACTIVE DATABASE: The DUPLICATE will be created directly from the source
datafiles, without an additional backup step.
 DORECOVER: The DUPLICATE will include the recovery step, bringing the standby
up to the current point in time.
 SPFILE: Allows us to reset values in the spfile when it is copied from the source
server.
 NOFILENAMECHECK: Destination file locations are not checked.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy