Advanced Queuing Table Status (vaq.sql)
What This Script Does
Section titled “What This Script Does”This script monitors Oracle Advanced Queuing activity by:
- Displaying current queue status and message counts
- Showing waiting, ready, and expired message statistics
- Filtering for queues with active messages only
- Supporting pattern matching for owner and queue name
- Providing wait time statistics for performance analysis
- Joining performance views with queue metadata
Script
Section titled “Script”rem vaq.sqlremtti 'AQ Table Status'remset lines 132remcol owner format a9col name format a30col queue_table format a30rem col waiting,rem col ready,rem col expired,rem col total_wait,rem col average_waitremselect owner, name, queue_table, waiting, ready, expired, total_wait, average_wait-- from gv$aq g ,from v$aq g , all_queues dwhere g.qid = d.qidand upper(d.owner) like upper(nvl('&owner', '%'))and upper(d.name) like upper(nvl('&name', '%'))and (g.waiting > 0 or g.ready > 0 or g.expired > 0)order by owner, name/
SQL> @vaq.sqlEnter value for owner: SCOTTEnter value for name: ORDER%
Parameters
Section titled “Parameters”- owner: Queue owner pattern (% for all owners, specific name for single owner)
- name: Queue name pattern (% for all queues, specific pattern for filtering)
Required Privileges
Section titled “Required Privileges”- SELECT on V$AQ
- SELECT on ALL_QUEUES
Sample Output
Section titled “Sample Output”AQ Table Status
OWNER NAME QUEUE_TABLE WAITING READY EXPIRED TOTAL_WAIT AVERAGE_WAIT--------- ------------------------------ ------------------------------ --------- ---------- ---------- ---------- ------------SCOTT ORDER_QUEUE ORDER_QT 0 125 5 234 45.2SCOTT PAYMENT_QUEUE PAYMENT_QT 3 87 2 456 78.5HR EMPLOYEE_NOTIFICATIONS EMP_NOTIF_QT 0 45 0 89 12.3SALES CUSTOMER_UPDATES CUST_UPD_QT 1 234 12 567 89.1
Key Output Columns
Section titled “Key Output Columns”- OWNER: Schema that owns the queue
- NAME: Queue name
- QUEUE_TABLE: Underlying queue table name
- WAITING: Number of messages waiting to be processed
- READY: Number of messages ready for consumption
- EXPIRED: Number of expired messages
- TOTAL_WAIT: Total wait time for all operations
- AVERAGE_WAIT: Average wait time per operation
Understanding Queue Message States
Section titled “Understanding Queue Message States”Message State Definitions
Section titled “Message State Definitions”- WAITING: Messages not yet ready for dequeue (future processing)
- READY: Messages available for immediate consumption
- EXPIRED: Messages that exceeded their expiration time
- PROCESSED: Messages successfully consumed (not shown in active count)
Normal vs Problem Patterns
Section titled “Normal vs Problem Patterns”- Healthy Queue: Low waiting, steady ready count, minimal expired
- Backlog: High ready count, increasing over time
- Stalled Processing: High waiting count, low ready processing
- Expiration Issues: High expired count
Queue Performance Analysis
Section titled “Queue Performance Analysis”Message Flow Health
Section titled “Message Flow Health”-- Extended analysis with retention infoSELECT q.owner, q.name, q.queue_table, aq.waiting, aq.ready, aq.expired, q.max_retries, q.retry_delay, q.retention_timeFROM all_queues q, v$aq aqWHERE q.qid = aq.qidAND (aq.waiting > 0 OR aq.ready > 0 OR aq.expired > 0)ORDER BY (aq.waiting + aq.ready + aq.expired) DESC;
Wait Time Analysis
Section titled “Wait Time Analysis”-- Calculate efficiency metricsSELECT owner, name, CASE WHEN total_wait = 0 THEN 0 ELSE ROUND(average_wait, 2) END avg_wait_time, CASE WHEN average_wait < 10 THEN 'Excellent' WHEN average_wait < 50 THEN 'Good' WHEN average_wait < 100 THEN 'Fair' ELSE 'Poor' END performance_ratingFROM v$aq aq, all_queues qWHERE aq.qid = q.qidAND (aq.waiting > 0 OR aq.ready > 0 OR aq.expired > 0);
Common Use Cases
Section titled “Common Use Cases”-
Queue Monitoring
- Monitor message backlogs
- Identify processing bottlenecks
- Track queue performance trends
-
Troubleshooting
- Find queues with high expired counts
- Identify stalled message processing
- Debug application queue issues
-
Capacity Planning
- Monitor queue growth patterns
- Plan consumer scaling
- Optimize queue configurations
Queue Health Indicators
Section titled “Queue Health Indicators”Healthy Queue Patterns
Section titled “Healthy Queue Patterns”- Steady Ready Count: Messages processed as they arrive
- Low Wait Times: Quick message processing
- Minimal Expired: Good retention settings
- Balanced Load: No single queue dominating
Problem Indicators
Section titled “Problem Indicators”- Growing Ready Count: Insufficient consumers
- High Expired Count: Messages timing out
- Long Average Wait: Processing delays
- Zero Activity: Stalled consumers
Filtering Strategies
Section titled “Filtering Strategies”By Owner
Section titled “By Owner”-- Monitor specific application queuesEnter value for owner: ORDERAPPEnter value for name: %
By Queue Pattern
Section titled “By Queue Pattern”-- Monitor notification queuesEnter value for owner: %Enter value for name: %NOTIFICATION%
By Table Pattern
Section titled “By Table Pattern”-- Find queues using specific table namingSELECT * FROM all_queuesWHERE queue_table LIKE '%ORDER%';
Performance Troubleshooting
Section titled “Performance Troubleshooting”High Message Counts
Section titled “High Message Counts”Symptoms: Large ready or waiting counts Causes:
- Insufficient consumers
- Slow message processing
- Consumer failures
Solutions:
- Add more consumers
- Optimize message processing
- Check consumer error logs
High Expired Counts
Section titled “High Expired Counts”Symptoms: Many expired messages Causes:
- Short expiration times
- Processing delays
- Consumer downtime
Solutions:
- Increase retention time
- Improve processing speed
- Add consumer redundancy
Long Wait Times
Section titled “Long Wait Times”Symptoms: High average_wait values Causes:
- Network issues
- Database performance
- Lock contention
Solutions:
- Check network connectivity
- Tune database performance
- Optimize queue operations
Queue Table Analysis
Section titled “Queue Table Analysis”Message Details
Section titled “Message Details”-- Examine messages in queue tableSELECT msg_state, msg_priority, user_data, enq_time, deq_timeFROM aq$queue_table_nameWHERE q_name = 'QUEUE_NAME'ORDER BY enq_time DESC;
Queue Statistics
Section titled “Queue Statistics”-- Get detailed queue statisticsSELECT queue_schema, queue_name, num_msgs, spill_msgs, cnum_msgs, dequeue_enabled, enqueue_enabledFROM dba_queue_tablesWHERE owner = 'SCOTT';
Administrative Tasks
Section titled “Administrative Tasks”Queue Management
Section titled “Queue Management”-- Enable/disable queue operationsBEGIN DBMS_AQADM.STOP_QUEUE( queue_name => 'SCOTT.ORDER_QUEUE' );END;/
BEGIN DBMS_AQADM.START_QUEUE( queue_name => 'SCOTT.ORDER_QUEUE' );END;/
Queue Purging
Section titled “Queue Purging”-- Purge expired messagesBEGIN DBMS_AQADM.PURGE_QUEUE_TABLE( queue_table => 'SCOTT.ORDER_QT', purge_condition => 'tab.q_name = ''ORDER_QUEUE'' AND tab.msg_state = ''EXPIRED''' );END;/
Monitoring Automation
Section titled “Monitoring Automation”Create Monitoring View
Section titled “Create Monitoring View”CREATE OR REPLACE VIEW queue_health_monitor ASSELECT owner, name, queue_table, waiting + ready + expired total_messages, CASE WHEN expired > (waiting + ready) * 0.1 THEN 'HIGH_EXPIRED' WHEN ready > 1000 THEN 'HIGH_BACKLOG' WHEN average_wait > 100 THEN 'SLOW_PROCESSING' ELSE 'HEALTHY' END health_status, waiting, ready, expired, average_waitFROM v$aq aq, all_queues qWHERE aq.qid = q.qid;
Alert Generation
Section titled “Alert Generation”-- Identify problem queuesSELECT * FROM queue_health_monitorWHERE health_status != 'HEALTHY'ORDER BY total_messages DESC;
Integration with Applications
Section titled “Integration with Applications”Consumer Monitoring
Section titled “Consumer Monitoring”-- Check active consumersSELECT client_name, consumer_name, address, protocol, last_error_msg, last_error_dateFROM dba_queue_subscribersWHERE queue_name = 'ORDER_QUEUE';
Error Analysis
Section titled “Error Analysis”-- Find processing errorsSELECT exception_queue_owner, exception_queue, original_queue_owner, original_queue, COUNT(*) error_countFROM dba_queue_tables qt, aq$qt.aq$_qt_e eWHERE qt.queue_table = 'ORDER_QT'GROUP BY exception_queue_owner, exception_queue, original_queue_owner, original_queue;
RAC Considerations
Section titled “RAC Considerations”Cross-Instance Queues
Section titled “Cross-Instance Queues”For RAC environments, consider using GV$AQ:
-- Monitor across all instancesSELECT inst_id, owner, name, waiting, ready, expiredFROM ( SELECT g.inst_id, d.owner, d.name, g.waiting, g.ready, g.expired FROM gv$aq g, all_queues d WHERE g.qid = d.qid AND (g.waiting > 0 OR g.ready > 0 OR g.expired > 0))ORDER BY inst_id, owner, name;
Best Practices
Section titled “Best Practices”-
Regular Monitoring
- Check queue status hourly during peak times
- Monitor message expiration rates
- Track average wait time trends
-
Proactive Management
- Set up alerts for high backlogs
- Monitor expired message trends
- Plan consumer capacity
-
Performance Optimization
- Tune queue table storage
- Optimize message processing
- Balance consumer workload
Troubleshooting
Section titled “Troubleshooting”No Queues Shown
Section titled “No Queues Shown”- Check if AQ is configured
- Verify queue activity (script filters inactive queues)
- Confirm user privileges
Missing Statistics
Section titled “Missing Statistics”- Restart queue activity to refresh stats
- Check if statistics collection is enabled
- Verify queue configuration
Performance Issues
Section titled “Performance Issues”- Analyze message processing logic
- Check database performance
- Review network connectivity