blog.tanelpoder.com 1GettingtheMostOutofASH©TanelPoder
GettingtheMostOutofOracle’sActiveSessionHistory,
TimeModelandWaitEvents
TanelPoder
blog.tanelpoder.com 2GettingtheMostOutofASH©TanelPoder
Intro:Aboutme
• TanelPõder• OracleDatabasePerformancegeek(18+years)• ExadataPerformancegeek• LinuxPerformancegeek• HadoopPerformancegeek
• CEO&co-founder:
ExpertOracleExadatabook
(2nd editionisoutnow!)
Instantpromotion
blog.tanelpoder.com 3GettingtheMostOutofASH©TanelPoder
“Thedatabaseisslow!”
1. Everyonecomplains2. Systemmonitoringtoolsshowacleardifference
Any“Top5-Waitevents”or“TopSQL”toolshouldbeenough
blog.tanelpoder.com 4GettingtheMostOutofASH©TanelPoder
“Thedatabaseisslow”?
1. Onlyoneuserorafewuserscomplain• Whyhasn’tmybatchjobcompleted?
2. Systemmonitoringdoesnotshowanyvisibledifference• Youmightbetemptedtocomparetoday8amto“lastFriday”8am
Youshouldmeasureyourslowbatchjob
only!!!
blog.tanelpoder.com 5GettingtheMostOutofASH©TanelPoder
Measuring SQL execution activity over time – V$SQLSTATS?
SELECTA
SELECTX
idle SELECTB UPDATEC
Time
SID 10
SID 11
SID 12
idle idle
SELECTY INSERTZidle
SELECTN SELECTN UPDATEKSELECTN idle SELECTN SEL
SELECTA idle SELECTB UPDATECidle idle
SELECTAidle UPDATEC idleidle COMMIT
SID 13
SID 14
SID 15
V$SQL, V$SQLSTATS, Statspack/AWR Top SQL reports measure SQL performance, not sessions’ performance
Instance-level detail (not session-level)SQL statement level breakdown
blog.tanelpoder.com 6GettingtheMostOutofASH©TanelPoder
Measuring session activity details over time – SQL trace
SELECTA
SELECTX
idle SELECTB UPDATEC
Time
SID 10
SID 11
SID 12
idle idle
SELECTY INSERTZidle
SELECTN SELECTN UPDATEKSELECTN idle SELECTN SEL
SELECTA idle SELECTB UPDATECidle idle
SELECTAidle UPDATEC idleidle COMMIT
SID 13
SID 14
SID 15
Session-level detailBreakdown by SQL Statements +Breakdown by Wait EventsBasic performance counters (logical IOs, parses etc)Full chronological detail of session activityNo instance-wide coverage in realistic cases
blog.tanelpoder.com 7GettingtheMostOutofASH©TanelPoder
WhatisOracleDatabaseactivityabout?
1. Abunchofsessions• YouneedasessionfordoinganythinginOracle
1. Applicationsusethesesessionstoexecute(PL)SQLcursors• Mostapplication->databasecallsrequiretheuseofacursor• IncludingPL/SQLstoredprocedurecalls(unlessusingdirectRPC)
1. Thecursorexecutionwilldosomework• Duringtheexecution,theprocesseseither:
• WorkonCPU– OratleastwanttoworkonCPU,butOSschedulerdoesn’tallowthem
• DonotWorkonCPU– TheyhavebeenputtosleepbyOSbecauseofablockingsystemcall– Theyhavegonetosleepvoluntarily,waitingforsomeeventcompletion
blog.tanelpoder.com 8GettingtheMostOutofASH©TanelPoder
V$SESSION
SGA
OracleProcess(thread)
SID999...SID3SID2SID1
8dq0v1mjngj77hk2m2702uac13sma6rkr27
0ruh367af7gb
V$SESSION
...
V$SQLSTATS
OracleProcess(thread)
OracleProcess(thread)
TotalCPU,ElapsedTime,IOconsumedbythisSQLID/Child
Currently thissession is
runningSQLIDc13sma6rkr27
AWR,Statspack“TOPSQL”reports
RegularSQLcursorexecutionmetrics
(CPU,Elapsed, Exec#,LIO/PIO)
blog.tanelpoder.com 9GettingtheMostOutofASH©TanelPoder
V$SESSION
SID123
SQL_IDSTATEEVENT
USERNAMEPROGRAMMACHINEMODULEACTION
...
SID122....................................
SID121....................................
Currently thissession isrunning
SQLIDc13sma6rkr27
SID124....................................
SID125....................................
SID126....................................
Currently thissession happens to
beWAITING
Thissession waitsfor“db filesequential
read”eventcompletion
Thissession wascreatedbyuserJOE
Thissession iscreatedbyaprogram
calledReportRunner.exe Thissession was
createdbyuserJOE
• AnOracleprocesspopulatesinformationinV$SESSION• Immediatelywhensomethingchanges,likenewSQLIDisexecuted,await
ends...
V$SESSION
blog.tanelpoder.com 10GettingtheMostOutofASH©TanelPoder
V$SESSION
• V$SESSIONisafixedarray(separateineachRACinstance)• Thesessionsparametercontrolsthenumberofslotsinthisarray• TheSIDisjustaslotnumberintheV$SESSIONarray
• Whendoingwork,eachOracleprocessupdatesinformationinitscorrespondingsessionslot• Constant,immediateupdatesaboutcurrent state/taskathand• Anupdate(let’ssayanewwaitevent)overwritesthepreviousvalue
• Developers,DBAscanquerytheseattributestofindwhatothersessionsareupto• FromV$SESSIONyouseeonlythecurrent stateofasession,nohistory!
blog.tanelpoder.com 11GettingtheMostOutofASH©TanelPoder
ActiveSessionHistory
History ofsamplesofSessions thathappenedtobeActive duringthesampling
blog.tanelpoder.com 12GettingtheMostOutofASH©TanelPoder
ActiveSessionHistoryandwhereitsdatacomesfrom
SGA
OracleProcess(thread)
SID999...SID3SID2SID1
8dq0v1mjngj77hk2m2702uac13sma6rkr27
0ruh367af7gb
V$SESSION
...
V$SQLSTATS
OracleProcess(thread)
OracleProcess(thread)
TotalCPU,ElapsedTime,IOconsumedbythisSQLID/Child
AWR,Statspack“TOPSQL”reports
RegularSQLcursorexecutionmetrics
(CPU,Elapsed, Exec#,LIO/PIO)
ASH
MMNLprocess
Activesession
samples
blog.tanelpoder.com 13GettingtheMostOutofASH©TanelPoder
Samplingsessionactivitydetailsovertime– WhichSQL?
SELECTA
SELECTX
idle SELECTB UPDATEC
Time
SID10
SID11
SID12
idle idle
SELECTY INSERTZidle
SELECTN SELECTN UPDATEKSELECTN idle SELECTN SEL
SELECTA idle SELECTB UPDATECidle idle
SELECTAidle UPDATEC idleidle COMMIT
SID13
SID14
SID15
2 xSELECTA1 xSELECTX1xSELECTY1 xSELECTN
Samplesessionactivityovertime->(v$session)
3 xSELECTA1 xSELECTX1xSELECTY1 xSELECTN
…3 xUPDATEC1 xSELECTX1 xSELECTY
Count thenumberof(active)sessionseachsample,groupbySQLID
blog.tanelpoder.com 14GettingtheMostOutofASH©TanelPoder
Samplingsessionactivity– WorkingorWaiting?
SELECTA
SELECTX
idle SELECTB UPDATEC
Time
SID10
SID11
SID12
idle idle
SELECTY INSERTZidle
SELECTN SELECTN UPDATEKSELECTN idle SELECTN SEL
SELECTA idle SELECTB UPDATECidle idle
SELECTAidle UPDATEC idleidle COMMIT
SID13
SID14
SID15
Commit
UserIO
CPU
Locks
Time
Sessioncount
blog.tanelpoder.com 15GettingtheMostOutofASH©TanelPoder
On-lineActiveSessionHistoryandhistoricalASH
• In-memoryarray• Oneineachinstance• Designedtokeepatleast1hourofhistoryinmemory• MMNLprocesscopiesactive sessioninfofromV$SESSIONandan"ASHLoc"
memorystructurethereoncepersecond• 1sample= 1second• V$ACTIVE_SESSION_HISTORY
• Long-termhistory• Oneperdatabase• RetentionconfiguredusingtheAWRretentionparameter• Only10%ofsamplessavedbydefaulttosavespace• 1sample=10seconds• DBA_HIST_ACTIVE_SESS_HISTORY
Thisisusedwhenswitchingto
Historical viewinOEM
blog.tanelpoder.com 16GettingtheMostOutofASH©TanelPoder
The correct logic for querying ASHSELECT
dimension1
, COUNT(*) secondsFROM
v$active_session_history
WHEREsample_time BETWEEN …
ORDER BY
seconds DESC
SQL> SELECT
2 sql_id3 , COUNT(*) seconds
4 FROM
5 v$active_session_history
6 WHERE
7 sample_time > SYSDATE-1/24/12
8 GROUP BY
9 sql_id
10 ORDER BY
11* seconds DESC
SQL> /
SQL_ID SECONDS
------------- ----------
2vp4k2kgy2wm4 12450
c13sma6rkr27c 27
8dq0v1mjngj7t 16
0w2qpuc6u2zsp 11
bymb3ujkr3ubk 10
...
Top SQL in last 5 minutes
ASHislikeafacttable inadimensionaldatamodel.
Theexistence ofarowinASHisafactofasessiontakingtimeindatabase(DBTime)- v$active_session_history row=1second- dba_hist_active_sess_history =10seconds
blog.tanelpoder.com 17GettingtheMostOutofASH©TanelPoder
The incorrect logic for querying ASH!!!SELECT
dimension1
, SUM(time_waited) seconds
FROM
v$active_session_history
WHEREsample_time BETWEEN …
ORDER BY
seconds DESC
SQL> ed
Wrote file afiedit.sql
1 SELECT
2 sql_id
3 , SUM(time_waited) this_is_wrong
4 FROM
5 v$active_session_history
6 WHERE
7 sample_time > SYSDATE-1/24/12
8 AND sql_id = '2vp4k2kgy2wm4'
9 GROUP BY
10 sql_id
11 ORDER BY
12* this_is_wrong DESC
SQL> /
SQL_ID THIS_IS_WRONG
------------- -------------
2vp4k2kgy2wm4 0
ASHdoesnottrace everysinglewaitthereis!
ThereforeinformationaboutmanyshortwaitsthathappenedbetweenASHsamplesislost!
However,counting thenumberofsampleswhereasessionwasactivegivesagoodapproximation ofwherewastheDBtimespent
blog.tanelpoder.com 18GettingtheMostOutofASH©TanelPoder
A simple ASH drilldown exampleSELECT
dimension1
, dimension2
, COUNT(*) seconds
FROM
v$active_session_historyWHERE
sample_time BETWEEN …
AND sql_id = ‘2vp4k2kgy2wm4’ORDER BY
seconds DESC
SQL> SELECT
2 sql_id
3 , session_id,session_serial#4 , COUNT(*) seconds
5 FROM
6 v$active_session_history
7 WHERE
8 sample_time > SYSDATE-1/24/12
9 AND sql_id = '2vp4k2kgy2wm4'10 GROUP BY
11 sql_id
12 , session_id,session_serial#13 ORDER BY
14* seconds DESC
SQL> /
SQL_ID SIDSERIAL SECONDS
------------- ---------- ----------
2vp4k2kgy2wm4 789,14653 622vp4k2kgy2wm4 789,14631 59
2vp4k2kgy2wm4 803,61957 56...
Who’s running this SQL?
YoucandrilldownintoasingleSQL,singleapplicationorasessionbyjustaddingWHEREconditionsforfilteringdata.
Youcanseemoredetailby justaddingASHdimensionfieldstotheGROUPBYclause
blog.tanelpoder.com 19GettingtheMostOutofASH©TanelPoder
SELECT...COUNT(*)FROMash
GROUPBYwait_class
GROUPBYsample_time
WHEREsample_timeBETWEEN ...
GROUPBYSQL_ID...
GROUPBYSESSION_ID,USERNAME...GROUPBY
wait_class
blog.tanelpoder.com 20GettingtheMostOutofASH©TanelPoder
AverageActiveSessions(AAS):Whyanewmetric?ThemeaningofAWR
"100%" constantlychangesbasedonhowmanysessions
areloggedonandhowidle/activetheyare
blog.tanelpoder.com 21GettingtheMostOutofASH©TanelPoder
AverageActiveSessions(ASHreport)ASHrecordsallactivesessionsevery
second.5919activesessionssamplesover9minutes(540seconds)
Onaveragewehad5919/540=10.96activesessions duringeachsample
8.29AASwerewaitingfordb filesequentialread(75.67%oftotal
AAS)
Timespentbybackgroundprocesses,
it'snotadirectindicatorofuserresponsetime
blog.tanelpoder.com 22GettingtheMostOutofASH©TanelPoder
BasicTroubleshootingExamples
blog.tanelpoder.com 23GettingtheMostOutofASH©TanelPoder
PerformanceHome:Non-DatabaseHostCPU
SomethingelseisconsumingalltheCPUresource! (someotherdatabaseinstance,applicationor
amonitoringagent,etc) YouneedtorunanOStool(top)tofindthetopCPUusers.Your
databaseinstancemayjustbeavictimhere.
LoadaverageevenhigherthantheCPUusage(1600%- 16virtualthreads)
blog.tanelpoder.com 24GettingtheMostOutofASH©TanelPoder
PerformanceHome:ExtraIOandCPUtime?WhytheI/OwaitandCPUtimespike?
blog.tanelpoder.com 25GettingtheMostOutofASH©TanelPoder
PerformanceHome:WorkloadIncreaseThedatabaseisdoingmore
work!
...andmorediskreads
...andmoredirtybuffer
writesandlogfilewrites
blog.tanelpoder.com 26GettingtheMostOutofASH©TanelPoder
PerformanceHome:ExtraI/Otimeandthroughputdrop?
Throughputhasdropped!
WhytheI/Ospike?
blog.tanelpoder.com 27GettingtheMostOutofASH©TanelPoder
PerformanceHome:I/Osubsystemissue!
WearedoinglessI/Os?!
TheaverageI/Otimehasincreased
significantly!
blog.tanelpoder.com 28GettingtheMostOutofASH©TanelPoder
Tworeasonswhyyourworkloadisrunningslowly:
1.It'sdoingtoomuchwork
2.Itcannotworkfastenough
ToomanyI/Ooperations
(SQLplanissue?)
EveryI/Ooperationtakestoomuchtime(storageissue?)
blog.tanelpoder.com 29GettingtheMostOutofASH©TanelPoder
IOtimejumpsup,someuserscomplain
Throughputhasdropped!
blog.tanelpoder.com 30GettingtheMostOutofASH©TanelPoder
I/OlatencyI/Olatencyhas
increased
blog.tanelpoder.com 31GettingtheMostOutofASH©TanelPoder
DrilldownintotheI/Owaits
"cellsmarttablescan"isthefulltablescanwait
event
blog.tanelpoder.com 32GettingtheMostOutofASH©TanelPoder
BreaktheIOwaitsdownbySQL_IDandSessionID
AsingleSQLconsuming80%of
waittime
Nosinglesessionwaitingmuch
morethanothers
blog.tanelpoder.com 33GettingtheMostOutofASH©TanelPoder
DrilldownintotheproblemSQL
JustclickontheSQL_ID(hovermouseoverforSQLtextpreview
blog.tanelpoder.com 34GettingtheMostOutofASH©TanelPoder
Firstimpression:ThisSQLhasnotbeenexecutedornotusedmuchresourceinpast?
Multipledifferentexecutionplans!TheSQLviewshowsonly1plan_hash_value ata
time!
blog.tanelpoder.com 35GettingtheMostOutofASH©TanelPoder
Let'sseetheresourceusageoftheotherplan
ThisSQLwasusingadifferentplanearlier,beforetheproblem
happened!
blog.tanelpoder.com 36GettingtheMostOutofASH©TanelPoder
ComparingExecutionPlans
Before
After
TheStatisticspaneshowsyouthenumberofexecutions,logical&physicalIOcounts
blog.tanelpoder.com 37GettingtheMostOutofASH©TanelPoder
UsingASHAnalytics
Selecttheproblemrange(withenough"before"time)
blog.tanelpoder.com 38GettingtheMostOutofASH©TanelPoder
ASHAnalytics:DrillDownintoaSQL_IDCurrent
breakdown("groupby")ison
SQL_IDRightclickontheSQLofinteresttoshowonly itsdata
blog.tanelpoder.com 39GettingtheMostOutofASH©TanelPoder
ASHAnalytics:DrillDownintoaSQL_ID
NowthechartshowsonlygivenSQL_ID
Theblacklineshowstotalactivityforreference
Nowlet'sgrouptheASHdatabya
differentattribute!
blog.tanelpoder.com 40GettingtheMostOutofASH©TanelPoder
ASHAnalytics:DrillDownintoaSQL_ID
Samedata,brokendownbyplanhashvalue
Allrecordedplansusedbythis
SQL_IDarelistedonasinglechart
blog.tanelpoder.com 41GettingtheMostOutofASH©TanelPoder
ASHAnalytics:DrillDownintoaSQL_ID
YoucanbreaktheactivitydownbyanyASHattribute,likeevenSQLplan
linein11g+
blog.tanelpoder.com 42GettingtheMostOutofASH©TanelPoder
ThefullpowerofASHdatadimensions
blog.tanelpoder.com 43GettingtheMostOutofASH©TanelPoder
ASHisafacttableinadimensionaldatamodel
• ASHisafacttable
• Themereexistence ofarecordinASHisafact• ...ofdatabasetimeusedbysomesessioninpast• That'swhyyoushouldjustCOUNT(*) therecords
• YoucanbreakdownthetimeconsumptionusingGROUPBY onASHdimension attributecolumns,togetTOP-reports:• SQLID• Waitevent• UserID• SessionID• Program
blog.tanelpoder.com 44GettingtheMostOutofASH©TanelPoder
Top-activitybyASHdimensions
BasicASHattributestogroupTOPactivityby
blog.tanelpoder.com 45GettingtheMostOutofASH©TanelPoder
V$ACTIVE_SESSION_HISTORYcolumnsinOracle11.2Name Null? Type------------------------------- -------- ------------SAMPLE_ID NUMBERSAMPLE_TIME TIMESTAMP(3)IS_AWR_SAMPLE VARCHAR2(1)SESSION_ID NUMBERSESSION_SERIAL# NUMBERSESSION_TYPE VARCHAR2(10)FLAGS NUMBERUSER_ID NUMBERSQL_ID VARCHAR2(13)IS_SQLID_CURRENT VARCHAR2(1)SQL_CHILD_NUMBER NUMBERSQL_OPCODE NUMBERSQL_OPNAME VARCHAR2(64)FORCE_MATCHING_SIGNATURE NUMBERTOP_LEVEL_SQL_ID VARCHAR2(13)TOP_LEVEL_SQL_OPCODE NUMBERSQL_PLAN_HASH_VALUE NUMBERSQL_PLAN_LINE_ID NUMBERSQL_PLAN_OPERATION VARCHAR2(30)SQL_PLAN_OPTIONS VARCHAR2(30)SQL_EXEC_ID NUMBERSQL_EXEC_START DATE
ASHsamplemetadata
Session info
SQLstatementinfo
SQLexecutionplan info
IndividualSQLexecution info
blog.tanelpoder.com 46GettingtheMostOutofASH©TanelPoder
V$ACTIVE_SESSION_HISTORYcolumnsinOracle11.2...PLSQL_ENTRY_OBJECT_ID NUMBERPLSQL_ENTRY_SUBPROGRAM_ID NUMBERPLSQL_OBJECT_ID NUMBERPLSQL_SUBPROGRAM_ID NUMBERQC_INSTANCE_ID NUMBERQC_SESSION_ID NUMBERQC_SESSION_SERIAL# NUMBERPX_FLAGS NUMBEREVENT VARCHAR2(64)EVENT_ID NUMBEREVENT# NUMBERSEQ# NUMBERP1TEXT VARCHAR2(64)P1 NUMBERP2TEXT VARCHAR2(64)P2 NUMBERP3TEXT VARCHAR2(64)P3 NUMBERWAIT_CLASS VARCHAR2(64)WAIT_CLASS_ID NUMBERWAIT_TIME NUMBERSESSION_STATE VARCHAR2(7)TIME_WAITED NUMBER
PL/SQLobjectinfo,join todba_procedures /@procid.sql
Parallelexecutioninfo
Waiteventinfo
Remember,youshouldnot sumanywaitcolumns,use
COUNT(*)toestimateDBTime
Waiteventparameters(extrainfo)
blog.tanelpoder.com 47GettingtheMostOutofASH©TanelPoder
V$ACTIVE_SESSION_HISTORYcolumnsinOracle11.2BLOCKING_SESSION_STATUS VARCHAR2(11)BLOCKING_SESSION NUMBERBLOCKING_SESSION_SERIAL# NUMBERBLOCKING_INST_ID NUMBERBLOCKING_HANGCHAIN_INFO VARCHAR2(1)CURRENT_OBJ# NUMBERCURRENT_FILE# NUMBERCURRENT_BLOCK# NUMBERCURRENT_ROW# NUMBERTOP_LEVEL_CALL# NUMBERTOP_LEVEL_CALL_NAME VARCHAR2(64)CONSUMER_GROUP_ID NUMBERXID RAW(8)REMOTE_INSTANCE# NUMBERTIME_MODEL NUMBERIN_CONNECTION_MGMT VARCHAR2(1)IN_PARSE VARCHAR2(1)IN_HARD_PARSE VARCHAR2(1)IN_SQL_EXECUTION VARCHAR2(1)IN_PLSQL_EXECUTION VARCHAR2(1)IN_PLSQL_RPC VARCHAR2(1)IN_PLSQL_COMPILATION VARCHAR2(1)IN_JAVA_EXECUTION VARCHAR2(1)IN_BIND, IN_CURSOR_CLOSE, IN_SEQUENCE_LOAD ...
Blockingsession info
DBobjectinvolved inawait(notpopulated forallwaits,notalwayscleanedupproperly)
Timemodelphaseinfo.
TheseY/Nflagstellinwhichphase(SQLparse,SQLexecute,login,PL/SQL,login) thesessionhappened tobewhensampled
Databasecall(OPIcall)info
Currenttransactioninfo
blog.tanelpoder.com 48GettingtheMostOutofASH©TanelPoder
V$ACTIVE_SESSION_HISTORYcolumnsinOracle11.2CAPTURE_OVERHEAD VARCHAR2(1)REPLAY_OVERHEAD VARCHAR2(1)IS_CAPTURED VARCHAR2(1)IS_REPLAYED VARCHAR2(1)DBREPLAY_FILE_ID NUMBERDBREPLAY_CALL_COUNTER NUMBERSERVICE_HASH NUMBERPROGRAM VARCHAR2(48)MODULE VARCHAR2(64)ACTION VARCHAR2(64)CLIENT_ID VARCHAR2(64)MACHINE VARCHAR2(64)PORT NUMBERECID VARCHAR2(64)TM_DELTA_TIME NUMBERTM_DELTA_CPU_TIME NUMBERTM_DELTA_DB_TIME NUMBERDELTA_TIME NUMBERDELTA_READ_IO_REQUESTS NUMBERDELTA_WRITE_IO_REQUESTS NUMBERDELTA_READ_IO_BYTES NUMBERDELTA_WRITE_IO_BYTES NUMBERDELTA_INTERCONNECT_IO_BYTES NUMBERPGA_ALLOCATED NUMBERTEMP_SPACE_ALLOCATED NUMBER
DBReplay&workloadcapture
Clientapplicationinfo
I/Ocounters.Thesecanbesummedovermultiplesamples
Executioncontextidentifier(end-to-endrequestID)
Sessionmemoryusagewhensampled(useMAXorAVG*)
MoreprecisemeasurementofDB/CPUtimebetweensamples
blog.tanelpoder.com 49GettingtheMostOutofASH©TanelPoder
Ok,howtouseallthisawesomeinformation?
blog.tanelpoder.com 50GettingtheMostOutofASH©TanelPoder
Profiling!Breakingdownsessionresponsetime
1. WhichDBoperation?• Login,Cursoropen/close,Parse,SQLExecute,PL/SQLExecute,LOBaccess?
1. WhichSQLstatement?• OrPL/SQLprocedure• Whichexecutionplanversion?
1. WorkingonCPUorWaiting?• Ifwaiting,forwhat?
2. When?• sample_time
TimeModel,top_level_call_name
sql_opname
SQL_IDTOP_LEVEL_SQL_IDPL_SQL_OBJECT_ID
...
SESSION_STATEEVENTP1,P2,P3
blog.tanelpoder.com 51GettingtheMostOutofASH©TanelPoder
ashtop.sql usage1-- @ashtop <GROUP_BY> <FILTER> <BEGIN_TIME> <END_TIME>
SQL> @ashtop username,sql_id session_type='FOREGROUND' sysdate-1/24 sysdate
USERNAME SQL_ID TotalSeconds CPU User I/O Application---------------------- ------------- ------------ ---------- ---------- -----------SOE c13sma6rkr27c 1218 605 3 0SOE 8dq0v1mjngj7t 1212 206 1001 0SOE bymb3ujkr3ubk 965 255 612 0TANEL 5n83a4q202674 724 24 700 0...
SQL> @ashtop session_state,event sql_id='c13sma6rkr27c' sysdate-1/24 sysdate
SESSION EVENT TotalSeconds CPU User I/O Application------- ------------------------- ------------ ---------- ---------- -----------ON CPU 603 603 0 0WAITING gc cr block 2-way 313 0 0 0WAITING gc current block 2-way 100 0 0 0WAITING gc buffer busy acquire 87 0 0 0...
blog.tanelpoder.com 52GettingtheMostOutofASH©TanelPoder
ashtop.sql usage2SQL> @ashtop event,blocking_session_status,blocking_inst_id,blocking_session, \
blocking_session_serial# \"wait_class in ('Concurrency','Cluster')" sysdate-1/24 sysdate
EVENT BLOCKING_SE B_INST_ID B_SESSION BSERIAL# TotalSeconds Cluster--------------------------- ----------- --------- --------- -------- ------------ -------gc cr block 2-way UNKNOWN 339 339gc current block 2-way UNKNOWN 299 299gc current grant busy GLOBAL 156 156gc current grant 2-way UNKNOWN 117 117gc cr grant 2-way UNKNOWN 34 34gc cr multi block request UNKNOWN 22 22gc current grant busy UNKNOWN 22 22gc current block busy UNKNOWN 21 21gc buffer busy acquire UNKNOWN 20 20library cache: mutex X UNKNOWN 20 0gc current grant 2-way GLOBAL 11 11gc buffer busy acquire VALID 1 1174 42307 7 7gc buffer busy acquire VALID 1 588 32309 6 6gc buffer busy acquire VALID 1 981 31893 4 4gc buffer busy acquire VALID 1 1173 26117 4 4gc buffer busy acquire VALID 1 1365 15545 4 4...
Manywaiteventspopulate the
blockingsessioncolumns.
(RACstillaproblem)
blog.tanelpoder.com 53GettingtheMostOutofASH©TanelPoder
ashtop.sql scriptSELECT
&1, COUNT(*) "TotalSeconds", SUM(CASE WHEN wait_class IS NULL THEN 1 ELSE 0 END) "CPU", SUM(CASE WHEN wait_class ='User I/O' THEN 1 ELSE 0 END) "User I/O", SUM(CASE WHEN wait_class ='Application' THEN 1 ELSE 0 END) "Application", SUM(CASE WHEN wait_class ='Concurrency' THEN 1 ELSE 0 END) "Concurrency", SUM(CASE WHEN wait_class ='Commit' THEN 1 ELSE 0 END) "Commit"... <some output snipped> ..., SUM(CASE WHEN wait_class ='Queueing' THEN 1 ELSE 0 END) "Queueing", SUM(CASE WHEN wait_class ='Other' THEN 1 ELSE 0 END) "Other"
FROMv$active_session_history a
, dba_users uWHERE
a.user_id = u.user_id (+)AND &2AND sample_time BETWEEN &3 AND &4GROUP BY
&1ORDER BY
"TotalSeconds" DESC, &1
Verysimplequery!Thequerystructureremainsthesame,justtheGROUPcolsandfilterschange
ASHanalysisissimple!
blog.tanelpoder.com 54GettingtheMostOutofASH©TanelPoder
ParsingissuesSQL> @ashtop sql_id "session_id=201 and session_serial#=2045" sysdate-1/24 sysdate
%This SQL_ID TotalSeconds CPU User I/O Application Concurrency----- ------------- ------------ ---------- ---------- ----------- -----------
7% 6mfhuc2m1wwh6 15 15 0 0 00% 01p50dapj7mn1 1 1 0 0 00% 08qbgdbcq0zn1 1 1 0 0 0
...
SQL> @ashtop sql_plan_hash_value "session_id=201 and session_serial#=2045".....
%This SQL_PLAN_HASH_VALUE TotalSeconds CPU User I/O Application----- ------------------- ------------ ---------- ---------- -----------
90% 2274240236 202 202 0 010% 0 23 23 0 0
SQL> SELECT sql_text FROM v$sql WHERE plan_hash_value = 2274240236;SQL_TEXT----------------------------------------select count(*) from dual where rownum = -107532095select count(*) from dual where rownum = 2016837960
NosingleSQLtakesmajorityof time.Many different
SQL_IDs
Literalvalues!
blog.tanelpoder.com 55GettingtheMostOutofASH©TanelPoder
TimeModelPhasesexample- ParsingSQL> @ash/time_model username "session_id=201 and session_serial#=2045" sysdate-
1/24 sysdate
COUNT(*) %This USERNAME STAGE---------- ----- --------------- -------------------------------------------
133 74% TANEL PARSE HARD_PARSE SQL_EXECUTION37 21% TANEL PARSE SQL_EXECUTION7 4% TANEL SQL_EXECUTION3 2% TANEL SQL_EXECUTION PLSQL_EXECUTION
TimeModelattributestellinwhichtypeofexecution
thesessionwasin(itcomplementsSQL_IDand
waiteventinfo)
TherearealsoV$SESS_TIME_MODELandV$SYS_TIME_MODELviews
(different scope)
blog.tanelpoder.com 56GettingtheMostOutofASH©TanelPoder
topcur.sql
• ListtopSQLbydistinctSQL_IDsandnumberofchildren(versions)• QueriesV$SQL(notASH)
SQL> @topcur================================================================================================ SQLs not using bind variables (check the SQL texts of top offenders) ================================================================================================
TOTAL_CHILDREN DISTINCT_SQLIDS PLAN_HASH_VALUE MIN(SQL_ID) MAX(SQL_ID) MIN(FIRST_LOAD_TIME)-------------- --------------- --------------- ------------- ------------- --------------------
3517 3517 2274240236 0027x8k49at8f gzrqcr44fr34t 2013-04-26/14:11:2633 31 0 03tuga43v3xkg g7mt7ptq286u7 2013-04-21/11:41:3715 15 1388734953 089dbukv1aanh gn9m0mtakrwmc 2013-04-21/11:41:39
================================================================================================ SQLs with many child cursors under a parent (use nonshared*.sql to find the reasons) ================================================================================================
TOTAL_CHILDREN DISTINCT_SQLIDS DISTINCT_PLANS SQL_ID MIN(PLAN_HASH_VALUE) MAX(PLAN_HASH_VALUE)-------------- --------------- -------------- ------------- -------------------- --------------------
2994 1 1 axdb0g9p3ypsa 2966233522 2966233522
ManydifferentSQLtexts
CheckSQLtextofsomeSQL_IDs
SingleSQLtextusedbyallchildren
Runnonshared.sql tofind thereasons
blog.tanelpoder.com 57GettingtheMostOutofASH©TanelPoder
TimeModelPhasesexample– SequenceLoad
SQL> @ash/time_model_phases sql_id "session_id=201 and session_serial#=2045" sysdate-1/24/60 sysdate
COUNT(*) %This SQL_ID STAGE---------- ----- ------------- --------------------------------------------------
51 85% 0mnrqmmbrk776 SQL_EXECUTION SEQUENCE_LOAD9 15% 0mnrqmmbrk776 SQL_EXECUTION
SQL> @ash/time_model_phases sql_id,session_state,event "session_id=201 and session_serial#=2045" sysdate-1/24/60 sysdate
COUNT(*) %This SQL_ID SESSION EVENT STAGE---------- ----- ------------- ------- ---------------- ------------------------
39 65% 0mnrqmmbrk776 ON CPU SQL_EXECUTION SEQUENCE_LOAD11 18% 0mnrqmmbrk776 WAITING row cache lock SQL_EXECUTION SEQUENCE_LOAD10 17% 0mnrqmmbrk776 ON CPU SQL_EXECUTION
-- fix the problemSQL> ALTER SEQUENCE s CACHE 10000;
Sequence altered.
blog.tanelpoder.com 58GettingtheMostOutofASH©TanelPoder
TimeModelHierarchy1) background elapsed time
2) background cpu time3) RMAN cpu time (backup/restore)
1) DB time2) DB CPU2) connection management call elapsed time2) sequence load elapsed time2) sql execute elapsed time2) parse time elapsed
3) hard parse elapsed time4) hard parse (sharing criteria) elapsed time
5) hard parse (bind mismatch) elapsed time3) failed parse elapsed time
4) failed parse (out of shared memory) elapsed time2) PL/SQL execution elapsed time2) inbound PL/SQL rpc elapsed time2) PL/SQL compilation elapsed time2) Java execution elapsed time2) repeated bind elapsed time
Checkv$sess_time_model in
OracleReferencedocs:
http://bit.ly/11pkGjS
DBTime isthetotaltimetheDBspent
servicingapplicationcallsinDB
Usethe"parseelapsedtime"numbersfor
estimatingparsingoverhead.
blog.tanelpoder.com 59GettingtheMostOutofASH©TanelPoder
WaitEvents
blog.tanelpoder.com 60GettingtheMostOutofASH©TanelPoder
WaitEvents
SQL> SELECT wait_class, COUNT(*) FROM v$event_name GROUP BY wait_class;
WAIT_CLASS COUNT(*)------------------------------ ----------Administrative 55Application 17Cluster 50Commit 2Concurrency 33Configuration 24Idle 95Network 35Other 745Queueing 9Scheduler 8System I/O 31User I/O 48
1152differentwaitevents inOracle
11.2.0.3(@sed.sql)
Similareventsorganizedintowaitclasses
IdlewaiteventsarenotaccountedinsessionDBTime–anddonotshow up
inASH
blog.tanelpoder.com 61GettingtheMostOutofASH©TanelPoder
UserI/OWaitClass
• YourquerywaitsforIOfor"toomuch"eitherbecause:
1. TheSQLisdoingtoomuchIO(badplan,toomuchdata,etc)• Revertbacktothegoodplan• DrilldownintotheSQLqueryandoptimize it
2. TheI/Oitselfisslow• TalktoDBA/sysadmin /storageteamJ• Cachemore
blog.tanelpoder.com 62GettingtheMostOutofASH©TanelPoder
UserI/O – examineIOlatencywithASHdataSQL> @ash/event_hist db.file.*read
Wait time Num ASH Estimated Estimated % Event AwesomeWait Event bucket ms+ Samples Total Waits Total ms Time Graphic------------------------ ---------- --------- ----------- ---------- --------- ------------db file parallel read 0 18 0 0 0 | |
128 1 5.1 128 .2 | |256 17 47.2 4352 8.3 |# |512 18 24.2 9216 17.5 |## |1024 30 30 30720 58.4 |###### |2048 2 2 4096 7.8 |# |4096 1 1 4096 7.8 |# |
db file sequential read 0 894 0 0 0 | |8 1 82 8 0 | |
16 9 329.3 144 0 | |32 34 729.9 1088 0 | |64 62 659.3 3968 .2 | |128 105 557.9 13440 .6 | |256 401 1023.3 102656 4.7 | |512 1071 1485.5 548352 25.1 |### |1024 822 822 841728 38.6 |#### |2048 189 189 387072 17.7 |## |
IOsubsystemisslow,assingleblockreadsoftentaketenstohundredsofms
blog.tanelpoder.com 63GettingtheMostOutofASH©TanelPoder
CommitWaitClass– slowIO
SQL> @ash/event_hist "log file.*"Wait time Num ASH Estimated Estimated % Event Awesome
Wait Event bucket ms+ Samples Total Waits Total ms Time Graphic------------------------ ---------- ---------- ----------- ---------- -------- ------------log file parallel write 0 33 0 0 0 | |
8 1 72.4 8 0 | | 16 4 150.1 64 .1 | | 32 4 93.7 128 .1 | | 64 8 90 512 .4 | | 128 6 30.4 768 .6 | | 256 41 103.5 10496 8.5 |# | 512 77 117 39424 32 |### | 1024 60 60 61440 49.9 |##### | 2048 5 5 10240 8.3 |# |
log file sync 0 95 0 0 0 | | 16 1 38.5 16 0 | | 32 1 17 32 0 | | 64 4 45.3 256 .1 | | 128 5 26.2 640 .3 | | 256 24 65.4 6144 2.9 | | 512 80 102.5 40960 19.5 |## | 1024 72 72 73728 35.1 |#### | 2048 37 37 75776 36.1 |#### | 4096 3 3 12288 5.9 |# |
IOsubsystemisslow,asthe"logfileflush"writestakehundredsorthousands ofms
blog.tanelpoder.com 64GettingtheMostOutofASH©TanelPoder
CommitWaitClass– fastIO
SQL> @ash/event_hist "log file"
Wait time Num ASH Estimated Estimated % Event AwesomeWait Event bucket ms+ Samples Total Waits Total ms Time Graphic------------------------ ---------- ------- ----------- ---------- ------- ------------log file parallel write 0 12 30717.1 0 0 | |
1 27 40739.8 27 93.1 |######### | 2 1 360.8 2 6.9 |# |
log file sync 0 5 9337.5 0 0 | | 1 12 17268.9 12 75 |######## | 2 2 631.5 4 25 |### |
SQL> @ashtop username,program "event='log file sync'" sysdate-1/24 sysdate
%This USERNAME PROGRAM TotalSeconds CPU User I/O Commit----- --------- ----------------- ------------ ---------- ---------- -------100% SOE JDBC Thin Client 247 0 0 247
Commitsarefast,every"logfilesync"
takes1-2msFindtopcommitters
blog.tanelpoder.com 65GettingtheMostOutofASH©TanelPoder
ApplicationWaitClass– lockcontention
• Lockstakenandreleasedatwillbytheapplicationcode(TM,TX)arelistedinApplicationwaitclass(notConcurrency)• Ifthere'sasinglesessioncausingmostoftheblocking,
seewhatthatsessionwasdoingwhileotherswaitedonitslock
• JustqueryASHdataforthatsessiononly(withintheblockingtimerange)
SQL> @ashtop event,blocking_session_status,blocking_session,blocking_session_serial# wait_class='Application' sysdate-1/24 sysdate
%This EVENT BLOCKING_SE B_SESSION B_SERIAL# Seconds Application
----- ----------------------------------- ----------- --------- --------- --------- -----------
100% enq: TM - contention VALID 5 14279 5857 58570% enq: TM - contention GLOBAL 11 110% enq: KO - fast object checkpoint VALID 1166 1 8 80% enq: KO - fast object checkpoint GLOBAL 3 30% SQL*Net break/reset to client NO HOLDER 1
CommoncauseforTMlocksisDMLonparenttableswithunindexed
foreignkeys:http://bit.ly/aeANst
blog.tanelpoder.com 66GettingtheMostOutofASH©TanelPoder
ConcurrencyWaitClass
• Concurrencywaitsaregenerallyvariousblockinginternal locksofwhichtheapplicationdoesnothavedirectcontrol• Bufferpins,latches,mutexes,internalenqueuesetc.• Somewaiteventspopulatetheblockingsessioninfo,somedon't
SQL> @ashtop event,blocking_session_status,blocking_sessionwait_class='Concurrency' sysdate-1/24 sysdate
%This EVENT B_STATUS B_SESSION Seconds CPU Concurrency----- ------------------------------ -------- --------- ------- ---- -----------
77% library cache: mutex X UNKNOWN 27 0 276% buffer busy waits VALID 1754 2 0 26% cursor: pin S UNKNOWN 2 0 23% buffer busy waits VALID 2334 1 0 13% latch: cache buffers chains UNKNOWN 1 0 13% latch: cache buffers chains VALID 1171 1 0 13% os thread startup UNKNOWN 1 0 1
blog.tanelpoder.com 67GettingtheMostOutofASH©TanelPoder
Waiteventparameters
• Everywaitcanpostupto3"additionalinfo" parameterswiththewait• ShownasP1,P2,P3(orPARAMETER1-3)invariousviewsandtraces• Contentsdependentonthewaittype• P1forlatchwaitsisthelatchaddress• P1fordiskreadwaiteventsisusuallythefile# ofthereadblock• V$EVENT_NAMEandASHhaveP1TEXT,P2TEXT,P3TEXTcolumnswith
explanation
blog.tanelpoder.com 68GettingtheMostOutofASH©TanelPoder
Usingwaiteventparameters- 1
SQL> @ashtop p1text,p1,p2text,p2,p3text,p3 "event='buffer busy waits'" sysdate-1/24 sysdate
%This P1TEXT P1 P2TEXT P2 P3TEXT P3 TotalSeconds----- ---------- ---------- ---------- ---------- ---------- ------ ------------
67% file# 7 block# 43120238 class# 1 233% file# 7 block# 43120039 class# 1 1
SQL> @bclass 1
CLASS UNDO_SEGMENT_ID------------------ ---------------data block
-- find which segment this block belongs toSQL> @dba2 7 43120238
OWNER SEGMENT_NAME------------------------------ ------------SOE LOGON
FindthehotblockusingP1/P2andblocktypewithP3
blog.tanelpoder.com 69GettingtheMostOutofASH©TanelPoder
Usingwaiteventparameters- 2
SQL> @ashtop p1text,p1,p2text,TO_NUMBER(TRIM(SUBSTR(TO_CHAR(p2,'0XXXXXXXXXXXXXXX'),1,8)),'XXXXXXXXXXXXXXXX') "event='library cache: mutex X'" sysdate-1/24 sysdate
%This P1TEXT P1 P2TEXT TO_NUMB TotalSeconds CPU Concurrency----- ---------- ---------- ---------- ------- ------------ ------- -------------
13% idn 4138265817 value 170 3 0 38% idn 539807965 value 170 2 0 28% idn 1792366761 value 121 2 0 24% idn 172627511 value 170 1 0 14% idn 421399181 value 73 1 0 14% idn 421399181 value 109 1 0 1
SQL> SELECT type,owner,name,locked_total,pinned_totalFROM v$db_object_cache WHERE hash_value = 4138265817;
TYPE OWNER NAME LOCKED_TOTAL PINNED_TOTAL-------------------- ---------- -------------------- ------------ ------------PACKAGE BODY SYS DBMS_RANDOM 329 33065680
TheP1forthiswaiteventisthehash
valueoflibrarycacheobject.P2istricky,butcontainstheblocking
SID
blog.tanelpoder.com 70GettingtheMostOutofASH©TanelPoder
WhatistheCPUWaitinEMPerformancePage?
CPUWait isanEMderivedmetric andisthedeltabetweenestimated CPUusagefromASH(AAS)andmeasured CPU
usagefromtimemodel.
blog.tanelpoder.com 71GettingtheMostOutofASH©TanelPoder
ManuallyQueryingASH:Howmuchhistoryinmemory?
SQL> SELECT inst_id, oldest_sample_time, sysdate - oldest_sample_time ash_in_memoryFROM gv$ash_info;
INST_ID OLDEST_SAMPLE_TIME ASH_IN_MEMORY ---------- -------------------------------- -----------------------------
2 25-APR-13 08.32.44.255000000 AM +000000000 03:53:22.7450000001 25-APR-13 08.22.18.382000000 AM +000000000 04:03:48.618000000
SQL> SELECT inst_id, min(sample_time), sysdate - MIN(sample_time) ash_in_memoryFROM gv$active_session_history GROUP BY inst_id;
INST_ID MIN(SAMPLE_TIME) ASH_IN_MEMORY---------- --------------------------- ------------------------
1 25-APR-13 08.21.37.284 AM +000000000 04:03:51.7162 25-APR-13 08.32.13.195 AM +000000000 03:53:15.805
• 11.2+
• 10g+
blog.tanelpoder.com 72GettingtheMostOutofASH©TanelPoder
ASHandbackgroundprocesses?
• EverybackgroundprocessalsohasasessioninV$SESSION• ExceptDispatchers(D000),IdleSharedServers(S000)andIdlePXslaves
(P000)andDISM
• YoucantroubleshootbackgroundprocessactivitywithASHandwaiteventstoo!• Justlikewith
foregroundprocesses
blog.tanelpoder.com 73GettingtheMostOutofASH©TanelPoder
DrillingdownintoSQLExecution
blog.tanelpoder.com 74GettingtheMostOutofASH©TanelPoder
SQLMonitoring:Example
MostofDBTimeisspentonWaiting
(blue)
Focusonlinewheremostofwaitingtookplace
blog.tanelpoder.com 75GettingtheMostOutofASH©TanelPoder
Aquerybottleneckedbydataprocessing,notretrieval
• Aquerybottleneckedbydataprocessing,notretrieval• HashjoinsandaGROUPBYspillingtoTEMP
blog.tanelpoder.com 76GettingtheMostOutofASH©TanelPoder
ReadingaSQLMonitoringreport– in3steps
1. DatabaseTime breakdown• Thetotaltimeactivelyconsumedbythis executionofthequery• ActivitytimeofQC+allPXslavesifparallelexecution
• Q:MostlyonCPUormostlywaiting?
2. Activity% breakdown• IfDBTimewasspentmostlyonCPUthenlookintoCPUActivity% column• IfDBTimewasspentmostlyonwaitingthenWaitActivity% column
• Thistellsyouinwhichexecutionplanline(s)mostofthetimewasspent
1. Executions,IOBytes/Requests,ActualRows returnedmetricstellyouhowmuchworktherowsourceshadtodo
blog.tanelpoder.com 77GettingtheMostOutofASH©TanelPoder
SQLMonitoring– Durationvs DBTime?
• Duration istheamountofwall-clocktimefromtheexecutionstart,uptoclosingthecursor (orreachingendofdata)
• Ifyouopenacursoranddon'tfetchforawhile,theDurationstillkeepsincreasing
• DBTime istheamountofdatabasetime(activityinsidetheDB)yoursession(andallitsPXslaves,ifany)spentexecutingthisSQL
• Soifyourunan1-hourDMLstatementwith8parallelslaves,youmayseeDBTimeupto9hours(upto1hfortheQC,upto8hforallPXslaves)
blog.tanelpoder.com 78GettingtheMostOutofASH©TanelPoder
DBTimemuchsmallerthanDuration?!Duration =15
seconds(wall-clocktime)
DBTime =1.3seconds
(timespent insideDB)
332000rowswerereturned,fetched10rowsatatime(33167fetches).
Mosttimespentonnetworkroundtrips
outsideDB
blog.tanelpoder.com 79GettingtheMostOutofASH©TanelPoder
DBTimemuchbiggerthanDuration?
Duration =9seconds(wall-clocktime)
DBTime =~36seconds
(timespent insideDB)ParallelExecution!
Eachslavecanuseupto1secondofDBTimeperwall-clocksecond(plusQC)
blog.tanelpoder.com 80GettingtheMostOutofASH©TanelPoder
DBTimemuchbiggerthanDuration?
BreakdownthisSQLexecutionactivity
(acrossallPXslaves)bywaiteventorplan
line
blog.tanelpoder.com 81GettingtheMostOutofASH©TanelPoder
ASH-based“SQLmonitoring”report:asqlmon.sql
SQL> @ash/asqlmon 8dq0v1mjngj7t 1
SEC Activity Visual ID OPERATION STATE EVENT ---- -------- ------------ --- ------------------------------------------ ------- -----------------------
6 .3 % | | 0 SELECT STATEMENT ON CPU% | | 1 COUNT STOPKEY
1257 58.4 % |###### | 2 TABLE ACCESS BY INDEX ROWID [CUSTOMERS] WAITING db file sequential read2 .1 % | | 2 ON CPU
11 .5 % | | 2 WAITING db file scattered read 2 .1 % | | 3 INDEX UNIQUE SCAN [CUSTOMERS_PK] ON CPU
28 1.3 % | | 3 WAITING db file scattered read 845 39.3 % |#### | 3 WAITING db file sequential read
OBJ_ALIAS_QBC_NAME ASQLMON_PREDICATES PROJECTION ------------------------- ----------------------- ---------------------------------------------------------
[SEL$1] [F:]ROWNUM<:B1 "CUSTOMER_ID"[NUMBER,22], "CUST_FIRST_NAME"[VARCHAR2,30],CUSTOMERS@SEL$1 [SEL$1] "CUSTOMER_ID"[NUMBER,22], "CUST_FIRST_NAME"[VARCHAR2,30],CUSTOMERS@SEL$1 [SEL$1] "CUSTOMER_ID"[NUMBER,22], "CUST_FIRST_NAME"[VARCHAR2,30],CUSTOMERS@SEL$1 [SEL$1] "CUSTOMER_ID"[NUMBER,22], "CUST_FIRST_NAME"[VARCHAR2,30],CUSTOMERS@SEL$1 [SEL$1] [A:] "CUSTOMER_ID"=:B2 "CUSTOMERS".ROWID[ROWID,10], "CUSTOMER_ID"[NUMBER,22] CUSTOMERS@SEL$1 [SEL$1] [A:] "CUSTOMER_ID"=:B2 "CUSTOMERS".ROWID[ROWID,10], "CUSTOMER_ID"[NUMBER,22]
• Deliberatelywideoutput– highlightarowandscrollleft/right:
blog.tanelpoder.com 82GettingtheMostOutofASH©TanelPoder
Otherstuff,ifthere'stime
blog.tanelpoder.com 83GettingtheMostOutofASH©TanelPoder
WhatdoesASHhavethatV$SESSIONdoesn’t?
• SQLPlanHashValue• It’sretrievablefromX$KSUSE.KSUSESPHthough
• PLAN_LINEcolumns(11g+)• Therearelessawesomeworkarounds(likeusingstatistics_level=all for
selectqueries)
• TimeModelcolumns• UseV$SESS_TIME_MODELtogetsessionlevelbreakdown• Snappershowssessiontimemodelmetricsin“TIME”section
• QueryCoordinatorSID&instanceinfo• It’sretrievablefromV$PX_SESSION• usepx.sql &pxs.sql scripts
blog.tanelpoder.com 84GettingtheMostOutofASH©TanelPoder
WhatdoesSQLTracehavethatASHdoesn’t?
• FullchronologicallyorderedtraceofallSQLexecutions• Regardlessofhowfasttheycompleted• Regardlessofrecursivedepth• Row-countsreturnedfromanystepintheexecutionplan!
• Everysinglebindvariablevalueputinplaceduringthetracing• Someexoticdatatypescan’tbedumpedhuman-readablythough
• Everysinglewaitevent• P1/P2/P3values• Andtheirexactmeasureddurations
• Noticeableoverhead,whenenabled• Inadditiontotracefile writing,itenablestherowsource-levelprofilingforcursors
executedinthetracedsession(excepttheSQLalreadyrunning)
blog.tanelpoder.com 85GettingtheMostOutofASH©TanelPoder
SQLTracingasingleSQLID(11g+)
• UseASHdatatoidentifyproblemSQLanddrilldownwithSQLtrace• Ifneeded...• EitherusealogintriggerorALTERSYSTEM
SQL> ALTER SESSION SET EVENTS 'sql_trace[SQL: 32cqz71gd8wy3] -plan_stat=all_executions,wait=true,bind=true';
Session altered.
SQL> ALTER SESSION SET EVENTS 'sql_trace[SQL: 32cqz71gd8wy3] off';
Session altered.
PLAN_STAT- whentodumpSQLplanlinelevelstatistics
NEVER,FIRST_EXECUTION,ALL_EXECUTIONS
ALTER SESSION SET EVENTS 'trace [RDBMS.SQL_Optimizer.*]
[SQL: 32cqz71gd8wy3]';
Session altered.
YoucanEnableothertracesbySQL_IDtoo
blog.tanelpoder.com 86GettingtheMostOutofASH©TanelPoder
FurtherReading
• ASHArchitectureandAdvancedUsage presentation• ByGrahamWood,UriShaft,JohnBeresniewicz ofOracleCorp• AboutASHmotivation,designandinternals
• http://www.nocoug.org/download/2013-08/NOCOUG_201308_ASH_Architecture_and_Advanced%20Usage.pdf
• OrjustgoogleforASHArchitectureandAdvancedUsage
• ASH-simulationwithouttheDiagnosticsPacklicense(v$session)• OracleASHSimulation–OraSASH
• http://pioro.github.io/orasash/index.html• ASHViewer
• http://jonathanlewis.wordpress.com/2011/03/06/free-ash/
blog.tanelpoder.com 87GettingtheMostOutofASH©TanelPoder
FurtherReading– Reference
• WaitEventsreferenceinOracleDocumentation• OracleDatabaseReference– AppendixCOracleWaitevents• http://docs.oracle.com/cd/E11882_01/server.112/e17110/waitevents.htm
• AnotherwaiteventreferencebyKyleHailey• https://sites.google.com/site/embtdbo/wait-event-documentation
• V$ACTIVE_SESSION_HISTORYcolumnreference• http://docs.oracle.com/cd/E18283_01/server.112/e17110/dynviews_1007.ht
m
• V$EVENT_NAME• Includeswait_class,P1,P2,P3meanings• [email protected]
blog.tanelpoder.com 88GettingtheMostOutofASH©TanelPoder
Thanks!
Myblog&scripts:
http://[email protected]
NewWorld!
http://gluent.com