Check Missing Archive Logs in Oracle Data Guard Standby Database
Check Missing Archive Logs in Oracle Data Guard Standby Database
Purpose
This SQL query helps database administrators identify missing archive logs on an Oracle Data Guard standby database. When archive logs fail to transfer from the primary to the standby database, it creates gaps that prevent proper synchronization. Running this query on the standby database reveals which log sequences are present locally but missing at the destination, allowing administrators to take corrective action before the gap becomes too large.
Original Code
1select local.thread#
2, local.sequence# from
3 (select thread#
4 , sequence#
5 from v$archived_log
6 where dest_id=1) local
7where local.sequence# not in
8 (select sequence#
9 from v$archived_log
10 where dest_id=2 and
11 thread# = local.thread#)
12/
Code Breakdown
The query works by comparing two sets of archive log records from the v$archived_log view.
Inner Query (local):
- Selects
thread#andsequence#fromv$archived_log - Filters for
dest_id=1, which represents the local archived logs on the standby database - Creates a subquery alias called
local
Outer Query:
- Retrieves thread number and sequence number from the local set
- Uses
NOT INclause to exclude sequences that exist indest_id=2 - Filters by matching
thread#to ensure comparison within the same redo thread
Result:
The query returns all archive log sequences that exist locally (dest_id=1) but are missing from the standby destination (dest_id=2).
Key Points
- Run on standby database only: This query must be executed on the standby database to detect gaps
- dest_id values:
dest_id=1typically refers to local archived logs, whiledest_id=2refers to the standby destination - Thread awareness: The query accounts for RAC environments where multiple threads exist
- Gap detection: Missing sequences indicate synchronization issues that require immediate attention
Insights and Best Practices
Oracle Data Guard relies on continuous archive log transfer to keep standby databases synchronized with the primary. When archive logs go missing, the standby database cannot apply changes, creating a recovery gap that increases over time. This query provides a quick diagnostic tool to identify specific missing sequences.
For small gaps (fewer than 15-20 logs), administrators can manually copy missing archive logs from the primary database and register them on the standby using ALTER DATABASE REGISTER LOGFILE. For larger gaps, Oracle recommends using incremental backup methods to resynchronize the standby database.
Alternative gap detection methods include querying v$archive_gap view or checking v$managed_standby to see where log apply processes have stopped. Regular monitoring of archive log gaps prevents situations where standby databases fall too far behind to be useful for disaster recovery or failover scenarios.
References
- V$ARCHIVED_LOG - Oracle Help Center - Official Oracle documentation for v$archived_log view structure and columns
- How to Recover Archive Gaps in Standby Database - Two methods for resolving archive log gaps including manual shipping and incremental backup strategies
- Resolving Missing Archive Log Gap in Oracle Data Guard - Step-by-step guide for fixing archive log gaps using incremental backups and standby control files
- Troubleshooting Data Guard - Oracle Help Center - Official troubleshooting guide covering common Data Guard problems including archive destination errors
- Query Executed by DataGuard Gap Oracle Probe - Advanced query for tracking archive log gaps between primary and standby databases
- Data Guard Cheatsheet - Datadisk - Comprehensive command reference for Data Guard monitoring including archive gap detection
- Resolving Archive Log Gaps in Oracle Data Guard - Video explanation of detecting and resolving archive log gaps with practical examples