You are on page 1of 4

Standby Database

 Primary Database Setup


 Standby Database Setup
 Standby Recovery
 Managed Standby Recovery
 Read Only Database
 Standby Database Backup
 Standby server not available for a period
 Primary server not available for a period
 To activate the standby database
 Miscellaneous

Primary Database Setup

 Shutdown the database using: SHUTDOWN IMMEDIATE


 Backup all database files.
 Add an entry for the standby server into the tnsnames.ora file:

STBY =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = standby_host )(PORT = 1512))
)
(CONNECT_DATA =
(SERVICE_NAME = standby_sid)
)
)

 Assuming your database in already in ARCHIVELOG mode the first four of the following init.ora paramters will already be set.
Add the last two entires:

log_archive_start = true
log_archive_dest_1 = "location=C:\Oracle\oradata\ORCL\archive"
log_archive_dest_state_1 = enable
log_archive_format = %%ORACLE_SID%%T%TS%S.ARC

log_archive_dest_2 = "service=STBY optional reopen=5"


log_archive_dest_state_2 = enable

 Startup the database using:


o STARTUP PFILE=C:\Oracle\Admin\SID\PFile\init.ora
 Create standby database controlfile using:
o ALTER DATABASE CREATE STANDBY CONTROLFILE AS 'c:\stbycf.f';
 Shutdown Primary Database

Standby Database Setup

Copy the production backup files to the standby server (parameter file, password file,data files, redo log files)
Copy the standby controlfile to the standby server.

Alter the control_files and archive parameters of the init.ora as follows:

#use the standby service name


service_names = STBY.world

#reference the standby controlfile


control_files = ("C:\Oracle\oradata\orcl\stbycf.f")

#switch archiving and reference archive directory (same as primary)

log_archive_start = true
log_archive_dest_1 = "location=C:\Oracle\oradata\ORCL\archive"
log_archive_dest_state_1 = enable
log_archive_format = %%ORACLE_SID%%T%TS%S.ARC
log_archive_dest_2 = "service=STBY optional reopen=5"

#parameter for standby database


log_archive_dest_state_2 = enable
standby_archive_dest = C:\Oracle\oradata\orcl\archive

 Add the following entries into the listener.ora file:

(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = ntfm451)(PORT = 1512))
)
STANDBY_LISTENER = (ADDRESS_LIST=
(ADDRESS=(PROTOCOL=tcp)(PORT=1512)(HOST=standby_server))
)

The file should resemble the following:

# LISTENER.ORA Network Configuration File: C:\Oracle\Ora817\network\admin\listener.ora


# Generated by Oracle configuration tools.

LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))
)
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = standby_server)(PORT = 1521))
)
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = standby_server)(PORT = 1512))
)
)
(DESCRIPTION =
(PROTOCOL_STACK =
(PRESENTATION = GIOP)
(SESSION = RAW)
)
(ADDRESS = (PROTOCOL = TCP)(HOST = standby_server)(PORT = 2481))
)
)

STANDBY_LISTENER = (ADDRESS_LIST=
(ADDRESS=(PROTOCOL=tcp) (PORT=1512) (HOST=standby_server))
)

SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = PLSExtProc)
(ORACLE_HOME = C:\Oracle\Ora81)
(PROGRAM = extproc)
)
(SID_DESC =
(GLOBAL_DBNAME = orcl)
(ORACLE_HOME = C:\Oracle\Ora81)
(SID_NAME = orcl)
)
)
SID_LIST_STANDBY_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = standby_sid)
(ORACLE_HOME = C:\Oracle\Ora81)
)
)

 Reload the listener file using lsnrctl reload from the command prompt.
 Add the following entry into the tnsnames.ora file:

STBY =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = standby_server)(PORT = 1512))
)
(CONNECT_DATA =
(SERVICE_NAME = standby_sid)
)
)

At this point the recovery process can start.


Standby Recovery

Regular recovery requires archive logs to be copied manually between the server and user initiation of the recovery process.

Copy all archive logs from the primary to the standby server.
From sqlplus do the following:

SQL> CONNECT sys/password AS SYSDBA


SQL> STARTUP NOMOUNT PFILE=C:\Oracle\Admin\SID\PFile\init.ora
SQL> ALTER DATABASE MOUNT STANDBY DATABASE;
SQL> RECOVER STANDBY DATABASE;
This process must be repeated every time archive logs are manually transfered.

Managed Standby Recovery

During managed recovery the transfer of archivelogs is controlled by the servers without user intervention.

