Вы находитесь на странице: 1из 9

TroubleshootingParallelExecutionwithActiveSessionHistory

LastupdatedNov.11,2012

Introduction
ParallelProcessSpikes
WaitEvents
TempTablespaceSpikes
PGASpikes

ParallelExecutionTableofContents

Introduction

ActiveSessionHistory(ASH)isoneofthemostpowerfuldebuggingtoolsavailabletotheDBAordeveloper.Itis
adatadictionaryviewcalledSYS.DBA_HIST_ACTIVE_SESS_HISTORY.ThereisnocorrespondingALL_orUSER_
view.TheASHviewispopulatedeverysecondwithasamplingofdatafromthev$sessionviewjoinedtoother
v$views.Sincethisisasampling,notalloftherowsfromv$sessionarecopiedtotheASH.However,most
performanceproblemsgoonforminutesorevenhours.ThesearegoingtohavealotofrowsinASH.

TheASHviewdoesnotcontainallofthecolumnsfromthev$sessionview.Forinstance,theosusercolumnis
missing.Thiscanmakeitdifficulttoidentifythepersonofinterestassociatedwithaperformanceproblem.
However,themachinenameiscopiedintotheASH.ThismachinenameiseitheraPCnameoraservername.If
yourcompanycantellyouwhoisassignedaPCwithagivenname,thenyoucantranslatethemachinename
intoapersonsname.

TheASHviewalsohascolumnsthatarenotinv$session,suchaspga_allocatedandtemp_space_allocated.
Theseareenormouslyuseful,asweshallsee.

TheASHviewispartoftheworkloadrepository,soeveryrowgetsasnap_ideventhoughtheviewispopulated
continuouslyeverysecondinsteadofjustduringtheAWRsnapshots.TheASHviewhasthesameretention
periodastheworkloadrepository,sothedatainitisonlygoingtogobackaweekortwo,orwhateveryour
AWRretentionperiodis.

SincetheASHviewcontainssamplesofthev$sessionvieweverysecond,theunderlyingtablewillgetverylarge
foranactivedatabase.Idontthinkthatthereareanyindexesonthesetables.Accordingly,queriesonASHcan
bechallenging,andthereareafewtricksinvolved.Thesequeriescaneasilytake5minutestorunwithone
process,sousingaparallelprocessinghintisalmostessential.Andthenwhenthequerycompletes,itcan
easilyreturnthousandsofrows,soyouneedtoknowhowtoaggregatetheresultsintousefulinformation.

UseoftheActiveSessionHistoryviewwilldescribedbelowandillustratedwithexamples.Theseexampleswill
takespikesinresourceutilizationfromourqueriesthatusetheworkloadrepositoryviewstomonitorthe
database.TheASHviewisthelinkthatenablesustogofromobservingaperformanceproblemtofindingthe
solution.

Followingisthedescriptionoftheactivesessionhistoryview:
SQL>describesys.dba_hist_active_sess_history
NameNull?Type

SNAP_IDNOTNULLNUMBER
DBIDNOTNULLNUMBER
INSTANCE_NUMBERNOTNULLNUMBER
SAMPLE_IDNOTNULLNUMBER
SAMPLE_TIMENOTNULLTIMESTAMP(3)
SESSION_IDNOTNULLNUMBER
SESSION_SERIAL#NUMBER
SESSION_TYPEVARCHAR2(10)

