← Data Guard
Oracle · Data Guard
How to check the redo apply gap on an Oracle Data Guard standby
Compare last received vs last applied sequence per thread on an Oracle Data Guard standby, with RAC-aware host and timestamp variants.
Tested on11g12c18c19c21c23ai26ai
Two views of the same question: how far behind is the standby? Query 1 is single-instance and compares max sequence received (archived=''YES'') against max sequence applied (applied=''YES'') per thread. Query 2 uses GV$ views and adds host, instance, DB name, and the timestamp of the last applied archive — useful on a RAC standby.
-- 1) Simple gap (single-instance), tied to the current incarnation
SET LINES 800 PAGESIZE 10000
BREAK ON REPORT
COMPUTE SUM LABEL TOTAL OF gap ON REPORT
SELECT primary.thread#,
primary.maxsequence AS primary_seq,
standby.maxsequence AS standby_seq,
primary.maxsequence - standby.maxsequence AS gap
FROM (SELECT thread#, MAX(sequence#) AS maxsequence
FROM v$archived_log
WHERE archived = 'YES'
AND resetlogs_change# = (SELECT resetlogs_change# FROM v$database)
GROUP BY thread#) primary,
(SELECT thread#, MAX(sequence#) AS maxsequence
FROM v$archived_log
WHERE applied = 'YES'
AND resetlogs_change# = (SELECT resetlogs_change# FROM v$database)
GROUP BY thread#) standby
WHERE primary.thread# = standby.thread#;
-- 2) RAC-aware gap with host, instance, DB name, and last-applied timestamp
SET LINES 1000
COL host_name FORMAT a32
COL last_apply FORMAT a20
COL db_unique_name FORMAT a15
COL db_name FORMAT a10
SELECT DISTINCT
i.host_name,
i.instance_name,
a.thread#,
d.name AS db_name,
d.db_unique_name,
b.last_seq,
a.applied_seq,
TO_CHAR(a.last_app_timestamp, 'DD/MM/YYYY HH24:MI:SS') AS last_apply,
b.last_seq - a.applied_seq AS arc_diff
FROM (SELECT thread#,
MAX(sequence#) AS applied_seq,
MAX(next_time) AS last_app_timestamp
FROM gv$archived_log
WHERE applied IN ('YES', 'IN-MEMORY')
GROUP BY thread#) a,
(SELECT thread#, MAX(sequence#) AS last_seq
FROM gv$archived_log
GROUP BY thread#) b,
gv$instance i,
gv$database d
WHERE a.thread# = b.thread#
AND a.thread# = i.thread#
AND i.con_id = d.con_id;data guardapply gapv$archived_lograc