Showing posts with label Dataguard. Show all posts
Showing posts with label Dataguard. Show all posts

Thursday, October 30, 2014

Resolving Gaps in DataGuard Physical Standby Using RMAN Incremental Backup


1.Defer log_archive_dest_state_2 in primary database

alter system set log_archive_dest_state_2='DEFER';

2.check Current_scn in primary and compare with Standby

SQL> select current_scn from v$database;
CURRENT_SCN
-----------
    3436343

3.alter database recover managed standby database cancel -->in standby
 rman target /

Recovery Manager: Release 11.2.0.2.0 - Production on Wed Oct 29 13:49:26 2014
Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.
connected to target database: RMAN (DBID=1700890588)

RMAN>
run {
allocate channel c1 type disk format '/backup/%U.bkp';
backup incremental from scn 3436343 database;
}

4.Transfer the backup pieces to Standby location

5.Backup control file in Primary Database location and transfer to standby location

alter database create standby controlfile as '/tmp/control_standby.ctl';

6.Startup mount physical standby database with latest control file
alter database mount standby database;
rman target /
catalog start with '/backup/%U.bkp';

>recover database;

In Standby Database

SQL> alter database recover managed standby database disconnect from session;

Enable below command in primary

alter system set log_archive_dest_state_2='ENABLE'; 

Archive log GAP detection

Archive log GAP detection:

SELECT ARCH.THREAD# "Thread", ARCH.SEQUENCE# "Last Sequence Received", APPL.SEQUENCE# "Last Sequence Applied", (ARCH.SEQUENCE# - APPL.SEQUENCE#) "Difference" FROM (SELECT THREAD# ,SEQUENCE# FROM V$ARCHIVED_LOG WHERE (THREAD#,FIRST_TIME ) IN (SELECT THREAD#,MAX(FIRST_TIME) FROM V$ARCHIVED_LOG GROUP BY THREAD#))ARCH, (SELECT THREAD# ,SEQUENCE# FROM V$LOG_HISTORY WHERE (THREAD#,FIRST_TIME ) IN (SELECT THREAD#,MAX(FIRST_TIME) FROM V$LOG_HISTORY GROUP BY THREAD#)) APPL WHERE ARCH.THREAD# = APPL.THREAD# ORDER BY 1;



Determining Which Log Files Were Not Received by the Standby Site.


SELECT LOCAL.THREAD#, LOCAL.SEQUENCE# FROM (SELECT THREAD#, SEQUENCE# FROM V$ARCHIVED_LOG WHERE DEST_ID=1) LOCAL WHERE LOCAL.SEQUENCE# NOT IN (SELECT SEQUENCE# FROM V$ARCHIVED_LOG WHERE DEST_ID=2 AND THREAD# = LOCAL.THREAD#);

Archive log difference:

ALTER SESSION SET NLS_DATE_FORMAT = 'DD-MON-YYYY HH24:MI:SS';

 SELECT a.thread#, b. last_seq, a.applied_seq, a. last_app_timestamp, b.last_seq-a.applied_seq ARC_DIFF FROM (SELECT thread#, MAX(sequence#) applied_seq, MAX(next_time) last_app_timestamp FROM gv$archived_log WHERE applied = 'YES' GROUP BY thread#) a, (SELECT thread#, MAX (sequence#) last_seq FROM gv$archived_log GROUP BY thread#) b WHERE a.thread# = b.thread#;


set lines 200
col name format a40
col value format a20
 select * from v$dataguard_stats;


  set lines 200
  col type format a30
  col ITEM format a20
  col comments format a20
  select * from v$recovery_progress;
 
 
  SET PAGESIZE 9999
  col day format a15
  SELECT A.*, Round(A.Count#*B.AVG#/1024/1024) Daily_Avg_Mb FROM(SELECT To_Char(First_Time,'YYYY-MM-DD') DAY, Count(1) Count#, Min(RECID) Min#, Max(RECID) Max# FROM gv$log_history GROUP BY To_Char(First_Time,'YYYY-MM-DD') ORDER BY 1 DESC) A,(SELECT Avg(BYTES) AVG#, Count(1) Count#, Max(BYTES) Max_Bytes, Min(BYTES) Min_Bytes FROM gv$log ) B;




Check MRP Rate:

set linesize 400
col Values for a65
col Recover_start for a21
select to_char(START_TIME,'dd.mm.yyyy hh24:mi:ss') "Recover_start",to_char(item)||' = '||to_char(sofar)||' '||to_char(units)||' '|| to_char(TIMESTAMP,'dd.mm.yyyy hh24:mi') "Values" from v$recovery_progress where start_time=(select max(start_time) from v$recovery_progress);


Delete Archive log in standby location:

#!/usr/bin/ksh
ARCH_DIR=/archive/orcl
#take the log number to be applied
LogNo=`tail -30000 /oracle/app/oracle/product/10.2.0/admin/orcl/bdump/alert* | grep "Media Recovery Log" | cut -d " " -f 4 | cut -d "_" -f 5 | tail -1 `
echo "Oracle applied LogNo is $LogNo"
#extract 10
let SecLogNo=${LogNo}-10
echo "new backlog log No: $SecLogNo"
#delete small numbers from this in arch dir
cd $ARCH_DIR
for i in `ls *.arc`
do
Newi=`echo $i | cut -d "_" -f 4`
if [ $Newi -lt $SecLogNo ] ; then
echo "$i to be deleted..."
rm $i
fi
done