FLAGSNUMBER
USER_IDNUMBER
SQL_IDVARCHAR2(13)
SQL_CHILD_NUMBERNUMBER
SQL_OPCODENUMBER
FORCE_MATCHING_SIGNATURENUMBER
TOP_LEVEL_SQL_IDVARCHAR2(13)
TOP_LEVEL_SQL_OPCODENUMBER
SQL_PLAN_HASH_VALUENUMBER
SQL_PLAN_LINE_IDNUMBER
SQL_PLAN_OPERATIONVARCHAR2(64)
SQL_PLAN_OPTIONSVARCHAR2(64)
SQL_EXEC_IDNUMBER
SQL_EXEC_STARTDATE
PLSQL_ENTRY_OBJECT_IDNUMBER
PLSQL_ENTRY_SUBPROGRAM_IDNUMBER
PLSQL_OBJECT_IDNUMBER
PLSQL_SUBPROGRAM_IDNUMBER
QC_INSTANCE_IDNUMBER
QC_SESSION_IDNUMBER
QC_SESSION_SERIAL#NUMBER
EVENTVARCHAR2(64)
EVENT_IDNUMBER
SEQ#NUMBER
P1TEXTVARCHAR2(64)
P1NUMBER
P2TEXTVARCHAR2(64)
P2NUMBER
P3TEXTVARCHAR2(64)
P3NUMBER
WAIT_CLASSVARCHAR2(64)
WAIT_CLASS_IDNUMBER
WAIT_TIMENUMBER
SESSION_STATEVARCHAR2(7)
TIME_WAITEDNUMBER
BLOCKING_SESSION_STATUSVARCHAR2(11)
BLOCKING_SESSIONNUMBER
BLOCKING_SESSION_SERIAL#NUMBER
BLOCKING_INST_IDNUMBER
BLOCKING_HANGCHAIN_INFOVARCHAR2(1)
CURRENT_OBJ#NUMBER
CURRENT_FILE#NUMBER
CURRENT_BLOCK#NUMBER
CURRENT_ROW#NUMBER
CONSUMER_GROUP_IDNUMBER
XIDRAW(8)
REMOTE_INSTANCE#NUMBER
IN_CONNECTION_MGMTVARCHAR2(1)
IN_PARSEVARCHAR2(1)
IN_HARD_PARSEVARCHAR2(1)
IN_SQL_EXECUTIONVARCHAR2(1)
IN_PLSQL_EXECUTIONVARCHAR2(1)
IN_PLSQL_RPCVARCHAR2(1)
IN_PLSQL_COMPILATIONVARCHAR2(1)
IN_JAVA_EXECUTIONVARCHAR2(1)
IN_BINDVARCHAR2(1)
IN_CURSOR_CLOSEVARCHAR2(1)
SERVICE_HASHNUMBER
PROGRAMVARCHAR2(64)
MODULEVARCHAR2(48)
ACTIONVARCHAR2(32)
CLIENT_IDVARCHAR2(64)
ECIDVARCHAR2(64)

TheexecutionplanofaqueryrunontheASHviewwillrevealtheunderlyingtables.

EXPLAINPLANFOR
SELECT*FROMSYS.DBA_HIST_ACTIVE_SESS_HISTORY;

SQL>SELECT*FROMTABLE(dbms_xplan.display(NULL,NULL,'typical',NULL));
PLAN_TABLE_OUTPUT

Planhashvalue:1921269144

|Id|Operation|Name|Rows|Bytes|Cost(%CPU)|Time|Pstart|Pstop|

|0|SELECTSTATEMENT||781|205K|18(6)|00:00:01|||
|*1|FIXEDTABLEFIXEDINDEX|X$XPLTON(ind:1)|1|47|0(0)|00:00:01|||
|*2|FIXEDTABLEFIXEDINDEX|X$XPLTOO(ind:1)|1|47|0(0)|00:00:01|||
|*3|HASHJOIN||781|205K|18(6)|00:00:01|||
|4|TABLEACCESSFULL|WRH$_EVENT_NAME|995|66665|5(0)|00:00:01|||
|*5|HASHJOINRIGHTOUTER||781|154K|13(8)|00:00:01|||
|*6|TABLEACCESSFULL|WRM$_SNAPSHOT|45|720|3(0)|00:00:01|||
|7|PARTITIONRANGEALL||781|141K|9(0)|00:00:01|1|3|
|8|TABLEACCESSFULL|WRH$_ACTIVE_SESSION_HISTORY|781|141K|9(0)|00:00:01|1|3|

