You are on page 1of 11

Create Oracle10g Physical Standby Database with Rman 1.

Description of the demo Data Guard The diagram below depicts a demo physical standby database setup with one primary database and one physical standby database. It is implemented on 2 Linux servers , running Oracle Enterprise Edition Release 10.2.0.3.0. Primary database, med, is located on asp_sandbox server and a physical standby database, stby is located on asp_standby server. Oracle Net service is Established between the two servers with Net Service names, PRIME for the primary database and STBY for the standby database. Demo Data Guard Diagram with one Primary and Physical Standby Database

Primary Database Asp_Sandbox

Physical Standby DB Asp_Stan dby Standby Archive d Redo Log Files

Log Apply Servic es

Online Redo Log Files

Log Transport Service

Archiv ed Redo Logs

Standby Online Redo Log Files es Oracle Net Service

Standb y Redo Log Files

Primary DB Archived Redo Logs

2. Prepare the primary server a. Enable forced logging on prime db Sql>alter database force logging; b. Create a password file orapwd file=passwordfile passoword=oracle entries=5 c. Setup the init parameters:

db_name=med db_unique_name=PRIME LOG_ARCHIVE_CONFIG='DG_CONFIG=(PRIME,ST BY)' LOG_ARCHIVE_DEST_1= 'LOCATION=USE_DB_RECOVERY_FILE_DEST VALID_FOR=(ALL_LOGFI LES,ALL_ROLES) DB_UNIQUE_NAME=PRI ME' LOG_ARCHIVE_DEST_2= 'SERVICE=STBY LGWR ASYNC VALID_FOR=(ONLINE_L OGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=STB Y' LOG_ARCHIVE_DEST_STATE_1=ENABLE LOG_ARCHIVE_DEST_STATE_2=defer LOG_ARCHIVE_FORMAT=med_%t_%s_%r.arc LOG_ARCHIVE_MAX_PROCESSES=4 remote_login_passwordfile='EXCLUSIVE' FAL_SERVER=STBY FAL_CLIENT=PRIME STANDBY_FILE_MANAGEMENT=AUTO STANDBY_ARCHIVE_DEST= USE_DB_RECOVERY_FILE_DEST Local_listener=(address=(protocol=tcp)(host=aspsandbox)(port=1521)) Service_name=PRIME Db_recovery_file_dest=/home/oracle/arc_logs Db_recovery_file_dest_size=10g d. Create spfile from pfile and restart prime db Sql>create spfile from pfile; 3. Back up prime db for standby using following script #!/bin/sh export ORACLE_HOME=/u01/app/oracle/product/10.2.0 export ORACLE_SID=med

LOG=/home/oracle/u01/app/oracle/scripts/workarea/logs/rmam_ba ckup_$$.log Who_Mail=daniel@4medica.com $ORACLE_HOME/bin/rman target / > ${LOG} << ! run { backup as compressed backupset database include current controlfile for standby; sql "alter system archive log current"; backup archivelog all delete input; } ! /bin/cat ${LOG} |grep "^([ORA|RMAN]-[0-9])*: " > ${LOG}.err if [ `/bin/cat ${LOG}.err |wc -l` -ne 0 ] then /bin/mail -s "Rman Backup failed.." ${Who_Mail} < ${LOG}.err exit 4 else /bin/mail -s "Rman Backup completed" ${Who_Mail} < ${LOG} # /bin/rm -f ${LOG}.* fi 4.Add standby redo logs Sql>alter database add standby logfile group 4 /home/oracle/arc_logs/PRIME/onlinelog/prime_stby01.dbf size 100M; Sql> alter database add standby logfile group 5 /home/oracle/arc_logs/PRIME/onlinelog/prime_stby02.dbf size 100M; Sql> alter database add standby logfile group 6 /home/oracle/arc_logs/PRIME/onlinelog/prime_stby03.dbf size 100M; Sql> alter database add standby logfile group 7 /home/oracle/arc_logs/PRIME/onlinelog/prime_stby04.dbf size 100M; 5.Set Oracle Net on both prime and standby using Prime and Stby pointing to prime and standby databases STBY =

