Oracle Time Model Queries: System and Session Performance Monitoring
Oracle Time Model Queries: System and Session Performance Monitoring
Purpose
Oracle time model queries provide database administrators with powerful tools to measure and analyze where time is spent within the database system. These queries use two essential dynamic performance views that track accumulated time for various database operations in microseconds. The primary purpose is to identify performance bottlenecks by examining how much time the database spends on different operations, helping administrators prioritize tuning efforts effectively. Time model statistics measure DB time, which represents the total time spent in database calls by foreground sessions and serves as an indicator of total instance workload. By analyzing these metrics, database professionals can determine whether the system is constrained by CPU resources or waiting for other operations to complete.
Breakdown of Code
Query 1: System Time Model
1set lines 100 pages 999
2select stat_name
3,value
4from v$sys_time_model
5order by value desc
6/
This query retrieves system-wide accumulated times for various database operations. The v$sys_time_model view displays instance-level statistics that are cumulative since database startup. The query formats output to 100 characters per line and 999 pages, selects the statistic name and its value, then orders results by value in descending order to show which operations consume the most time.
Query 2: Session Time Model
1set lines 100 pages 999
2select stat_name
3,value
4from v$sess_time_model
5where sid = '&sid'
6order by value desc
7/
This query retrieves session-level accumulated times for a specific session identifier. The v$sess_time_model view provides the same statistics as the system view but filtered to a single session, allowing administrators to drill down into specific session behavior. The query uses a substitution variable (&sid) to specify which session to analyze.
Key Points
Time values in both views are stored as 8-byte integers in microseconds and can hold approximately 580,000 years of data before wrapping. All time statistics are cumulative, meaning they accumulate from instance startup for system views or from session start for session views. Background process time is excluded from statistics unless the statistic specifically tracks background processes.
The most important time model statistic is DB time, which equals DB CPU plus non-idle wait time. This formula helps identify whether sessions are spending time actively working on CPU or waiting for resources. Timed operations buffer at most 5 seconds of time data, meaning long-running operations may have up to 5 seconds of unaccounted time.
Insights
Time model statistics provide a common currency for Oracle performance analysis by expressing all metrics in time units. This standardization allows database administrators to compare different types of operations on an equal basis when prioritizing tuning efforts. The hierarchical relationship between statistics forms trees where child statistics are contained within parent statistics.
Querying these views helps identify sessions with high wait percentages, indicating they spend more time waiting than executing on CPU. For system-level analysis, ordering by value descending immediately reveals which operations consume the most database time. Session-level analysis enables targeted troubleshooting of specific application connections or user sessions experiencing performance issues.
The time model method for performance tuning focuses on removing excess DB time by identifying the largest potential improvements within scope. This approach proves more effective than randomly adjusting system parameters without understanding where time is actually spent.
How Time Model Statistics Work
Time model statistics form two distinct trees that show containment relationships between parent and child statistics. The first tree starts with background elapsed time, while the second tree begins with DB time. Under DB time, major categories include DB CPU, connection management, sequence load, SQL execute, parse time, PL/SQL execution, and Java execution elapsed time.
Important child statistics under parse time include hard parse elapsed time, which further breaks down into sharing criteria and bind mismatch categories. These granular breakdowns help administrators understand not just that parsing is slow, but specifically why parsing takes time.
Parse time elapsed includes both soft and hard parse time, while SQL execute elapsed time for select statements includes the time spent fetching query results. Understanding these inclusions prevents misinterpretation when analyzing performance data.
Using Time Model for Performance Diagnosis
Administrators should calculate the difference between cumulative values at the start and end of a period when analyzing performance. This delta approach provides meaningful insights into performance during specific time windows rather than since database startup.
To identify sessions spending excessive time waiting, calculate wait percentage by subtracting DB CPU from DB time and dividing by DB time. Sessions with wait percentages above 90% are spending most of their time blocked rather than executing. These sessions become prime candidates for further investigation using views like v$session, v$active_session_history, or v$session_wait.
The DB time method follows a systematic process: identify the performance issue, scope it, set goals, capture data, investigate DB time distribution, modify the system for largest gain, and evaluate against goals. This iterative approach ensures tuning efforts focus on areas with maximum impact.
Benefits of Time Model Queries
Time model queries provide direction when facing unclear performance problems by showing where the database spends its time across the three resources it consumes: disk, CPU, and memory. These queries eliminate guesswork that previously required accumulating statistics across multiple V$ views and operating system commands.
The views support both system-wide and session-specific analysis, enabling administrators to work at the appropriate scope for each problem. System-wide views help identify overall instance workload and resource constraints, while session views pinpoint specific application or user issues.
AWR reports include time model statistics in a dedicated section, making historical analysis possible without running live queries. This historical perspective helps identify trends and validate whether tuning changes produced desired improvements.
References
Oracle Official Documentation - V$SYS_TIME_MODEL - Complete reference for the system-wide time model view including column descriptions and statistic definitions.
Oracle Official Documentation - V$SESS_TIME_MODEL - Detailed documentation for session-level time model statistics with relationship trees and statistic explanations.
Oracle Time Model Statistics Guide - Comprehensive overview of time model statistics and their role in measuring database performance.
Measuring Database Performance - Oracle Documentation - Official guide covering database statistics, time model statistics, and performance measurement techniques.
Modeling Oracle Time - Database Journal - Tutorial explaining Oracle's time model and how to use V$SYS_TIME_MODEL and V$SESS_TIME_MODEL for performance analysis.
What Is Oracle DB Time, DB CPU, and Non-Idle Wait Time - Detailed explanation of DB time calculation and the relationship between DB CPU and wait time.
Identify Top Waiting Sessions Using Time Model Stats - Practical guide with SQL examples for identifying sessions with high wait percentages.
DB Time Performance Tuning: Theory and Practice - Comprehensive presentation covering the DB time method for performance tuning and practical implementation.