Performance Tuning in Oracle 10g Part 2 - SAGE Computing Services
Transcript of Performance Tuning in Oracle 10g Part 2 - SAGE Computing Services
www.sagecomputing.com.auwww.sagecomputing.com.au
Performance Tuning in Oracle 10gPerformance Tuning in Oracle 10gPart 2Part 2
Penny Cookson - Managing Director
SAGE Computing ServicesSAGE Computing ServicesCustomised Oracle Training WorkshopsCustomised Oracle Training Workshops
and Consultingand Consultingwww.sagecomputing.com.auwww.sagecomputing.com.au
www.sagecomputing.com.auwww.sagecomputing.com.au
AgendaAgenda
• System Statistics• Using wait events – Tuning I/O• Common tuning problems – examples• Using ADDM
www.sagecomputing.com.auwww.sagecomputing.com.au
System Statistics
www.sagecomputing.com.auwww.sagecomputing.com.au
Cost ModelCost Model
Prior to Oracle 9iNumber of I/OsEstimates of index blocks in memory OPTIMIZER_INDEX_CACHINGEstimates of cost of index scanOPTIMZER_INDEX_COST_ADJ
Oracle 9iI/O plus CPU costing if system statistics gathered
Oracle 10gCPU and I/OSystem statistics or defaults
www.sagecomputing.com.auwww.sagecomputing.com.au
System StatisticsSystem Statistics
CPUSPEEDNW Millions of CPU cycles per second
IOSEEKTIM Noworkload estimate of IO seek time
IOTFRSPEED Noworkload estimate of IO transfer time
SREADTIM Single block read time (milliseconds)
MREADTIM Multi block read time (milliseconds)
CPUSPEED Millions of CPU cycles per second
MBRC Average number of blocks in multiblock read
MAXTHR Maximum I/O throughput (parallel)
SLAVETHR Average slave I/O throughput (parallel)
www.sagecomputing.com.auwww.sagecomputing.com.au
Gathering System StatisticsGathering System Statistics
Workload statisticsCPUSPEEDNW, IOSEEKTIME, IOTFRSPEED
Noworkload statisticsSREADTIME, MREADTIME, CPUSPEED, MBRC, SLAVETHR
Optimiser uses workload statistics if availableGather at times of representative workload
Daytime OLTP setNightime batch / reporting set
Import as required
www.sagecomputing.com.auwww.sagecomputing.com.au
System Statistics System Statistics InformationInformation
SYS.AUX_STATS$PNAME = statistic name or informationInformation
STATUS AUTOGATHERINGCOMPLETEDBADSTATS
DSTART Start date/time DSTOP End date/time
www.sagecomputing.com.auwww.sagecomputing.com.au
Gathering System StatisticsGathering System Statistics
DBMS_STATS.CREATE_STAT_TABLE ('SYS','OLTP_SYSSTAT','STAT_TS');
DBMS_STATS.GATHER_SYSTEM_STATS( gathering_mode => 'INTERVAL', interval => 2, stattab => 'OLTP_SYSSTAT', statid => 'OLTP');
DBMS_STATS. DELETE_SYSTEM_STATS;
DBMS_STATS.IMPORT_SYSTEM_STATS( stattab => 'OLTP_SYSSTAT', statid => 'OLTP', statown=> 'SYS');
www.sagecomputing.com.auwww.sagecomputing.com.au
Effect of CPU CostingEffect of CPU Costing
QUANTITY COUNT(*)---------- ----------
1 128448820 14271235 7136240 71358
COST COUNT(*)---------- ----------
0 99899725 99120 71356360 71349420 71353735 713573000 713553360 713544000 7135011200 71350SELECT count(comments)
FROM bookings_largeWHERE quantity = 1AND cost = 25
www.sagecomputing.com.auwww.sagecomputing.com.au
With CPU CostingWith CPU Costing
EXPLAIN PLAN FORSELECT count(comments)FROM bookings_largeWHERE quantity = 1AND cost = 25
-------------------------------------------------------------------------------------| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |-------------------------------------------------------------------------------------| 0 | SELECT STATEMENT | | 1 | 15 | 1982 (6)| 00:00:12 || 1 | SORT AGGREGATE | | 1 | 15 | | ||* 2 | TABLE ACCESS FULL| BOOKINGS_LARGE | 43494 | 637K| 1982 (6)| 00:00:12 |-------------------------------------------------------------------------------------
Predicate Information (identified by operation id):---------------------------------------------------
2 - filter("COST"=25 AND "QUANTITY"=1)
www.sagecomputing.com.auwww.sagecomputing.com.au
Without CPU CostingWithout CPU Costing
EXPLAIN PLAN FORSELECT --+ NO_CPU_COSTINGcount(comments)FROM bookings_largeWHERE quantity = 1AND cost = 25
---------------------------------------------------------------------| Id | Operation | Name | Rows | Bytes | Cost |---------------------------------------------------------------------| 0 | SELECT STATEMENT | | 1 | 15 | 952 || 1 | SORT AGGREGATE | | 1 | 15 | ||* 2 | TABLE ACCESS FULL| BOOKINGS_LARGE | 43494 | 637K| 952 |---------------------------------------------------------------------
Predicate Information (identified by operation id):---------------------------------------------------
2 - filter("QUANTITY"=1 AND "COST"=25)
Note-----
- cpu costing is off (consider enabling it)
www.sagecomputing.com.auwww.sagecomputing.com.au
Using wait events – Tuning I/O
www.sagecomputing.com.auwww.sagecomputing.com.au
Wait Event ClassesWait Event Classes
SELECT distinct wait_class#, wait_classFROM v$event_nameORDER BY wait_class#
WAIT_CLASS# WAIT_CLASS----------- ----------------------------------
0 Other1 Application2 Configuration3 Administrative4 Concurrency5 Commit6 Idle7 Network8 User I/O9 System I/O
10 Scheduler11 Cluster
www.sagecomputing.com.auwww.sagecomputing.com.au
Wait Event ClassesWait Event Classes
Application Includes locking problemsConfiguration Database configuration problemsAdministrative Caused by database administrationConcurrency Contention for buffers and latchesCommit log file synchronisationIdle Waiting for something to doNetwork Network delaysUser I/O Disk read / write waits by users,
SMON and MMONSystem I/O Disk read/ write waits by background
process except SMON and MMONScheduler Resource manager waitsCluster RAC waitsOther Other insignificant waits
www.sagecomputing.com.auwww.sagecomputing.com.au
What Class is Causing What Class is Causing WaitsWaits
SELECT wait_class_id, wait_class#, wait_class, total_waits, time_waited
FROM v$system_wait_class
WAIT_CLASS_ID WAIT_CLASS# WAIT_CLASS TOTAL_WAITS TIME_WAITED------------- ----------- ------------------------------ ----------- -----------
1893977003 0 Other 2000 525284217450380 1 Application 320 103290255840 2 Configuration 111 5233875070507 4 Concurrency 765 36553386400367 5 Commit 527 3852723168908 6 Idle 555098 119651782000153315 7 Network 526262 891740759767 8 User I/O 97884 1201984108307767 9 System I/O 8699 6811
www.sagecomputing.com.auwww.sagecomputing.com.au
User I/O EventsUser I/O Events
SELECT nameFROM v$event_nameWHERE wait_class# = 8
NAME---------------------------local write waitbuffer read retryread by other sessiondb file sequential readdb file scattered readdb file single writedb file parallel readdirect path readdirect path read tempdirect path writedirect path write tempBFILE read
www.sagecomputing.com.auwww.sagecomputing.com.au
What Events are Causing What Events are Causing User I/O WaitsUser I/O Waits
System wait events – User I/OSELECT e.event, e.total_waits, e.total_timeouts,
e.time_waited, average_waitFROM v$system_event e, v$event_name nWHERE n.event_id = e.event_idAND n.wait_class# = 8 – User I/O
EVENT TOTAL_WAITS TOTAL_TIMEOUTS TIME_WAITED AVERAGE_WAIT------------------------- ----------- -------------- ----------- ------------read by other session 45432 0 40824 1db file sequential read 49525 0 74044 1db file scattered read 3311 0 5610 2db file single write 8 0 3 0db file parallel read 1 0 1 1direct path read 92 0 34 0direct path read temp 6 0 0 0direct path write 108 0 4 0direct path write temp 35 0 0 0
www.sagecomputing.com.auwww.sagecomputing.com.au
User I/O ClassUser I/O Class
db file sequential readSingle block IOMay be index access
db file scattered readMulti block IOTable full scan or index fast full scanSort operation
db file single writeWriting file headers
BFILE readWaiting for read of external bfile
Direct path read and direct path read tempSort operations written to diskParrallel slaves
www.sagecomputing.com.auwww.sagecomputing.com.au
What Objects are Causing What Objects are Causing Sequential readsSequential reads
SELECT object_name, current_obj#, current_file#,current_block#, wait_time, time_waited
FROM v$active_session_history h, dba_objects oWHERE session_id = 141AND session_serial# = 2AND o.object_id = h.current_obj#AND event = 'db file sequential read'
OBJECT_NAME CURRENT_OBJ# CURRENT_FILE# CURRENT_BLOCK# WAIT_TIME TIME_WAITED--------------- ------------ ------------- -------------- ---------- -----------BK_LG_EVTNO 54674 8 16442 0 2440BK_LG_EVTNO 54674 8 16374 0 180BOOKINGS_LARGE 54577 8 9645 0 20874BOOKINGS_LARGE 54577 8 8904 0 63567BOOKINGS_LARGE 54577 8 12850 0 6029BOOKINGS_LARGE 54577 8 4011 0 13001BK_LG_EVTNO 54674 8 16265 0 14899BK_LG_EVTNO 54674 8 16229 0 173BK_LG_EVTNO 54674 8 16216 0 14479
www.sagecomputing.com.auwww.sagecomputing.com.au
Example Example –– Sequential ReadsSequential Reads
www.sagecomputing.com.auwww.sagecomputing.com.au
www.sagecomputing.com.auwww.sagecomputing.com.au
www.sagecomputing.com.auwww.sagecomputing.com.au
www.sagecomputing.com.auwww.sagecomputing.com.au
www.sagecomputing.com.auwww.sagecomputing.com.au
www.sagecomputing.com.auwww.sagecomputing.com.au
www.sagecomputing.com.auwww.sagecomputing.com.au
www.sagecomputing.com.auwww.sagecomputing.com.au
www.sagecomputing.com.auwww.sagecomputing.com.au
Tuning Tuning –– Sequential ReadsSequential Reads
Abnormally high wait level may be an index that should not be used
For table accessFor nested loop join
CheckStatistics on the index are currentOptimiser mode is not FIRST_ROWSColumn has a histogram if data is skewedThere is not an old SQL*ProfileBind peeking
If all this is OK – tune the SQL
www.sagecomputing.com.auwww.sagecomputing.com.au
Example Example –– Scattered ReadsScattered Reads
DECLAREv_1 VARCHAR2(4) := 'VCR1';v_2 NUMBER;BEGINSELECT count(b.comments)INTO v_2FROM bookings_large bWHERE b.resource_code = v_1;
v_1 := 'PC1';
FOR counter IN 1..20 LOOPSELECT count(b.comments)INTO v_2FROM bookings_large bWHERE b.resource_code = v_1;
END LOOP;END;
www.sagecomputing.com.auwww.sagecomputing.com.au
Skewed data + HistogramSkewed data + Histogram
SELECT resource_code, COUNT(*)FROM bookings_largeGROUP BY resource_code
RESO COUNT(*)---- ----------BRLG 297763BRSM 148879CONF 99255FLPC 99252LNCH 148881PC1 9629TAP1 49626VCR1 489252VCR2 99255
SELECT endpoint_number, endpoint_valueFROM user_histogramsWHERE table_name = 'BOOKINGS_LARGE'AND column_name = 'RESOURCE_CODE'
ENDPOINT_NUMBER ENDPOINT_VALUE-------------- --------------
1198 3.4436E+351760 3.4436E+352124 3.4949E+352456 3.6501E+353040 3.9620E+353079 4.1675E+353279 4.3748E+355173 4.4790E+355554 4.4790E+35
www.sagecomputing.com.auwww.sagecomputing.com.au
www.sagecomputing.com.auwww.sagecomputing.com.au
www.sagecomputing.com.auwww.sagecomputing.com.au
www.sagecomputing.com.auwww.sagecomputing.com.au
www.sagecomputing.com.auwww.sagecomputing.com.au
Tuning Tuning –– Scattered ReadsScattered Reads
Abnormally high levels may be a full scan of large tableCheck
Statistics on the table and indexes are currentSystem statistics are gatheredColumn has a histogram if data is skewedThere is not an old SQL*ProfileBind peeking
If all this is OK – tune the SQL
www.sagecomputing.com.auwww.sagecomputing.com.au
Bind PeekingBind Peeking
Values of bind variable inspected on hard parseSubsequent executions use the same planIf selective value first, subsequent executions may use innapropriate indexIf non selective value first, subsequent executions may full scan Set _optim_peek_user_binds to FALSE
www.sagecomputing.com.auwww.sagecomputing.com.au
Tuning Tuning –– I/OI/O
Minimise I/ODistribute I/OTune sortsTune buffer cacheUse KEEP buffer pool for
small scans on commonly used tables tables with sequential reads and commonly used data
Use RECYCLE buffer pool forrandom access to large tables
www.sagecomputing.com.auwww.sagecomputing.com.au
Common Tuning Problems - examples
www.sagecomputing.com.auwww.sagecomputing.com.au
www.sagecomputing.com.auwww.sagecomputing.com.au
www.sagecomputing.com.auwww.sagecomputing.com.au
www.sagecomputing.com.auwww.sagecomputing.com.au
www.sagecomputing.com.auwww.sagecomputing.com.au
Wait Event Wait Event ––direct path read tempdirect path read temp
Blocks read directly to the user Occurs when sorting performed on diskSort area determined:
By PGA_AGGREGATE targetBy SORT_AREA_SIZE if manual
Default = 20% of SGAIncrease for DSS databases
www.sagecomputing.com.auwww.sagecomputing.com.au
www.sagecomputing.com.auwww.sagecomputing.com.au
Wait Event Wait Event ––buffer busy waitsbuffer busy waits
Wait for a specific buffer that someone else is usingAnother session may be reading the buffer inAnother session may have the block pinned in the bufferIndex hot spotsTable insert hot spots
www.sagecomputing.com.auwww.sagecomputing.com.au
www.sagecomputing.com.auwww.sagecomputing.com.au
www.sagecomputing.com.auwww.sagecomputing.com.au
www.sagecomputing.com.auwww.sagecomputing.com.au
Find the Object Find the Object
SELECT object_name, current_obj#, current_file#, current_block#, wait_time, time_waited
FROM v$active_session_history h, dba_objects oWHERE o.object_id = h.current_obj#AND event = 'buffer busy waits'
OBJECT_NAME CURRENT_OBJ# CURRENT_FILE# CURRENT_BLOCK# WAIT_TIME TIME_WAITED--------------- ------------ ------------- -------------- ---------- -----------BK_LG_EVTNO 54674 8 14477 0 391BK_LG_EVTNO 54674 8 15194 17 0BK_LG_EVTNO 54674 8 15294 1 0BK_LG_EVTNO 54674 8 22947 0 281891BK_LG_EVTNO 54674 8 16774 30 0BK_RES2 54692 8 20465 0 1022386BK_RES2 54692 8 21655 0 961881BK_RES2 54692 8 21655 0 961218BK_RES2 54692 8 21741 0 475933BK_RES2 54692 8 21741 0 475356BOOKINGS_LARGE 54577 8 20636 3 0BOOKINGS_LARGE 54577 8 20746 0 1027986BOOKINGS_LARGE 54577 8 20844 44 0BOOKLG_PK 54578 8 19995 0 269731BOOKLG_PK 54578 8 19995 0 269694
www.sagecomputing.com.auwww.sagecomputing.com.au
Wait Event Wait Event ––buffer busy waitsbuffer busy waits
Automatic segment storage managementFreelists if not ASSMReverse key indexesHash Partitioning Use automatic undo management
www.sagecomputing.com.auwww.sagecomputing.com.au
Wait Event Wait Event –– log buffer log buffer spacespace
Wait to write to the log buffer I/O to the log file is not keeping up with write requests to the bufferMove log files to faster drivesIncrease log buffer
www.sagecomputing.com.auwww.sagecomputing.com.au
www.sagecomputing.com.auwww.sagecomputing.com.au
www.sagecomputing.com.auwww.sagecomputing.com.au
Wait Event Wait Event –– log file synclog file sync
Wait class = CommitWrite redo information from log buffer to redo log filesOn user commitReduce commit frequencyMove redo log files to faster disk
www.sagecomputing.com.auwww.sagecomputing.com.au
Wait Event Wait Event –– log file parallel log file parallel writewrite
Wait class = System I/OLGWR waiting to write to redo log filesMay occur in conjunction with log file synclog file syncMove redo log files to faster diskDon’t overdo number of redo group membersReduce amount of redo
No logging Global temporary tables
www.sagecomputing.com.auwww.sagecomputing.com.au
Wait Event Wait Event –– log file switchlog file switch
(archiving needed)Required redo not finished being archivedCheck alert logIncrease archiver processes
(checkpoint incomplete)Required log needed to complete checkpointCheck sufficient redo log files
(clearing log file)Required logfile waiting to be cleared
(completion)Normal log file switch not complete
www.sagecomputing.com.auwww.sagecomputing.com.au
www.sagecomputing.com.auwww.sagecomputing.com.au
Wait Event Wait Event ––library cache latch waitslibrary cache latch waits
Library cache latch taken to add new statement Reduce hard parsingUse bind variablesUse cursor_sharing = SIMILARConsider increasing the SGA
www.sagecomputing.com.auwww.sagecomputing.com.au
Wait Event Wait Event ––free buffer waitfree buffer wait
DBWR not keeping up Look at wait events for DBWROptimise I/OBuffer cache too bigBuffer cache too small
www.sagecomputing.com.auwww.sagecomputing.com.au
Background Processes Background Processes
SELECT program, serial#, sidFROM v$sessionWHERE program like 'ORACLE.EXE%'
PROGRAM SERIAL# SID------------------------------ ---------- ----------ORACLE.EXE (q002) 2208 128ORACLE.EXE (MMNL) 1 156ORACLE.EXE (MMON) 1 158ORACLE.EXE (QMNC) 3 160ORACLE.EXE (CJQ0) 1 163ORACLE.EXE (RECO) 1 164ORACLE.EXE (SMON) 1 165ORACLE.EXE (CKPT) 1 166ORACLE.EXE (LGWR) 1 167ORACLE.EXE (DBW0) 1 168ORACLE.EXE (MMAN) 1 169ORACLE.EXE (PMON) 1 170
www.sagecomputing.com.auwww.sagecomputing.com.au
Background Process Background Process –– Wait Wait EventsEvents
SELECT event, wait_time, time_waitedFROM v$active_session_historyWHERE session_id = 168AND session_serial# = 1
EVENT WAIT_TIME TIME_WAITED------------------------------ ---------- -----------rdbms ipc message 3078109 0db file parallel write 0 1074rdbms ipc message 3077900 0rdbms ipc message 3077814 0db file parallel write 0 68898db file parallel write 0 2664db file parallel write 0 62162rdbms ipc message 3077741 0rdbms ipc message 3077854 0db file parallel write 0 5607db file parallel write 0 166db file parallel write 1596 0db file parallel write 0 161control file sequential read 222 0control file sequential read 0 20607control file sequential read 0 46275control file sequential read 0 20838
www.sagecomputing.com.auwww.sagecomputing.com.au
Using ADDM
www.sagecomputing.com.auwww.sagecomputing.com.au
ADDMADDM
Automatic Database Diagnostic MonitorPerforms self diagnosisRun for each AWR snapshot (hourly)Aim is to reduce DB timeIdentify bottlenecksMake recommendations
ImpactBenefitAction and rationale
STATISTICS_LEVEL TYPICAL or ALL
www.sagecomputing.com.auwww.sagecomputing.com.au
ADDM ADDM
Hot objectsHigh resource SQL / PL/SQL / JavaMemory structuresI/O PerformanceLog files / archiving / checkpointsContentionRAC issuesDocuments wait classes not causing problems
www.sagecomputing.com.auwww.sagecomputing.com.au
ADDM RecommendationsADDM Recommendations
Tune the SQLApplication changes
Use of bind variablesSequence caching
Schema changesPartitioning
ConfigurationChanges to init parametersChanges to file sizes
Hardware changes
www.sagecomputing.com.auwww.sagecomputing.com.au
Accessed through Enterprise Accessed through Enterprise ManagerManager
View ADDM output for up to 7 days
www.sagecomputing.com.auwww.sagecomputing.com.au
Accessed through Enterprise Accessed through Enterprise ManagerManager
View ADDM output for a snapshot
www.sagecomputing.com.auwww.sagecomputing.com.au
ADDM AnalysisADDM Analysis
Perform analysis between two snapshotsNo shutdown between snapshots
Run from Enterprise ManagerRun using @$ORACLE_HOME/rdbms/admin/addmrpt.sqlRun using DBMS_ADVISORProduces report
TextHTML
www.sagecomputing.com.auwww.sagecomputing.com.au
ADDM AnalysisADDM Analysis
Results in the following viewsDBA_ADVISOR_TASKSDBA_ADVISOR_LOGDBA_ADVISOR_RECOMMENDATIONSDBA_ADVISOR_FINDINGS
www.sagecomputing.com.auwww.sagecomputing.com.au
DBA_ADVISOR_FINDINGSDBA_ADVISOR_FINDINGS
Top 10 findingsSELECT type, messageFROM (SELECT type, message, count(*) num
FROM dba_advisor_findingsGROUP BY type, messageORDER BY num desc)
WHERE rownum < 10
TYPE MESSAGE ------------ ---------------------------------------------------------------------------------------SYMPTOM Wait class "User I/O" was consuming significant database time. INFORMATION There was no significant database activity to run the ADDM. PROBLEM SQL statements consuming significant database time were found. PROBLEM Wait event "class slave wait" in wait class "Other" was consuming significant database SYMPTOM Wait class "Other" was consuming significant database time. PROBLEM PL/SQL execution consumed significant database time. SYMPTOM The throughput of the I/O subsystem was significantly lower than expected. PROBLEM Individual database segments responsible for significant user I/O wait were found. PROBLEM Time spent on the CPU by the instance was responsible for a substantial part of databas
www.sagecomputing.com.auwww.sagecomputing.com.au
www.sagecomputing.com.auwww.sagecomputing.com.au
Thank You For Your Attention
Any Questions?
SAGE Computing ServicesSAGE Computing ServicesCustomised Oracle Training WorkshopsCustomised Oracle Training Workshops
and Consultingand Consultingwww.sagecomputing.com.auwww.sagecomputing.com.au