Professional Documents
Culture Documents
Diagnosis Oracle Logical Standby Data Guard Configuration and Scripts
Diagnosis Oracle Logical Standby Data Guard Configuration and Scripts
Configuration
-- NAME: DG_Logical_Standby_Diagnosis.sql
-- ------------------------------------------------------------------------
-- AUTHOR: Mohammad Abdul Momin Arju
-- January 2010.
-- ------------------------------------------------------------------------
-- PURPOSE:
-- This script is used to troubleshoot Oracle Data Guard issues for
-- Logical standby database.
-- ------------------------------------------------------------------------
-- DISCLAIMER:
-- This script is provided for educational purposes only.
-- Test it before you run in your production database.
-- ------------------------------------------------------------------------
-- Content of the Script
set linesize 79
set pagesize 180
set long 1000
set trim on
set trims on
alter session set nls_date_format = 'MM-DD-YYYY HH24:MI:SS';
set feedback on
select to_char(sysdate) time from dual;
set echo on
-- The following select will give us the generic information about how
-- this standby is setup. The database_role should be logical standby
as
-- that is what this script is intended to be ran on.
-- Force logging and supplemental logging are not mandatory but are
-- recommended if you plan to switchover. During normal operations it
is
-- acceptable for SWITCHOVER_STATUS to be SESSIONS ACTIVE or NOT
ALLOWED.
select force_logging,remote_archive,supplemental_log_data_pk,
supplemental_log_data_ui,switchover_status,dataguard_broker
from v$database;
set numwidth 8
column ID format 99
select process,status,client_process,sequence#
from v$managed_standby;
set numwidth 15
select
(case
when newest_scn = applied_scn then 'Done'
when newest_scn <= applied_scn + 9 then 'Done?'
when newest_scn > (select max(next_change#) from dba_logstdby_log)
then 'Near done'
when (select count(*) from dba_logstdby_log
where (next_change#, thread#) not in
(select first_change#, thread# from dba_logstdby_log)) > 1
then 'Gap'
when newest_scn > applied_scn then 'Not Done'
else '---' end) "Fin?",
newest_scn, applied_scn, read_scn from dba_logstdby_progress;
set numwidth 15
column trd format 99
set numwidth 15
set numwidth 15
-- Query the log miner dictionary for key tables necessary to process
-- changes for logical standby Label security will move AUD$ from SYS
to
-- SYSTEM. A synonym will remain in SYS but Logical Standby does not
-- support this.
set numwidth 5
column name format a9 wrap
column owner format a6 wrap
spool off
Databas
View e Description
DBA_LOGSTDBY_EVENTS Logical Contains information about the activity of a
only logical standby database. It can be used to
determine the cause of failures that occur when
SQL Apply is applying redo to a logical standby
database.
DBA_LOGSTDBY_HISTORY Logical Displays the history of switchovers and failovers
only for logical standby databases in a Data Guard
configuration. It does this by showing the
complete sequence of redo log streams
processed or created on the local system, across
all role transitions. (After a role transition, a new
log stream is started and the log stream
sequence number is incremented by the new
primary database.)
DBA_LOGSTDBY_LOG Logical Shows the log files registered for logical standby
only databases.
DBA_LOGSTDBY_NOT_UNIQUE Logical Identifies tables that have no primary and no
only non-null unique indexes.
DBA_LOGSTDBY_PARAMETERS Logical Contains the list of parameters used by SQL
only Apply.
DBA_LOGSTDBY_SKIP Logical Lists the tables that will be skipped by SQL
only Apply.
DBA_LOGSTDBY_SKIP_TRANSACT
ION
Logical Lists the skip settings chosen.
only
DBA_LOGSTDBY_UNSUPPORTED Logical Identifies the schemas and tables (and columns
only in those tables) that contain unsupported data
types. Use this view when you are preparing to
create a logical standby database.
V$ARCHIVE_DEST Primary, Describes all of the destinations in the Data
Databas
View e Description
physical, Guard configuration, including each destination's
snapshot, current value, mode, and status.
and Note: The information in this view does not
logical persist across an instance shutdown.
V$ARCHIVE_DEST_STATUS Primary, Displays runtime and configuration information
physical, for the archived redo log destinations.
snapshot, Note: The information in this view does not
and persist across an instance shutdown.
logical
V$ARCHIVE_GAP Physical, Displays information to help you identify a gap in
snapshot, the archived redo log files.
and
logical
V$ARCHIVED_LOG Primary, Displays archive redo log information from the
physical, control file, including names of the archived redo
snapshot, log files.
and
logical
V$DATABASE Primary, Provides database information from the control
physical, file. Includes information about fast-start failover
snapshot, (available only with the Data Guard broker).
and
logical
V$DATABASE_INCARNATION Primary, Displays information about all database
physical, incarnations. Oracle Database creates a new
snapshot, incarnation whenever a database is opened with
and the RESETLOGS option. Records about the current
logical and the previous incarnation are also contained
in the V$DATABASE view.
V$DATAFILE Primary, Provides datafile information from the control
physical, file.
snapshot,
and
logical
V$DATAGUARD_CONFIG Primary, Lists the unique database names defined with
physical, the DB_UNIQUE_NAME and LOG_ARCHIVE_CONFIGinitializ
snapshot, ation parameters.
and
Databas
View e Description
logical
V$DATAGUARD_STATS Primary, Displays various Data Guard statistics, including
physical, apply lag and transport lag. This view can be
snapshot, queried on any instance of a standby database.
and No rows are returned if queried on a primary
logical database. n.
V$DATAGUARD_STATUS Primary, Displays and records events that would typically
physical, be triggered by any message to the alert log or
snapshot, server process trace files.
and
logical
V$FS_FAILOVER_STATS Primary Displays statistics about fast-start failover
occurring on the system.
V$LOG Primary, Contains log file information from the online redo
physical, log files.
snapshot,
and
logical
V$LOGFILE Primary, Contains information about the online redo log
physical, files and standby redo log files.
snapshot,
and
logical
V$LOG_HISTORY Primary, Contains log history information from the control
physical, file.
snapshot,
and
logical
V$LOGSTDBY_PROCESS Logical Provides dynamic information about what is
only happening with SQL Apply. This view is very
helpful when you are diagnosing performance
problems during SQL Apply on the logical
standby database, and it can be helpful for other
problems.
V$LOGSTDBY_PROGRESS Logical Displays the progress of SQL Apply on the logical
only standby database.
V$LOGSTDBY_STATE Logical Consolidates information from
Databas
View e Description
only the V$LOGSTDBY_PROCESS and V$LOGSTDBY_STATS view
s about the running state of SQL Apply and the
logical standby database.
V$LOGSTDBY_STATS Logical Displays LogMiner statistics, current state, and
only status information for a logical standby database
during SQL Apply. If SQL Apply is not running,
the values for the statistics are cleared.
V$LOGSTDBY_TRANSACTION Logical Displays information about all active transactions
only being processed by SQL Apply on the logical
standby database.
V$MANAGED_STANDBY Physical Displays current status information for Oracle
and database processes related to physical standby
snapshot databases.
Note: The information in this view does not
persist across an instance shutdown.
V$REDO_DEST_RESP_HISTOGRAM Primary Contains the response time information for
destinations that are configured
for SYNC transport.
Note: The information in this view does not
persist across an instance shutdown.
V$STANDBY_EVENT_HISTOGRAM Physical Contains a histogram of apply lag values for the
physical standby. An entry is made in the
corresponding apply lag bucket by the Redo
Apply process every second. (This view returns
rows only on a physical standby database that
has been open in real-time query mode.)
Note: The information in this view does not
persist across an instance shutdown.
V$STANDBY_LOG Physical, Contains log file information from the standby
snapshot, redo log files.
and
logical
Run the following queries in your standby database in order to know details about your Data Guard
environment.
1) In order to know when your log last applied as well as last received log time issue following query:
select 'Last Applied : ' Logs, to_char(next_time,'DD-MON-
YY:HH24:MI:SS') Time
from v$archived_log
where sequence# = (select max(sequence#) from v$archived_log where
applied='YES')
union
select 'Last Received : ' Logs, to_char(next_time,'DD-MON-
YY:HH24:MI:SS') Time
from v$archived_log
where sequence# = (select max(sequence#) from v$archived_log);
Example output:
LOGS TIME
---------------- ------------------
Last Applied : 08-MAR-11:19:18:30
Last Received : 22-MAR-11:14:20:28
2) Verify the last sequence# received and the last sequence# applied to standby database by following
query:
select al.thrd "Thread", almax "Last Seq Received", lhmax "Last Seq
Applied"
from (select thread# thrd, max(sequence#) almax
from v$archived_log
where resetlogs_change#=(select resetlogs_change# from v$database)
group by thread#) al,
(select thread# thrd, max(sequence#) lhmax
from v$log_history
where first_time=(select max(first_time) from v$log_history)
group by thread#) lh
where al.thrd = lh.thrd;
Example output:
SQL> select al.thrd "Thread", almax "Last Seq Received", lhmax "Last
Seq Applied"
2 from (select thread# thrd, max(sequence#) almax
3 from v$archived_log
4 where resetlogs_change#=(select resetlogs_change# from
v$database)
5 group by thread#) al,
6 (select thread# thrd, max(sequence#) lhmax
7 from v$log_history
8 where first_time=(select max(first_time) from v$log_history)
9 group by thread#) lh
10 where al.thrd = lh.thrd;
3)In order to know about transport lag time, apply lag and apply finish time issue,
set lines 180
col name for a40
col value for a40
col unit for a40
select
NAME,
VALUE,
UNIT
from v$dataguard_stats
union
select null,null,' ' from dual
union
select null,null,'Time Computed: '||MIN(TIME_COMPUTED)
from v$dataguard_stats;
Example output:
NAME VALUE
UNIT
----------------------------------------
----------------------------------------
----------------------------------------
apply finish time
day(2) to second(3) interval
apply lag +13 16:29:57
day(2) to second(0) interval
estimated startup time 45
second
transport lag
day(2) to second(0) interval
6 rows selected.
4)In order to know the status of the processes involved in Data Guard configuration issue following query,
select
process,status,client_process,sequence#,block#,active_agents,known_age
nts
from v$managed_standby;
Example output:
SQL> select
process,status,client_process,sequence#,block#,active_agents,known_age
nts
from v$managed_standby;
8 rows selected.
5) In the primary database ensure that everything is fine by issuing following commands. In case of RAC
database ensure that these output is ok across all the instances.