(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP) (Host = 192.168.101.55) (Port = 1521) ) ) (CONNECT_DATA = (SID = med)) ) PRIME = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP) (Host = 192.168.101.112) (Port = 1521) ) ) (CONNECT_DATA = (SID = med)) ) 6. Prepare the standby server a. Copy all the db backupsets and controlfile backup to the standby server b. Copy the init parameter file from prime to the standby server and make the following changes: db_unique_name=STBY log_archive_dest_2='SERVICE=PRIME lgwr async valid_for=(online_logfiles,primary_role) db_unique_name=PRIME' fal_server=PRIME fal_client=STBY local_listener='(address=(protocol=tcp)(host=aspstandby)(port=1521))' service_names='STBY' STANDBY_ARCHIVE_DEST= USE_DB_RECOVERY_FILE_DEST c. Start the instance and create spfile as SQL> Startup nomount; SQL> Create pfile from spfile; d. Create standby db with the following script #!/bin/sh export ORACLE_HOME=/u01/app/oracle/product/10.2.0 export ORACLE_SID=med LOG= /home/oracle/u01/app/oracle/rman_logs/stby_$$.log Who_Mail=daniel@4medica.com $ORACLE_HOME/bin/rman target sys/oracle@PRIME auxiliary sys/oracle@STBY > ${LOG} <<! run {

allocate channel cl device type disk format '/save/oracle_save/aspsandbox/rman-backup/full_%u_%s_%p'; allocate auxiliary channel axu1 device type disk format '/save/oracle_save/asp-sandbox/rman-backup/full_%u_%s_%p'; set until logseq 1124 thread 1; duplicate target database for standby nofilenamecheck dorecover; } exit; ! /bin/cat ${LOG} | grep "^([ORA|RMAN]-[0-9])*: " > ${LOG}.err if [ `/bin/cat ${LOG}.err |wc -l` -ne 0 ] then k /bin/mail -s "Rman Stby Creation faled..." ${Who_Mail} < ${LOG}.err exit 2 else /bin/mail -s "Rman Stby Creation Completed" ${Who_Mail} < ${LOG} /bin/rm -f ${LOG}.* fi 4. Add standby redo log files on standby db (alter database add standby logfile group 4,5,6 size 100M;) Sql>alter database add standby logfile group 4 /home/oracle/arc_logs/STBY/onlinelog/stby_stby01.dbf size 100M; Sql> alter database add standby logfile group 5 /home/oracle/arc_logs/STBY/onlinelog/stby_stby02.dbf size 100M; Sql> alter database add standby logfile group 6 /home/oracle/arc_logs/STBY/onlinelog/stby_stby03.dbf size 100M; Sql> alter database add standby logfile group 7 /home/oracle/arc_logs/STBY/onlinelog/stby_stby04.dbf size 100M; 5. Enable automatic archive log applying service on standby db Sql>alter database recover managed standby database disconnect; 6. Enable archive log transportation service on prime db

Sql> alter system set LOG_ARCHIVE_DEST_STATE_2=enable scope=both; 7. Test archive log transportation on prime db Sql> alter system switch logfile; 8. Validating archive log applying on standby db Sql> select sequence#, archived, applied from v$archived_log;

SWITCHOVER TEST
Switchover prime database to standby database as 1. Make sure all logs are applied on standby database, execute following 3 times Sql>alter system switch logfile; 2. Make sure nobody is logged on the prime db Sql > SELECT OSUSER, USERNAME FROM V$SESSION. 3. Make sure prime db is ready to be switchover to standby Sql>select switchover_status from v$database; This should output to as To_Standby; 4. Switchover to standby and verify Sql> alter database commit to switchover to physical standby; Sql> shutdown immediate; Sql> startup mount; Sql> select switchover_status from v$database; This should output to as To_Primary; 5. bring up standby database Sql>alter database recover managed standby database disconnect; 6. Switchover standby database to primary database

Cancel log applying on standby as Sql>recover managed standby database cancel; Sql> alter database commit to switchover to primary; Sql> select switchover_status from v$database; Sql>Alter database open; Sql> alter system switch logfile;

FAILOVER TEST
Preparing for a Role Transition(Failover or Switchover) *. Verify init parameters for each db are configured correctly *. Ensure temporary tablespace and tempfiles exist on stby db that match temporary tablespace and tempfiles on primary *. Remove any delay in applying redo that may be in effect on the stby db to be the primary Preparing for a Failover 0. before testing failover, first verify redo logs that have been applied/archived on both primary and physical standby db sql>select sequence#, first_time, next_time,applied from v$archived_log order by sequence#; 1. try to transfer as much of available and unapplied prime db redo log as possible to standby db. sql>alter system switch logfile; 2. verify that the stby is ready to failover sql>select database_role from v$database; 3. Failover Steps: to transition a physical standby db to the primary role, make sure that no redo log gaps exist and then proceed with the failover, or go back to determine if any manual gap resolution steps should be performed. Step 1. Identify and resolve any gaps in the archived redo log files sql>select sequence#, applied, archived, first_time, next_time from v$archived_log where applied = YES order by sequence#; sql> select thread#, low_sequence#, high_sequence# from v$archive_gap;

