Streams Capture Lag History (streams_capture_lag.sql)
What This Script Does
Section titled “What This Script Does”This script provides historical analysis of Oracle Streams capture processes by:
- Retrieving capture statistics from AWR history
- Showing message creation and enqueue rates
- Displaying capture lag in seconds
- Breaking down elapsed time by operation type
- Focusing on the last 24 hours of data
Script
Section titled “Script”column total_messages_created HEADING 'Total|Messages|Created'column total_messages_enqueued HEADING 'Total Messages|Enqueued'column lag format 999,999 HEADING 'Capture|Lag|(Seconds)'column elapsed_capture HEADING 'Elapsed Time|Capture|(centisecs'column elapsed_rule_time HEADING 'Elapsed Time|Rule Evaluation|(centisecs)'column elapsed_enqueue_time HEADING 'Elapsed Time|Enqueuing Messages|(centisecs)'column elapsed_lcr HEADING 'Elapsed Time|LCR Creation|(centisecs)'column elapsed_redo_wait_time HEADING 'Elapsed Time|Redo Wait|(centisecs)'column elapsed_Pause_time HEADING 'Elapsed Time|Paused|(centisecs)'column begin_interval_time format a27column end_interval_time format a27column snap_id format 9,999column dbid format 9999999999column instance_number format 999column capture_name format a16column total_messages_captured heading 'Messages|Captured'
select s.begin_interval_time,s.end_interval_time , sc.* from dba_hist_streams_capture sc, dba_hist_snapshot s where sc.snap_id=s.snap_id and s.end_interval_time >= systimestamp-1 order by sc.capture_name,s.end_interval_time;
SQL> @streams_capture_lag.sql
Required Privileges
Section titled “Required Privileges”- SELECT on DBA_HIST_STREAMS_CAPTURE
- SELECT on DBA_HIST_SNAPSHOT
- AWR data must be available
Sample Output
Section titled “Sample Output” Messages CaptureBEGIN_INTERVAL_TIME END_INTERVAL_TIME SNAP_ID DBID INSTANCE CAPTURE_NAME Captured Lag--------------------------- --------------------------- ------- ----------- -------- ---------------- -------- --------15-JAN-24 01:00:22.123 15-JAN-24 02:00:25.456 1001 1234567890 1 STREAMS_CAPTURE 45,678 12315-JAN-24 02:00:25.456 15-JAN-24 03:00:28.789 1002 1234567890 1 STREAMS_CAPTURE 52,345 15615-JAN-24 03:00:28.789 15-JAN-24 04:00:31.012 1003 1234567890 1 STREAMS_CAPTURE 48,901 89
Key Output Columns
Section titled “Key Output Columns”- BEGIN/END_INTERVAL_TIME: AWR snapshot time window
- SNAP_ID: AWR snapshot identifier
- CAPTURE_NAME: Name of the capture process
- Messages Captured: Total messages captured in interval
- Capture Lag (Seconds): Delay between redo generation and capture
- Elapsed Time columns: Breakdown of time spent in different operations
Understanding the Metrics
Section titled “Understanding the Metrics”Capture Lag Thresholds
Section titled “Capture Lag Thresholds”- Optimal: < 60 seconds
- Acceptable: 60-300 seconds
- Warning: 300-600 seconds
- Critical: > 600 seconds
Performance Indicators
Section titled “Performance Indicators”- Message Rate: Messages captured per interval
- Redo Wait Time: Time waiting for redo data
- Rule Evaluation: Time spent evaluating capture rules
- Enqueue Time: Time to enqueue messages
Common Use Cases
Section titled “Common Use Cases”-
Performance Trending
- Track capture lag over time
- Identify peak periods
- Plan capacity requirements
-
Troubleshooting
- Diagnose increasing lag
- Find performance bottlenecks
- Correlate with system events
-
Capacity Planning
- Analyze message volumes
- Predict growth patterns
- Size Streams pool appropriately
Advanced Analysis
Section titled “Advanced Analysis”Modify Time Range
Section titled “Modify Time Range”-- Last 7 daysand s.end_interval_time >= systimestamp-7
-- Specific date rangeand s.end_interval_time between to_timestamp('2024-01-15 00:00:00','YYYY-MM-DD HH24:MI:SS') and to_timestamp('2024-01-16 00:00:00','YYYY-MM-DD HH24:MI:SS')
Additional Metrics
Section titled “Additional Metrics”-- Include all elapsed time columnsselect s.begin_interval_time, s.end_interval_time, sc.capture_name, sc.total_messages_captured, sc.lag, sc.elapsed_capture_time, sc.elapsed_rule_time, sc.elapsed_enqueue_time, sc.elapsed_lcr_time, sc.elapsed_redo_wait_time, sc.elapsed_pause_timefrom dba_hist_streams_capture sc, dba_hist_snapshot swhere sc.snap_id=s.snap_idorder by sc.capture_name,s.end_interval_time;
Troubleshooting High Lag
Section titled “Troubleshooting High Lag”-
Check Capture State
SELECT capture_name, state, error_number, error_messageFROM dba_captureWHERE capture_name = 'STREAMS_CAPTURE'; -
Review LogMiner Sessions
SELECT session_id, used_memory, max_memoryFROM v$logmnr_session; -
Analyze Redo Generation Rate
SELECT to_char(first_time,'YYYY-MM-DD HH24') hour,count(*) log_switches,round(sum(blocks*block_size)/1024/1024) mbFROM v$archived_logWHERE first_time > sysdate-1GROUP BY to_char(first_time,'YYYY-MM-DD HH24')ORDER BY 1;
Best Practices
Section titled “Best Practices”-
Monitoring
- Set alerts for lag > 300 seconds
- Track message rate trends
- Monitor Streams pool usage
-
Performance Tuning
- Optimize capture rules
- Size Streams pool appropriately
- Consider parallelism settings
-
Maintenance
- Regular statistics gathering
- Periodic capture restart
- Archive old processed logs