TheWRH$_ACTIVE_SESSION_HISTORYtableisthemaintablefortheASHview.Itisabigtable,andthereareno
indexesonitasfarasIcantell.AqueryontheASHviewcaneasilytakeover5minutesinadatabasethathasa
lotofsessionstosample(thisonedoesn't).So,queriesontheASHviewneedtouseparallelprocessesifthey
aregoingtoruninareasonableamountoftime.

WhenusingthePARALLELhintinaquerythatreadstheASHview,donotspecifyatablenameordegree.These
willeitherbeignored,orpreventthePARALLELhintfrombeingused.TheunderlyingtablesintheASHvieware
hiddendatadictionarytables,andtheseapparentlydon'tworkthesameasusertablesasfarasthePARALLEL
hintisconcerned.JustspecifythePARALLELhintandyouwillgetthedefaultdegreeofparallelism,whichis
equaltotheproductofthedatabaseparameterscpu_counttimesparallel_threads_per_cpu.Thisisthenumber
ofparallelprocessesthatyouwillgetforeachsetofsendersandreceivers.Sinceyouwillgetbothsendersand
receiversintheexecutionplanofanyqueryontheASHview,thetotalnumberofparallelprocessthatyourASH
querywillgetistwotimesthedefaultdegreeofparallelism.
explainplanfor
SELECT/*+PARALLEL*/*
FROMSYS.DBA_HIST_ACTIVE_SESS_HISTORY;
PLAN_TABLE_OUTPUT

Planhashvalue:391332229

|Id|Operation|Name|Rows|Bytes|Cost(%CPU)|Time|Pstart|Pstop|TQ|INOUT|PQDistrib|

|0|SELECTSTATEMENT||781|205K|11(10)|00:00:01||||||
|*1|FIXEDTABLEFIXEDINDEX|X$XPLTON(ind:1)|1|47|0(0)|00:00:01||||||
|*2|FIXEDTABLEFIXEDINDEX|X$XPLTOO(ind:1)|1|47|0(0)|00:00:01||||||
|3|PXCOORDINATOR|||||||||||
|4|PXSENDQC(RANDOM)|:TQ10002|781|205K|11(10)|00:00:01|||Q1,02|P>S|QC(RAND)|
|*5|HASHJOIN||781|205K|11(10)|00:00:01|||Q1,02|PCWP||
|6|PXRECEIVE||995|66665|3(0)|00:00:01|||Q1,02|PCWP||
|7|PXSENDBROADCAST|:TQ10000|995|66665|3(0)|00:00:01|||Q1,00|P>P|BROADCAST|
|8|PXBLOCKITERATOR||995|66665|3(0)|00:00:01|||Q1,00|PCWC||
|9|TABLEACCESSFULL|WRH$_EVENT_NAME|995|66665|3(0)|00:00:01|||Q1,00|PCWP||
|*10|HASHJOINRIGHTOUTER||781|154K|8(13)|00:00:01|||Q1,02|PCWP||
|11|PXRECEIVE||45|720|2(0)|00:00:01|||Q1,02|PCWP||
|12|PXSENDBROADCAST|:TQ10001|45|720|2(0)|00:00:01|||Q1,01|P>P|BROADCAST|
|13|PXBLOCKITERATOR||45|720|2(0)|00:00:01|||Q1,01|PCWC||
|*14|TABLEACCESSFULL|WRM$_SNAPSHOT|45|720|2(0)|00:00:01|||Q1,01|PCWP||
|15|PXBLOCKITERATOR||781|141K|5(0)|00:00:01|1|3|Q1,02|PCWC||
|16|TABLEACCESSFULL|WRH$_ACTIVE_SESSION_HISTORY|781|141K|5(0)|00:00:01|1|3|Q1,02|PCWP||

ParallelProcessSpikes

Belowistheoutputofthequerythatretrievestheparalleloperationmetricsfromthesys.dba_hist_sysstat
view.Asyoucansee,thereisaspikeintheparalleloperationsbetween8:00AMand11:00AM.

INTERVAL_HOURNOT_DGTOTAL_DGDG_SERIALDG_1_TO_25DG_25_TO_50DG_50_TO_75DG_75_TO_99

25SEP201200159000000
25SEP20120116610768718104
25SEP201202238702410
25SEP201203357602629212
25SEP20120436000000
25SEP2012051161876050
25SEP201206230621300

25SEP201207325611112
25SEP20120824717000000
25SEP201209104902000000
25SEP20121056475000000
25SEP201211175000000
25SEP201212178000000
25SEP201213198000000
25SEP201214217110000
25SEP201215232000000
25SEP201216224000000
25SEP20121772000000
25SEP20121811000000
25SEP2012197000000
25SEP2012203000000
25SEP2012216000000
25SEP20122230000000
25SEP2012231000000

Despitethespikeinparalleloperations,therewerenorequestsforparalleloperationsthatweredowngraded.
LetsquerytheActiveSessionHistoryandseewhattheseparalleloperationswere.

Thefollowingquerycountsthenumberofparallelsessionsgroupedbyuser_id,program,module,machine,and
sql_id.Theparallelsessionsareidentifiedthesamewaythattheywereinthev$sessionview:theprogram
nameastheformatoracle_owner@db_server_name,andthentheyhaveaparallelprocessIDinparentheses.

columnprogramformatA25
columnmachineformatA10
columnmoduleformatA25
columnuser_idformat9999999
columncountformat99999
SELECT*FROM(
SELECT/*+PARALLEL*/
count(*)AScount,
user_id,program,module,machine,sql_id
FROMSYS.DBA_HIST_ACTIVE_SESS_HISTORY
WHEREsample_time>TO_DATE('25SEP201208:00:00','DDMONYYYYHH24:MI:SS')
ANDsample_time<TO_DATE('25SEP201211:10:00','DDMONYYYYHH24:MI:SS')
ANDprogramLIKE'oracle@%'
GROUPBYuser_id,program,module,machine,sql_id
ORDERBYcount(*)desc
)
WHERErownum<=20
/
COUNTUSER_IDPROGRAMMODULEMACHINESQL_ID

1600oracle@db_server(J001)DBMS_SCHEDULERdb_server8szmwam7fysa3
109327oracle@db_server(P009)osuser@server2(TNSV1V3)server2avb14fdyuwdhy
108327oracle@db_server(P012)osuser@server2(TNSV1V3)server2avb14fdyuwdhy
920oracle@db_server(J002)DBMS_SCHEDULERdb_serverc6ksc6kfhjjc6
92327oracle@db_server(P000)osuser@server2(TNSV1V3)server2avb14fdyuwdhy
90327oracle@db_server(P008)osuser@server2(TNSV1V3)server2avb14fdyuwdhy
89327oracle@db_server(P006)osuser@server2(TNSV1V3)server2avb14fdyuwdhy
89327oracle@db_server(P004)osuser@server2(TNSV1V3)server2avb14fdyuwdhy
85327oracle@db_server(P010)osuser@server2(TNSV1V3)server2avb14fdyuwdhy
83327oracle@db_server(P011)osuser@server2(TNSV1V3)server2avb14fdyuwdhy
820oracle@db_server(J001)DBMS_SCHEDULERdb_server9q7k9nbpvk8pv
81327oracle@db_server(P001)osuser@server2(TNSV1V3)server2avb14fdyuwdhy
8057oracle@db_server(P033)osuser@server2(TNSV1V3)server20tahuczhvjmm3
80327oracle@db_server(P005)osuser@server2(TNSV1V3)server2avb14fdyuwdhy
79327oracle@db_server(P014)osuser@server2(TNSV1V3)server2avb14fdyuwdhy
74327oracle@db_server(P007)osuser@server2(TNSV1V3)server2avb14fdyuwdhy
70327oracle@db_server(P015)osuser@server2(TNSV1V3)server2avb14fdyuwdhy
69327oracle@db_server(P013)osuser@server2(TNSV1V3)server2avb14fdyuwdhy
65327oracle@db_server(P003)osuser@server2(TNSV1V3)server2avb14fdyuwdhy

6457oracle@db_server(P032)osuser@server2(TNSV1V3)server20tahuczhvjmm3

IfyouhaveRAC,thenyoumayneedmorethanoneservernameinthefilterpredicate.Youmaywillneedone
foreachinstance.

NoticetheparallelprocesshintintheSQLstatement.QueryingtheActiveSessionHistoryviewinserialmode
cantake5minutesormore.With64parallelprocesses,ittakes20to25secondstorunthisqueryinmy
database.Yourperformanceinyourdatabasewillvary,butyouarelikelytoneedtheparallelhintinthisquery.
Thetablenameinthehintistheunderlyingtablethattheviewisdefinedon.

TheASHviewhasothercolumnsinitthatyoumaywanttoinvestigate,sofeelfreetoaddthemtotheSELECT
clause.Theaboveoutputhasbeenlimitedtofitonapage.

Theuser_idisthenumberfromtheuser_idcolumnofthesys.dba_usersview.Youmaybetemptedtojointhe
sys.dba_hist_active_sess_historyviewtothesys.dba_usersviewonuser_id,buttheperformancecanbeeven
worsethanqueryingtheActiveSessionHistoryviewbyitself.Theseviewsaredefinedonmultipletableswith
complexoperations.Joiningthemcancauseunpredictableperformance,soIalwaysqueryontheASHviewby
itself.

Theuser_idvalueof0correspondstotheSYSaccount,soweignorethosesessions.Theparallelsessionsfor
user_id327mayhavedifferentprocessnumbers,buttheyallhavethesamesql_id,avb14fdyuwdhy.Usethe
followingquerytogettheSQLstatement:
SELECT*FROMsys.dba_hist_sqltextWHEREsql_id='8szmwam7fysa3';

TheresultwasanUPDATEstatementthatdidnotuseaprimaryoruniquekey.Infact,itwasdoinganindexskip
scanontheprimarykeyindexbecausethefirstcolumnoftheindexwasnotinthefilterpredicates.TheSQL
statementwastunedbyaddingthefirstcolumnoftheprimarykeytothewhereclause,althougharange
predicatehadtobeused.

WhenaqueryorDMLstatementaffectsasinglerowinatablebyuseofauniquescanonaprimaryorunique
keyindex,thenparallelprocessingwillnotbeusedevenifitisenabledontheindexthattheconstraintis
definedon.Inotherwords,theOracleoptimizerwillnotuseparallelprocessingforsinglerowtransactionseven
ifitisavailable.Itisntfasterormoreefficienttodoso.Becauseoftheoverheadinvolvedinallocatingparallel
processes,uniqueDMLstatementsdonotbenefitfromthem,andtheoptimizerknowsthat.

Ontheotherhand,anindexrangescancanbenefitfromparallelprocesses,sotheoptimizerwillusethemifthe
indexscanisnotunique.Thismayormaynotbedesirable.Typically,Iwillenableparallelprocessingon
indexesiftheyarelargeenough,butnotiftheyaresmall.

WaitEvents

Atthesametimethatwehadaspikeinparallelprocesses,therewasaspikeinthewaiteventlibrarycache:
mutexX.Thefollowingoutputfrommydailyreporthasthehourslistedhorizontallyinsteadofvertically:
Waiteventsinseconds:
MetricNameH00H01H02H03H04H05H06H07H08H09H10H11H12H13H14H15
librarycache:mutexX203014152714169574068211069777

Onceagain,betweenthehoursof8:00AMand11:00AM,therewasaspike.LetsquerytheActiveSession
Historyonwaiteventandseewhatweget.

SELECT*FROM(
SELECT/*+PARALLEL*/
count(*)AScount,
user_id,program,module,machine,sql_id

FROMSYS.DBA_HIST_ACTIVE_SESS_HISTORY
WHEREsample_time>TO_DATE('25SEP201208:00:00','DDMONYYYYHH24:MI:SS')
ANDsample_time<TO_DATE('25SEP201211:10:00','DDMONYYYYHH24:MI:SS')
ANDevent='librarycache:mutexX'
GROUPBYuser_id,program,module,machine,sql_id
ORDERBYcount(*)DESC
)
WHERErownum<=20
/
COUNTUSER_IDPROGRAMMODULEMACHINESQL_ID

73327oracle@db_server(P009)osuser@server2(TNSV1V3)server2avb14fdyuwdhy
61327oracle@db_server(P012)osuser@server2(TNSV1V3)server2avb14fdyuwdhy
60327oracle@db_server(P004)osuser@server2(TNSV1V3)server2avb14fdyuwdhy
56327oracle@db_server(P008)osuser@server2(TNSV1V3)server2avb14fdyuwdhy
53327oracle@db_server(P011)osuser@server2(TNSV1V3)server2avb14fdyuwdhy
51327oracle@db_server(P005)osuser@server2(TNSV1V3)server2avb14fdyuwdhy
46327oracle@db_server(P014)osuser@server2(TNSV1V3)server2avb14fdyuwdhy
43327oracle@db_server(P003)osuser@server2(TNSV1V3)server2avb14fdyuwdhy
43327oracle@db_server(P006)osuser@server2(TNSV1V3)server2avb14fdyuwdhy
42327oracle@db_server(P010)osuser@server2(TNSV1V3)server2avb14fdyuwdhy
42327oracle@db_server(P007)osuser@server2(TNSV1V3)server2avb14fdyuwdhy
36327oracle@db_server(P001)osuser@server2(TNSV1V3)server2avb14fdyuwdhy
36327oracle@db_server(P012)osuser@server2(TNSV1V3)server266hqjnsynh3b5
33327oracle@db_server(P013)osuser@server2(TNSV1V3)server2avb14fdyuwdhy
32327oracle@db_server(P015)osuser@server2(TNSV1V3)server2avb14fdyuwdhy
32327oracle@db_server(P003)osuser@server2(TNSV1V3)server266hqjnsynh3b5
31327oracle@db_server(P000)osuser@server2(TNSV1V3)server2avb14fdyuwdhy
30327oracle@db_server(P011)osuser@server2(TNSV1V3)server266hqjnsynh3b5
30327oracle@db_server(P014)osuser@server2(TNSV1V3)server266hqjnsynh3b5
30327oracle@db_server(P002)osuser@server2(TNSV1V3)server2avb14fdyuwdhy

Thetoptenresultsallhavethesamesql_idastheUPDATEstatementthatcausedourparallelprocessspike.
Youwilloftenseeaperformanceproblemaffectmultiplemetrics.

TempTablespaceSpikes

ThefollowingoutputfrommydailyreportshowsaspikeinwritestotheTEMPtablespace.
Temptablespacemetrics:
MetricNameH00H01H02H03H04H05H06H07H08H09H10H11H12H13H14H15
tempstatxs_phyblkwrt22121251641317162356676261262
v$sort_segmentused_extents51000000012030000
ValuesareinGigabytes

Rememberthatthevaluefor"physicalblockswritten"isacumulativemetric,and"usedextents"isasnapshot
takenonthehour.Between1:00AMand2:00AM,therewere121GigabytesofdatawrittentotheTEMP
tablespace,butthesnapshotvaluesthatbracketthisintervalare1and0.Thisisbecausethedatais
continuouslywrittento,andthendeletedfrom,theTEMPtablespace.Theextentsdidnotpileupatthe
snapshottimes.ThisisnormalbehaviorfortheTEMPtablespace.

However,thespikeof121GigabytesofdatawrittenindicatesthatthereareSQLstatementthathavemultipass
joins(SeeCostBasedOracleFundamentalsbyJonathanLewis,Chapter12,"HashJoins").WecanusetheASH
viewtofindtheseSQLstatements.

SELECT*FROM(
SELECT/*+PARALLEL*/
count(*)AScount,
user_id,program,module,machine,sql_id
FROMSYS.DBA_HIST_ACTIVE_SESS_HISTORY
WHEREsample_time>TO_DATE('09OCT201208:00:00','DDMONYYYYHH24:MI:SS')
ANDsample_time<TO_DATE('09OCT201211:10:00','DDMONYYYYHH24:MI:SS')

ANDtemp_space_allocated>1024*1024*1024
GROUPBYuser_id,program,module,machine,sql_id
ORDERBYcount(*)DESC
)
WHERErownum<=20
/
COUNTUSER_IDPROGRAMMODULEMACHINESQL_ID

140401oracle@db_server(P005)user1@server2(TNSV1V3)server200gzy11w5tvtw
54401oracle@db_server(P037)user1@server2(TNSV1V3)server200gzy11w5tvtw
2753user2@server3(TNSV1V3)user2@server3(TNSV1V3)server31xrbpuk849qq3
753user2@server3(TNSV1V3)user2@server3(TNSV1V3)server3czujsw3fhp3hx
4293sqlplus@server3(TNSV1V3)SQL*Plusserver396t76t3utp5z6

TheconditionintheWHEREclausethatfilteredontemp_space_allocatedusedoneGigabytefortheliteral.You
maywanttochangethistosomethingmorerepresentativeforyourdatabase.

Thetoptwosessionsareparallelprocessesforthesamesql_id,00gzy11w5tvtw. Sincethesesessionsmake
upagoodmajorityofthesessionscountedforinthiscondition,thissqlstatementistheprimesuspect.Youcan
findoutjusthowmuchofthetemptablespacethatthesesessionsusedbylookingatindividualrowsfromthe
ASHview.

columntemp_space_allocatedformat999,999,999,999
SELECT/*+PARALLEL*/
sql_id,
TO_CHAR(sample_time,'DDMONYYYYHH24:MI:SS')ASsample_time,
temp_space_allocated
FROMSYS.DBA_HIST_ACTIVE_SESS_HISTORY
WHEREsample_time>TO_DATE('09OCT201208:00:00','DDMONYYYYHH24:MI:SS')
ANDsample_time<TO_DATE('09OCT201211:10:00','DDMONYYYYHH24:MI:SS')
ANDsql_id='00gzy11w5tvtw'
ORDERBYsample_time;
SQL_IDSAMPLE_TIMETEMP_SPACE_ALLOCATED

00gzy11w5tvtw09OCT201210:12:4813,849,591,808
00gzy11w5tvtw09OCT201210:12:5814,166,261,760
00gzy11w5tvtw09OCT201210:12:5812,156,141,568
00gzy11w5tvtw09OCT201210:13:0814,469,300,224
00gzy11w5tvtw09OCT201210:13:1812,156,141,568
00gzy11w5tvtw09OCT201210:13:2812,156,141,568
00gzy11w5tvtw09OCT201210:13:3812,156,141,568
00gzy11w5tvtw09OCT201210:13:4815,703,474,176
00gzy11w5tvtw09OCT201210:13:4812,156,141,568
00gzy11w5tvtw09OCT201210:13:5816,027,484,160
00gzy11w5tvtw09OCT201210:14:0812,156,141,568
00gzy11w5tvtw09OCT201210:14:1812,156,141,568
00gzy11w5tvtw09OCT201210:14:1816,667,115,520
00gzy11w5tvtw09OCT201210:14:2812,156,141,568
00gzy11w5tvtw09OCT201210:14:3812,156,141,568
00gzy11w5tvtw09OCT201210:14:4812,156,141,568
00gzy11w5tvtw09OCT201210:14:5817,996,709,888
00gzy11w5tvtw09OCT201210:15:0812,156,141,568
00gzy11w5tvtw09OCT201210:15:1818,660,458,496
00gzy11w5tvtw09OCT201210:15:5918,662,555,648
00gzy11w5tvtw09OCT201210:16:0918,662,555,648
00gzy11w5tvtw09OCT201210:16:1918,662,555,648
00gzy11w5tvtw09OCT201210:16:2918,662,555,648
00gzy11w5tvtw09OCT201210:16:3918,662,555,648

NoticethatthevaluetrackedbytheASHview,temp_space_allocated,isasnapshotvalue.Itgoesupanddown,
andpeaksatover18Gigabytes.Itmayhavewrittenmorethan18Gigofdatatothetemptablespace,butno
morethat18Gigofspacewasallocatedatanyonetime.Themetricfromthev$tempstatxsview,phyblkwrt
(physicalblockswritten)wasacumulativevalue.Thisillustratesthefactthatsimilarmetricsindifferentv$view
arenotnecessarilythesame.Nevertheless,wecanstillfindtheoffendingqueryandtrytotuneit.

SELECT*FROMsys.dba_hist_sqltextWHEREsql_id='00gzy11w5tvtw';

Theoffendingusercanfoundfromthesys.dba_usersview:
SELECTuser_id,usernameFROMsys.dba_usersWHEREuser_id=401;

Ifyouhaveuserswhosharethesameusernamewithotherusersandapplications,thenitcanbedifficultto
identifythepersonofinterestresponsiblefortheoffendingquery.If,ontheotherhand,yourcompany
followsgoodsecuritypracticesandhasdedicatedaccountsforeachpersonandeachapplication,thenyourjob
ofhelpingtheusersismucheasier.

PGASpikes

ThefollowingrowfrommydailyreporthasaspikeinPGAuse.
PGAinGigabytes:
MetricNameH00H01H02H03H04H05H06H07H08H09H10H11H12H13H14H15
totalPGAallocated19133525910881111321

ThestatistictotalPGAallocatedisasnapshotvaluetakeneverytimetheAWRtakesasnapshotofthev$
views.Hence,weonlyknowthevalueatthesnapshottimes,andnotbetweenthem.

AfterPGAisused,thePGAmemoryremainsallocatedforawhileincaseanothersessionneedsPGAmemory.
However,afteracertainamountoftime,whichisnotdocumented,thePGAmemorywillbereleasedifitisnot
reused.

Sincethespikeof19GigabytesintotalPGAallocatedisbelowthevalueoftheparameter
pga_aggregate_target,whichis50Gig,wearenothittingtheresourcelimitwiththismemoryspike.The
databaseisnotgoingtoexperienceperformanceproblemsasawhole.Tuningthisspikemayindicatea
conditionknownascompulsivetuningdisorder,whichisastateofcontinuedtuningwhentherearentany
morerealperformanceproblems.

AlthoughthedatabaseasawholemaynotsufferfromthisPGAspike,theSQLstatementthatcauseditcould
usesomehelp,andIamsupposedtospendpartofmytimeonproactivetuning.Ialsoneededanexampleof
howtotuneaPGAspike,andIvealreadyfixedalltherealperformanceproblems.So,wewillusetheASHto
findtheSQLstatementresponsibleforthisspike.

SELECT*FROM(
SELECT/*+PARALLEL*/
count(*)AScount,
user_id,program,module,machine,sql_id
FROMSYS.DBA_HIST_ACTIVE_SESS_HISTORY
WHEREsample_time>TO_DATE('09OCT201208:00:00','DDMONYYYYHH24:MI:SS')
ANDsample_time<TO_DATE('09OCT201211:10:00','DDMONYYYYHH24:MI:SS')
ANDpga_allocated>1024*1024*1024
GROUPBYuser_id,program,module,machine,sql_id
ORDERBYcount(*)DESC
)
WHERErownum<=20
/
COUNTUSER_IDPROGRAMMODULEMACHINESQL_ID

33293sqlplus@pzm3017(TNSV1V3)SQL*Pluspzm30173uhcz0dc55z6c

ThisquerycountsalltherecordedsessionsintheASHviewthathavepga_allocatedgreaterthanoneGigabyte.
Tofindtheactualpga_allocatedoftheSQLstatement,wecanquerytheASHonceagain.

columnpga_allocatedformat999,999,999,999

SELECT/*+PARALLEL*/
sql_id,
TO_CHAR(sample_time,'DDMONYYYYHH24:MI:SS')ASsample_time,
pga_allocated
FROMSYS.DBA_HIST_ACTIVE_SESS_HISTORY
WHEREsample_time>TO_DATE('29SEP201200:00:00','DDMONYYYYHH24:MI:SS')
ANDsample_time<TO_DATE('29SEP201201:10:00','DDMONYYYYHH24:MI:SS')
ANDsql_id='3uhcz0dc55z6c'
ORDERBYsample_time;

SQL_IDSAMPLE_TIMEPGA_ALLOCATED

3uhcz0dc55z6c29SEP201200:13:4595,633,408
3uhcz0dc55z6c29SEP201200:13:5595,633,408
3uhcz0dc55z6c29SEP201200:14:0595,633,408
3uhcz0dc55z6c29SEP201200:14:1595,633,408
3uhcz0dc55z6c29SEP201200:14:25407,453,696
3uhcz0dc55z6c29SEP201200:14:35642,924,544
3uhcz0dc55z6c29SEP201200:14:45828,194,816
3uhcz0dc55z6c29SEP201200:14:55918,700,032
3uhcz0dc55z6c29SEP201200:15:061,038,237,696
3uhcz0dc55z6c29SEP201200:15:161,131,692,032
3uhcz0dc55z6c29SEP201200:15:261,224,163,328
3uhcz0dc55z6c29SEP201200:15:361,315,454,976
3uhcz0dc55z6c29SEP201200:15:461,381,056,512
3uhcz0dc55z6c29SEP201200:15:561,381,056,512
3uhcz0dc55z6c29SEP201200:16:061,381,056,512
3uhcz0dc55z6c29SEP201200:16:161,381,056,512
3uhcz0dc55z6c29SEP201200:16:261,381,056,512
3uhcz0dc55z6c29SEP201200:16:361,381,056,512
3uhcz0dc55z6c29SEP201200:16:461,381,056,512
3uhcz0dc55z6c29SEP201200:16:561,381,056,512
3uhcz0dc55z6c29SEP201200:17:061,381,056,512
3uhcz0dc55z6c29SEP201200:17:161,381,056,512
3uhcz0dc55z6c29SEP201200:17:261,381,056,512
3uhcz0dc55z6c29SEP201200:17:361,381,056,512
3uhcz0dc55z6c29SEP201200:17:461,381,056,512
3uhcz0dc55z6c29SEP201200:17:561,381,056,512
3uhcz0dc55z6c29SEP201200:18:061,381,056,512
3uhcz0dc55z6c29SEP201200:18:161,381,056,512
3uhcz0dc55z6c29SEP201200:18:261,381,056,512
3uhcz0dc55z6c29SEP201200:18:361,381,056,512
3uhcz0dc55z6c29SEP201200:18:461,381,056,512
3uhcz0dc55z6c29SEP201200:18:5649,299,456
3uhcz0dc55z6c29SEP201200:19:0649,299,456
3uhcz0dc55z6c29SEP201200:19:1649,561,600
3uhcz0dc55z6c29SEP201200:19:2649,561,600
3uhcz0dc55z6c29SEP201200:19:3645,301,760
3uhcz0dc55z6c29SEP201200:19:4649,561,600

Thevalueofpga_allocatedcangoupanddownforaSQLstatement.ForthisSQL,thepga_allocateddoesnot
gomuchhigherthanoneGigabyte.OtherSQLstatementmusthavecontributedtotheTotalPGAAllocated
spikeof19Gig,buttheyneverhadmorethan1GigofPGA,sotheywerenotinourASHqueryresults.Lowering
thefilterconditiontolessthan1GigwouldfindtheseotherSQLstatements,buttherewouldbealotofthem
withlessthan1GigofPGAeach.Tuningallofthemwouldtakealotoftimeforlittlereturnonperformance
improvement.Thisdoesnotsatisfymycompulsivetuningdisorder,soIwilllookforperformanceproblems
elsewhere.

Вам также может понравиться