Step 2. If there is a gap of three logs, use the following to , after copying missing archivelogs from primary to stby. If archivelogs are not available on ASP Prod, copy them from ASP_Patch. sql>alter database register physical logfile filespec1; Repeat it till all gaps are resolved and copy all the logs necessary to the standby server. Step 3. Initiate a failover on the target physical standby database Sql> alter database recover managed standby database finish force; Note: force keyword terminates active RFS process on the target stby db, so that failover can proceed immediately without waiting for network timeout. Failover adds an end-of-redo marker to the header of the last log file being archived. Step 4. Convert the physical standby database to the primary role Once the .finish force completes successfully, change the standby db to the primary db role by Sql>alter database commit to switchover to primary; Step 5. Finish the transition of the standby database to the primary database role If the stby db has not been opened in read-only mode since the last time it was started: Sql> alter database open; Then perform a backup of the new database If the stby db has been opened in read-only mode since the last time it was started: Sql>shutdown immediate; Sql>startup; Then perform a backup of the new database Data Guard does not guarantee 100% of data recovery. We have size of Redo logs of 100M on ASP_PROD and in case of disaster, we may loose 100m of transaction data. 1.shut down primary db to simulate primary crash.

[oracle@asp-sandbox] $sqlplus '/as sysdba' SQL*Plus: Release 10.2.0.3.0 - Production on Sat Nov 20 22:42:12 2010 Copyright (c) 1982, 2006, Oracle. All Rights Reserved. Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 Production With the Partitioning, OLAP and Data Mining options SQL> shutdown immediate Database closed. Database dismounted. ORACLE instance shut down. 2.initiate a failover on the stby db [oracle@asp-standby] $sqlplus / as sysdba SQL*Plus: Release 10.2.0.3.0 - Production on Sat Nov 20 22:45:05 2010 Copyright (c) 1982, 2006, Oracle. All Rights Reserved. Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 Production With the Partitioning, OLAP and Data Mining options SQL> alter database recover managed standby database finish force; Database altered. 3.convert stby db to the primary role SQL> alter database commit to switchover to primary; Database altered. 4. finish the transition process SQL> select database_role from v$database; DATABASE_ROLE ---------------PRIMARY SQL> alter database open; Database altered. 5. disable log shipping between the new primary to the old primary NAME TYPE VALUE

------------------------------------ ----------- -----------------------------log_archive_dest_state_2 string ENABLE SQL> alter system set log_archive_dest_state_2=defer scope=both; System altered. =================================================== =========================== old primary archive logs: -rw-rw---- 1 oracle dba 93557248 Nov 20 00:19 o1_mf_1_1250_6gh14gp8_.arc -rw-rw---- 1 oracle dba 93554688 Nov 20 01:00 o1_mf_1_1251_6gh3lb4s_.arc -rw-rw---- 1 oracle dba 93557248 Nov 20 13:00 o1_mf_1_1252_6gjfq2jw_.arc -rw-rw---- 1 oracle dba 93557248 Nov 20 21:02 o1_mf_1_1253_6gk9z6qd_.arc -rw-rw---- 1 oracle dba 93557248 Nov 20 21:04 o1_mf_1_1254_6gkb3mpg_.arc -rw-rw---- 1 oracle dba 93555712 Nov 20 22:00 o1_mf_1_1255_6gkfct5r_.arc [oracle@asp-sandbox] $pwd /home/oracle/arc_logs/PRIME/archivelog/2010_11_20 new primary archive logs: -rw-r----- 1 oracle dba 93554688 Nov 20 01:00 o1_mf_1_1251_6gh14cmv_.arc -rw-r----- 1 oracle dba 93557248 Nov 20 13:00 o1_mf_1_1252_6gh3l7y5_.arc -rw-r----- 1 oracle dba 93557248 Nov 20 21:02 o1_mf_1_1253_6gjfq1xn_.arc -rw-r----- 1 oracle dba 93557248 Nov 20 21:04 o1_mf_1_1254_6gk9z598_.arc -rw-r----- 1 oracle dba 93555712 Nov 20 22:00 o1_mf_1_1255_6gkb3k7d_.arc -rw-r----- 1 oracle dba 1024 Nov 20 22:45 o1_mf_1_1256_6gkj0o47_.arc -rw-r----- 1 oracle dba 1024 Nov 20 22:49 o1_mf_1_1_6gkj7nks_.arc -rw-r----- 1 oracle dba 4194816 Nov 20 22:49 o1_mf_1_0_6gkj0nns_.arc [oracle@asp-standby] $pwd

/home/oracle/arc_logs/STBY/archivelog/2010_11_20 6.take a backup of the newly created primary db Nohup /bin/sh /u01/app/oracle/scripts/workarea/rman_backup4_standby.sh & 7.failover from asp_standby to asp_sandbox follows the same procedure. 9. Failover Scenarios If database crashes, we need to failover apache and database. If Apache crashes, we only failover apache and switch over the database.

You might also like