Copy all archive logs from the primary to the standby server. This is the only time you should need to do this.
From sqlplus do the following:

SQL> CONNECT sys/password AS SYSDBA


SQL> STARTUP NOMOUNT PFILE=C:\Oracle\Admin\SID\PFile\init.ora
SQL> ALTER DATABASE MOUNT STANDBY DATABASE;
SQL> RECOVER MANAGED STANDBY DATABASE;

As logs are archived from the primary, they will be applied to the standby. There is no indication in the recovery session that logs are being
applied. In order to monitor progress, check the standby aler.log. For example

Sat Jul 23 10:10:55 2005


ALTER DATABAE RECOVER MANAGED STANDBY DATABASE
Sat Jul 23 10:10:55 2005
Media Recovery Start: Managed Standby Recovery
Media Recovery Log
Media Recovery Waiting for thread 1 seq# 435
Sat Jul 23 10:11:55 2005
Media Recovery Log C:\Oracle\oradata\ORCL\archive\log_435.arc
Mediate Recovery Waiting for thread 1 seq# 436
Sat Jul 23 10:12:55 2005
Media Recovery Log C:\Oracle\oradata\ORCL\archive\log_436.arc
Media Recovery Waiting for thread 1 seq# 437

This window will then hang indefinitely while it continues to look for archive logs to apply. To stop the recovery open another sqlplus
session and type:

SQL> RECOVER MANAGED STANDBY DATABASE CANCEL;

Read Only Database

The standby database can be opened in read only mode at any point. While open in this mode new archive logs are not applied to the
database.

SQL> -- Cancel recovery if necessary


SQL> RECOVER MANAGED STANDBY DATABASE CANCEL;
SQL> ALTER DATABASE OPEN READ ONLY;
The database can subsequently be switched back to recovery mode as follows:

SQL> CONNECT sys/password AS SYSDBA


SQL> SHUTDOWN IMMEDIATE
SQL> STARTUP NOMOUNT PFILE=C:\Oracle\Admin\SID\PFile\init.ora
SQL> ALTER DATABASE MOUNT STANDBY DATABASE;
SQL> RECOVER MANAGED STANDBY DATABASE (timeout <mins>);

Backup Standby Database

Backups of the standby database can only be performed if the database is shut down or in read only mode. Read only mode is best for
managed recovery systems as archive logs will still be transfered during the backup process, thus preventing gap sequences. Once the
server is in the desired mode simple copy the appropriate database files.
Standby server not available for a period

SQL> CONNECT sys/password AS SYSDBA


SQL> SHUTDOWN IMMEDIATE

Copy all archive logs from the primary to the standby server which were not copied and use following

SQL> STARTUP NOMOUNT PFILE=C:\Oracle\Admin\SID\PFile\init.ora


SQL> ALTER DATABASE MOUNT STANDBY DATABASE;
SQL> RECOVER STANDBY DATABASE;
SQL> RECOVER MANAGED STANDBY DATABASE;

Standby database will recover all new-copied files immediately and wait for next.
Alert log file display the following message

Media Recovery Log C:\Oracle\oradata\ORCL\archive\log_437.arc


Media Recovery Log C:\Oracle\oradata\ORCL\archive\log_438.arc
Media Recovery Log C:\Oracle\oradata\ORCL\archive\log_439.arc
Media Recovery Waiting for thread 1 seq# 440

Primary server not available for a period

Just restart primary server

To activate the standby database

To activate the standby, first try to copy the most recent archive logs over to the standby, and apply them, then use

SQL > Alter database activate standby database;


SQL > shutdown immediate;
SQL > startup mount;
SQL > alter database open read write;

Then shutdown the standby to reset file headers and clear all buffers. You can’t copy only redo logs from the primary to the standby.
The standby is dismounted when activated.
The standby bit in the controlfile is no set, so you can never go back – the standby is now your primary database. Since redo log sequence
was reset when the standby was opened, it is a good idea to take a full backup at this point.

Miscellaneous

Sustained recovery will NOT retrospectively apply archive log, which have already been generated on the standby host. For example, the
primary may have already archived a number of logs to the remote (standby) host. If the standby is put into sustained recovery mode after
the logs have been archived, and the logs are required for roll forward, the recovery session will sit there forever (unless the timeout
parameter is specified).

Solution: Ensure all logs already archived to the standby host have been applied before starting a sustained recovery session. This can be
achieved by first performing non-sustained recovery.

Hope this will help you a lot by Fateh…


Special thanks for Shiraz Qureshi.

You might also like