Copyright 2008, Oracle. All rights reserved. 2 - 2 Objectives After completing this lesson, you should be able to do the following: View the top wait events to determine the highest wait View the time model to diagnose performance issues Use dynamic performance views to view statistics and wait events Use Enterprise Manager Monitoring Identify the key tuning components of the alert logs Identify the key tuning components of user trace files Copyright 2008, Oracle. All rights reserved. 2 - 3 Performance Tuning Diagnostics Diagnostic tools gather and format the following types of performance data: Cumulative statistics: Wait events with time information Time model Metrics: Statistic rates Sampled statistics: Active Session History Statistics by session Statistics by SQL Statistics by service Other dimensions Copyright 2008, Oracle. All rights reserved. 2 - 4 Performance Tuning Tools Available tools: Basic: Time model Top wait events Dynamic performance views and tables Alert log Trace files Enterprise Manager pages Add-in: Statspack Options: Diagnostics pack Tuning pack Copyright 2008, Oracle. All rights reserved. 2 - 5 Tuning Objectives The objectives of tuning are: Minimizing response time Increasing throughput Increasing load capabilities Decreasing recovery time Copyright 2008, Oracle. All rights reserved. 2 - 6 Top Wait Events Copyright 2008, Oracle. All rights reserved. 2 - 7 DB Time DB Time =
DB Wait Time +
DB CPU Time Copyright 2008, Oracle. All rights reserved. 2 - 8 CPU and Wait Time Tuning Dimensions Scalable application Possibly needs SQL tuning Needs instance/RAC tuning CPU time Wait time No gain achieved by adding CPUs/nodes DB time = DB CPU time + DB wait time Copyright 2008, Oracle. All rights reserved. 2 - 9 Time Model: Overview The time model is a set of statistics that give an overview of where time is spent inside the Oracle database. All statistics use the same dimension: time. The statistics are accessible through: V$SYS_TIME_MODEL V$SESS_TIME_MODEL DB time represents the total time spent in database calls. A tuning goal is to reduce DB time. Using DB time, you can gauge the performance impact of any entity of the database. SQL Parse DB time Copyright 2008, Oracle. All rights reserved. 2 - 10 Time Model Statistics Hierarchy Failed parse (out of shared memory) elapsed time DB time DB CPU Connection management call elapsed time Sequence load elapsed time SQL execute elapsed time Parse time elapsed Hard parse elapsed time Hard parse (sharing criteria) elapsed time Hard parse (bind mismatch) elapsed time Failed parse elapsed time PL/SQL execution elapsed time Inbound PL/SQL RPC elapsed time PL/SQL compilation elapsed time Java execution elapsed time Repeated bind elapsed time Background elapsed time Background CPU time RMAN CPU time (backup/restore) Copyright 2008, Oracle. All rights reserved. 2 - 12 Time Model Example Copyright 2008, Oracle. All rights reserved. 2 - 13 Dynamic Performance Views Dynamic performance views provide access to information about changing states and conditions in the instance. Session data Wait events Memory allocations Running SQL UNDO usage Open cursors Redo log usage And so on Oracle instance Copyright 2008, Oracle. All rights reserved. 2 - 14 Dynamic Performance Views: Usage Examples SQL> SELECT sql_text, executions 2 FROM v$sqlstats 3 WHERE cpu_time > 200000; SQL> SELECT * FROM v$session 2 WHERE machine = 'EDRSR9P1' and 3 logon_time > SYSDATE - 1; SQL> SELECT sid, ctime 2 FROM v$lock WHERE block > 0; a b c Copyright 2008, Oracle. All rights reserved. 2 - 15 Dynamic Performance Views: Considerations These views are owned by SYS. Different views are available at different times: The instance has been started. The database is mounted. The database is open. You can query V$FIXED_TABLE to see all the view names. These views are often referred to as v-dollar views. Read consistency is not guaranteed on these views because the data is dynamic. Copyright 2008, Oracle. All rights reserved. 2 - 16 Statistic Levels STATISTICS_LEVEL BASIC TYPICAL ALL Recommended default value Additional statistics for manual SQL diagnostics Disable all self-tuning capabilities V$STATISTICS_LEVEL Copyright 2008, Oracle. All rights reserved. 2 - 18 Statistics and Wait Events Statistics Wait events Reports Dynamic performance views Copyright 2008, Oracle. All rights reserved. 2 - 19 System Statistic Classes Cache Debug RAC SQL Redo User Enqueue OS V$SYSSTAT V$SESSTAT V$STATNAME System statistic classes Copyright 2008, Oracle. All rights reserved. 2 - 20 Displaying Statistics Statistics are collected for: Sessions All sessions V$SESSTAT Current session V$MYSTAT Services V$SERVICE_STATS System V$SYSSTAT Copyright 2008, Oracle. All rights reserved. 2 - 22 Displaying SGA Statistics NAME BYTES RES -------------------------------- ---------- --- Fixed SGA Size 1303132 No Redo Buffers 17780736 No Buffer Cache Size 50331648 Yes Shared Pool Size 142606336 Yes Large Pool Size 4194304 Yes Java Pool Size 12582912 Yes Streams Pool Size 0 Yes Shared IO Pool Size 0 Yes Granule Size 4194304 No Maximum SGA Size 836976640 No Startup overhead in Shared Pool 41943040 No Free SGA Memory Available 608174080 SQL> SELECT * FROM V$SGAINFO; Copyright 2008, Oracle. All rights reserved. 2 - 23 Wait Events A collection of wait events provides information about the sessions that had to wait or must wait for different reasons. These events are listed in the V$EVENT_NAME view, which has the following columns: EVENT# NAME PARAMETER1 PARAMETER2 PARAMETER3 Wait Copyright 2008, Oracle. All rights reserved. 2 - 24 Using the V$EVENT_NAME View NAME PARAMETER1 PARAMETER2 PARAMETER3 ------------------------------- ---------- ---------- ---------- PL/SQL lock timer duration alter system set mts_dispatcher waited buffer busy waits file# block# id library cache pin handle addr pin address 0*mode+name log buffer space log file switch (checkpoint incomplete) transaction undo seg# wrap# count ... 961 rows selected. SQL> SELECT name, parameter1, parameter2, parameter3 2 FROM v$event_name; Copyright 2008, Oracle. All rights reserved. 2 - 25 Wait Classes Scheduler Cluster Configuration Commit Application Administrative Network User I/O Concurrency System I/O Other Idle Background processes I/O Foreground processes I/O DBA commands Should be rare Inadequate database/ instance configuration Resource manager RAC resources User application code Inactive sessions Network messaging log file sync Internal database resources V$SESSION_WAIT_CLASS V$SERVICE_WAIT_CLASS V$SYSTEM_WAIT_CLASS V$EVENT_NAME Wait classes Copyright 2008, Oracle. All rights reserved. 2 - 26 Displaying Wait Event Statistics Wait event statistics levels: System Service Session Wait event statistics columns vary by view. V$SERVICE_EVENT V$SYSTEM_EVENT V$SESSION_EVENT EVENT X X X TOTAL_WAITS X X X TOTAL TIMEOUTS X X X TIME_WAITED X X X AVERAGE_WAIT X X X TIME_WAITED_MICRO X X X EVENT_ID X X X TOTAL_WAIT_FG X TOTAL_TIMEOUTS_FG X TIME_WAITED_FG X AVERAGE_WAIT_FG X TIME_WAITED_MICRO_FG X SID X SERVICE_NAME X SERVICE_NAME_HASH X WAIT_CLASS_ID X X WAIT_CLASS# X X WAIT_CLASS X X Copyright 2008, Oracle. All rights reserved. 2 - 28 Commonly Observed Wait Events Wait Event Area Buffer busy waits Buffer cache, DBWR Free buffer waits Buffer cache, DBWR, I/O Db file scattered read, Db file sequential read I/O, SQL Tuning Enqueue waits (enq:) Locks Library cache waits Latches Log buffer space Log buffer I/O Log file sync Over-commit, I/O Copyright 2008, Oracle. All rights reserved. 2 - 29 Using the V$SESSION_WAIT View SID SEQ# EVENT WAIT STATE TIME --- - -- ---- -------------------------------- ------- 1 1284 pmon timer 0 WAITING 2 1697 rdbms ipc message 0 WAITING 3 183 rdbms ipc message 0 WAITING 4 4688 rdbms ipc message 0 WAITING 5 114 smon timer 0 WAITING 6 14 SQL*Net message from client -1 WAITED SHORT TIME SQL> SELECT sid, seq#, event, wait_time, state 2 FROM v$session_wait; Copyright 2008, Oracle. All rights reserved. 2 - 31 Precision of System Statistics Views that include microsecond timings: V$SESSION_WAIT, V$SYSTEM_EVENT, V$SERVICE_EVENT, V$SESSION_EVENT (TIME_WAITED_MICRO column) V$SQL, V$SQLAREA (CPU_TIME, ELAPSED_TIME columns) V$LATCH, V$LATCH_PARENT, V$LATCH_CHILDREN (WAIT_TIME column) V$SQL_WORKAREA, V$SQL_WORKAREA_ACTIVE (ACTIVE_TIME column) Views that include millisecond timings: V$ENQUEUE_STAT (CUM_WAIT_TIME column) Copyright 2008, Oracle. All rights reserved. 2 - 32 Using Features of the Packs SQL traces Statspack System statistics Wait model Time model OS statistics Metrics Service statistics Histograms Optimizer statistics SQL statistics Monitoring and tuning with packs Monitoring and tuning without packs Database Configuration Management Pack Database and Host Configuration Deployments Patch Database and View Patch Cache Patch staging Clone Database Clone Oracle Home Search configuration Compare configuration Policies Database Diagnostics Pack Automatic Workload Repository Automatic Database Diagnostic Monitor (ADDM) Active Session History (ASH) Performance monitoring (database and host) Event notifications: notification methods, rules, and schedules Event history and metric history (database and host) Blackouts Dynamic metric baselines Monitoring templates Database Tuning Pack SQL Access Advisor SQL Tuning Advisor Automatic SQL Tuning SQL Tuning Sets Automatic Plan Evolution of SQL Plan Management SQL Monitoring Reorganize objects Copyright 2008, Oracle. All rights reserved. 2 - 34 Accessing the Database Home Page https://host name:1158/em Copyright 2008, Oracle. All rights reserved. 2 - 35 Enterprise Manager Performance Pages Copyright 2008, Oracle. All rights reserved. 2 - 37 Viewing the Alert Log Database Home page > Related Links region > Alert Log Contents Copyright 2008, Oracle. All rights reserved. 2 - 38 Using Alert Log Information as an Aid in Tuning The alert log file contains the following information that can be used to aid in tuning the database: Time to perform archiving Instance recovery start and complete times Deadlock and timeout errors Incomplete checkpoints Checkpoint start and end times Copyright 2008, Oracle. All rights reserved. 2 - 40 User Trace Files Server-process tracing can be enabled or disabled at the session or instance level. A user trace file contains statistics for traced SQL statements in that session. User trace files are created on a per server process basis. User trace files can also be created by: Performing a BACKUP CONTROL FILE TO TRACE Process errors Copyright 2008, Oracle. All rights reserved. 2 - 41 Background Processes Trace Files The Oracle database server dumps information about errors detected by any background process into trace files. Oracle Support uses these trace files to diagnose and troubleshoot. These files do not usually contain tuning information. Copyright 2008, Oracle. All rights reserved. 2 - 42 Summary In this lesson, you should have learned how to: View the top wait events to determine highest wait View the time model to diagnose performance issues Use dynamic performance views to view statistics and wait events Use Enterprise Manager Monitoring Identify the key tuning components of the alert logs Identify the key tuning components of user trace files Copyright 2008, Oracle. All rights reserved. 2 - 43 Practice 2 Overview: Using Basic Tools This practice covers the following topics: View the top waits events and the time model Use the alert log information for tuning View system statistics View wait events