Practical Steps To Implement Standby Database
Practical Steps To Implement Standby Database
Assumptions:
A. Oracle version used: 9.x B. Both the primary and the standby database are in the same machine. C. The primary database name will be db1 and the secondary database name will be db2 D. ORACLE_HOME=D:\oracle\ora92 E. The drive going to be used (here D) has atleast 1.2 GB free space
1. Create an initialization parameter file i.e. initdb1.ora with the following entries and place it ORACLE_HOME\database:
########################################################## *.compatible='9.2.0.0.0'
*.background_dump_dest='D:\oracle\ora92\admin\db1\bdump' *.core_dump_dest='D:\oracle\ora92\admin\db1\cdump'
*.user_dump_dest='D:\oracle\ora92\admin\db1\udump' *.control_files='d:\oracle\oradata\db1\control01.ctl','d:\oracle\oradata\db1\control02.ctl'
*.db_block_size=8192 *.db_cache_size=33554432 *.db_file_multiblock_read_count=16 *.dispatchers='(PROTOCOL=TCP) (SERVICE=db1XDB)' *.java_pool_size=33554432 *.large_pool_size=8388608 *.log_archive_start=TRUE *.open_cursors=300 *.pga_aggregate_target=25165824 *.processes=200 *.query_rewrite_enabled='FALSE' *.sga_max_size=157286400 *.shared_pool_size=50331648 *.sort_area_size=524288 *.timed_statistics=TRUE *.undo_management='AUTO' *.undo_retention=10800
*.undo_tablespace='UNDOTBS1'
##########################################################
2. Create the folders- bdump, cdump, udump, pfile (under D:\oracle\ora92\admin\db1) and the folder for the control files (d:\oracle\oradata\db1) as mentioned in the initdb1.ora file
set ORACLE_SID=db1
sqlplus /nolog
conn / as sysdba
4. Create a database with the name db1. This will be the primary database. In the SQL Plus prompt:
CREATE DATABASE db1 CONTROLFILE REUSE LOGFILE GROUP 1 'd:\oracle\oradata\db1\LOG01.LOG' SIZE 5M REUSE, GROUP 2 'd:\oracle\oradata\db1\LOG02.LOG' SIZE 5M REUSE
DATAFILE 'd:\oracle\oradata\db1\SYSTEM01.DBF' SIZE 400M REUSE DEFAULT TEMPORARY TABLESPACE TEMP TEMPFILE 'd:\oracle\oradata\db1\TEMP01.DBF' SIZE 50M REUSE UNDO TABLESPACE UNDOTBS1 DATAFILE 'd:\oracle\oradata\db1\UNDO01.DBF' SIZE 50M REUSE
CONN / as SYSDBA
SHUTDOWN IMMEDIATE
(SID_NAME = db1) )
10. In the tnsnames.ora file make the following entry (change the host name appropriately):
db1 = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 172.24.43.151)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED)(SERVICE_NAME = db1) ) )
CONN / AS SYSDBA
STARTUP MOUNT
########################################################## ##########################################################
########################################################## ##########################################################
SHUTDOWN IMMEDIATE
2. Create the folders- bdump, cdump, udump, pfile (under D:\oracle\ora92\admin\db2) and the folder for the control files (d:\oracle\oradata\db2) as mentioned.
3. Create an initialization parameter file i.e. initdb2.ora with the following entries and place it ORACLE_HOME\database:
##########################################################
*.compatible='9.2.0.0.0'
*.db_block_size=8192 *.db_cache_size=33554432 *.db_domain='' *.db_file_multiblock_read_count=16 *.dispatchers='(PROTOCOL=TCP) (SERVICE=db2XDB)' *.java_pool_size=33554432 *.large_pool_size=8388608 *.log_archive_dest_1='' *.log_archive_start=TRUE *.open_cursors=300 *.pga_aggregate_target=25165824 *.processes=200 *.query_rewrite_enabled='FALSE' *.sga_max_size=157286400 *.shared_pool_size=50331648 *.sort_area_size=524288 *.timed_statistics=TRUE *.undo_management='AUTO' *.undo_retention=10800
*.undo_tablespace='UNDOTBS1' *.REMOTE_LOGIN_PASSWORDFILE='EXCLUSIVE'
*.DB_FILE_NAME_CONVERT='D:\oracle\oradata\db1\','D:\oracle\oradata\db2\' *.DB_NAME='db1' *.instance_name='db2' *.service_names='db2' *.FAL_CLIENT='db2' *.FAL_SERVER='db1' *.LOCK_NAME_SPACE='db2' *.LOG_FILE_NAME_CONVERT='D:\oracle\oradata\db1\','D:\oracle\oradata\db2\' *.STANDBY_ARCHIVE_DEST='D:\oracle\oradata\db2' *.log_archive_dest='D:\oracle\oradata\db2' *.control_files='D:\oracle\oradata\db2\STBY_DB1.CTL'
##########################################################
4. Copy all datafiles and controlfiles of db1 as shown below to the location D:\oracle\oradata\db2.should be there:
D:\oracle\oradata\db1\LOG02.LOG
set ORACLE_SID=db2
sqlplus /nolog
conn / as sysdba
6. Startup the primary database and then change the following parameter in the spfile:
conn / as sysdba
startup OPEN
7. In the listener.ora file add the following entry and reload the listener:
8. In the tnsnames.ora file add the following entry (change the host name appropriately):
db2 = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 172.24.43.151)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED)(SERVICE_NAME = db2) ) )
SHUTDOWN IMMEDIATE;
STARTUP OPEN;
11. You can check the status of the standby database by:
########################################################## ##########################################################
########################################################## ##########################################################
commit;
2. Cancel the recovery mode of the standby database and open it in read only mode:
If you are able to see the records inserted in the temp table under test schema in the primary database in this secondary database your standby is working fine.
-=========================
USEFULL QUERIES:
-------------------------------------------------------------------------------SELECT SEQUENCE#, FIRST_TIME, NEXT_TIME FROM V$ARCHIVED_LOG ORDER BY SEQUENCE#; --IN PRIMARY DB
########################################################## ##########################################################
########################################################## ##########################################################
--------------------------------------------------------------------------------
Before going through the following steps make a backup copy of the following files of both db1 and db2:
--------------------------------------------------------------------------------
STEPS:
--------------------------------------------------------------------------------
3. In primary execute:
4. In secondary execute:
Select max (al.sequence#) "Last Seq Recieved", max(lh.sequence#) "Last Seq Applied" from v$archived_log al, v$log_history lh;
#*.control_files='d:\oracle\oradata\db1\control01.ctl','d:\oracle\oradata\db1\control02.ctl'
shutdown immediate;
--------------------------------------------------------------------------------
shutdown immediate;
#*.FAL_CLIENT='db2' #*.FAL_SERVER='db1'
#*.STANDBY_ARCHIVE_DEST='D:\oracle\oradata\db2' #*.log_archive_dest='D:\oracle\oradata\db2'
Now you can verify the role of the new primary(db2) and secondary(db1) in exactly the same way you did it while testing earlier by making some changes in the "test" table.
########################################################## ##########################################################
########################################################## ##########################################################
--------------------------------------------------------------------------------
STEPS:
--------------------------------------------------------------------------------
3. In primary execute:
4. In secondary execute:
Select max (al.sequence#) "Last Seq Recieved", max(lh.sequence#) "Last Seq Applied" from v$archived_log al, v$log_history lh;
5. In initialization parameter file of db2 uncomment the following lines which were commented:
shutdown immediate;
--------------------------------------------------------------------------------
*.control_files='D:\oracle\oradata\db1\STBY_DB1.CTL' *.STANDBY_ARCHIVE_DEST='D:\oracle\oradata\db1\dest_1'
*.FAL_CLIENT='db1' *.FAL_SERVER='db2'
shutdown immediate;
6. Verify the roles of the primary and standby database by making some change in the
########################################################## ##########################################################
########################################################## ##########################################################
Failover is performed when the primary is completely crashed and there is no option other then activating the standby as primary.
--------------------------------------------------------------------------------
1. Comment/remove the following lines from the initialization file of db2 i.e. initdb2.ora
*.FAL_CLIENT='db2' *.FAL_SERVER='db1'
SHUTDOWN IMMEDIATE;
3. Startup and open the database with the updated initialization file:
IT CANNOT BE ROLLEDBACK TO PREVIOUS STAGE OF STANDBY BECAUSE THE LOG SEQUENCE NUMBERS WILL BE RESET.