Vous êtes sur la page 1sur 5

17/7/2014 Le blog Oracle d'Ahmed AANGOUR: Trace 10046 et TKPROF

http://ahmedaangour.blogspot.com/2011/01/trace-10046-et-tkprof.html 1/5
Unblogpourcontribuerlacommunautfrancophoned'Oraclesurlesthmessuivants:ConceptsOracleSQL/PLSQLAnalysedesproblmesdeperformance
LeblogOracled'AhmedAANGOUR
mardi18janvier2011
Trace10046etTKPROF
OracleoffrelapossibilitdetracerdansunfichiertouteslesrequtesSQLetblocsPL/SQLeffectusparunesessiondonne.Cettetracepermetdercuprerles
informationssurlesstatistiquesd'excutiondecesrequtes:tempsd'excution,tempsCPU,tempsd'attente,waitevents,nombredelectureslogiques,nombredelectures
physiquesetc.
Cesontcesinformationsquivontnouspermettred'analyserlesproblmesdeperformanced'uneapplicationdonne.
Cefichiertracegnrestunpeucompliqutudierdanssonformatbrute.L'utilitaireTKPROFajustementpourbutdegnrerunrapportpartirdecefichierpourle
rendrepluslisible.
Voyonsd'abordcommentgnrerunetraceSQL10046.
Pouractiverletracingauniveaudemasessionj'utiliseengnralelescommandessuivantes:
ALTER SESSION SET timed_statistics = TRUE;
ALTER SESSION SET max_dump_file_size = unlimited;
ALTER SESSION SET TRACEFILE_IDENTIFIER = 'Ahmed_10046_sql_trace';
ALTER SESSION SET events '10046 trace name context forever, level 12';
PardfautleparamtreTIMED_STATISTICSestTRUEmaisparscuritjel'activeauniveausessionaucasoceparamtreaittdsactivauniveaudel'instance.
LeparamtreMAX_DUMP_FILE_SIZEdterminelataillemaximalequepeutatteindrelefichiertrace.JelemetUNLIMITEDaucasoauniveaudelabaseleDBA
aitmisunevaleurlimiteinsuffisante.
PourpouvoirretrouverfacilementmonfichiertracejemodifiegalementlavaleurduTRACEFILE_IDENTIFIER.Lenomdufichierdetracegnrcontiendraainsien
partiecequej'aimiscommevaleurpourceparamtre.
Ladernirecommandeactiveletracingdemasession.LeparamtreLEVEL12indiquequejesouhaitetracerleswaiteventsainsiquelesinformationsauniveaudes
bindvariables.
Exemple:
D:\oracle\product\11.2.0>sqlplus scott/tiger
SQL*Plus: Release 11.2.0.1.0 Production on Lun. Janv. 17 17:53:08 2011
Copyright (c) 1982, 2010, Oracle. All rights reserved.
Connect :
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> drop table t1 purge;
Table supprime.
SQL> create table t1 as select rownum num,a.* from dba_objects a;
Table cre.
SQL> ALTER SESSION SET TRACEFILE_IDENTIFIER = 'Ahmed_10046_sql_trace';
Session modifie.
SQL> ALTER SESSION SET timed_statistics = TRUE;
Session modifie.
SQL> ALTER SESSION SET max_dump_file_size = unlimited;
Session modifie.
SQL> ALTER SESSION SET events '10046 trace name context forever, level 12';
Session modifie.
SQL> declare
2 v_row_t1 t1%rowtype;
3 begin
4
5 for i in 1..100
6 loop
7 select * into v_row_t1 from t1 where num=i;
8 end loop;
9
0
Plus Blogsuivant
17/7/2014 Le blog Oracle d'Ahmed AANGOUR: Trace 10046 et TKPROF
http://ahmedaangour.blogspot.com/2011/01/trace-10046-et-tkprof.html 2/5
10 end;
11 /
Procdure PL/SQL termine avec succs.
SQL> ALTER SESSION SET events '10046 trace name context off';
Session modifie.
Ladernirecommandecidessuspermetdedsactiverletracing.
JepeuxmaintenantallerrcuprermonfichiertracequisetrouvedanslerpertoiredfinieparleparamtreUSER_DUMP_DEST:
SQL> sho parameter user_dump
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
user_dump_dest string d:\oracle\product\11.2.0\diag\
rdbms\orclp850\orclp850\trace
Voyonsunextraitducontenudelatrace"brutedepomme"
PARSING IN CURSOR #4 len=31 dep=1 uid=84 oct=3 lid=84 tim=3649721690252 hv=3779410954 ad='221a3fa8' sqlid='ask3fx3hnag0a'
SELECT * FROM T1 WHERE NUM=:B1
END OF STMT
BINDS #4:
Bind#0
oacdty=02 mxl=22(22) mxlc=00 mal=00 scl=00 pre=00
oacflg=03 fl2=206001 frm=00 csi=00 siz=24 off=0
kxsbbbfp=0f19c50c bln=22 avl=02 flg=05
value=2
EXEC #4:c=0,e=195,p=0,cr=0,cu=0,mis=0,r=0,dep=1,og=1,plh=3617692013,tim=3649721690403
WAIT #4: nam='direct path read' ela= 591 file number=4 first dba=531 block cnt=13 obj#=74591 tim=3649721691313
WAIT #4: nam='direct path read' ela= 869 file number=4 first dba=545 block cnt=15 obj#=74591 tim=3649721692358
WAIT #4: nam='direct path read' ela= 488 file number=4 first dba=561 block cnt=15 obj#=74591 tim=3649721692995
WAIT #4: nam='direct path read' ela= 466 file number=4 first dba=577 block cnt=15 obj#=74591 tim=3649721693619
WAIT #4: nam='direct path read' ela= 445 file number=4 first dba=593 block cnt=15 obj#=74591 tim=3649721694261
WAIT #4: nam='direct path read' ela= 494 file number=4 first dba=609 block cnt=15 obj#=74591 tim=3649721694905
WAIT #4: nam='direct path read' ela= 449 file number=4 first dba=625 block cnt=15 obj#=74591 tim=3649721695551
WAIT #4: nam='direct path read' ela= 368 file number=4 first dba=641 block cnt=15 obj#=74591 tim=3649721696094
WAIT #4: nam='direct path read' ela= 19977 file number=4 first dba=770 block cnt=30 obj#=74591 tim=3649721716234
WAIT #4: nam='direct path read' ela= 2939 file number=4 first dba=800 block cnt=32 obj#=74591 tim=3649721719585
WAIT #4: nam='direct path read' ela= 4390 file number=4 first dba=832 block cnt=32 obj#=74591 tim=3649721724244
WAIT #4: nam='direct path read' ela= 3115 file number=4 first dba=864 block cnt=32 obj#=74591 tim=3649721727616
WAIT #4: nam='direct path read' ela= 3090 file number=4 first dba=898 block cnt=30 obj#=74591 tim=3649721730985
WAIT #4: nam='direct path read' ela= 4408 file number=4 first dba=928 block cnt=32 obj#=74591 tim=3649721735640
WAIT #4: nam='direct path read' ela= 3124 file number=4 first dba=960 block cnt=32 obj#=74591 tim=3649721739013
WAIT #4: nam='direct path read' ela= 4385 file number=4 first dba=992 block cnt=32 obj#=74591 tim=3649721743674
WAIT #4: nam='direct path read' ela= 3140 file number=4 first dba=1026 block cnt=30 obj#=74591 tim=3649721747073
WAIT #4: nam='direct path read' ela= 4169 file number=4 first dba=1056 block cnt=32 obj#=74591 tim=3649721751712
WAIT #4: nam='direct path read' ela= 3051 file number=4 first dba=1088 block cnt=32 obj#=74591 tim=3649721755071
WAIT #4: nam='direct path read' ela= 3120 file number=4 first dba=1120 block cnt=32 obj#=74591 tim=3649721758446
WAIT #4: nam='direct path read' ela= 4396 file number=4 first dba=1154 block cnt=30 obj#=74591 tim=3649721763115
WAIT #4: nam='direct path read' ela= 3126 file number=4 first dba=1184 block cnt=32 obj#=74591 tim=3649721766486
WAIT #4: nam='direct path read' ela= 4406 file number=4 first dba=1216 block cnt=32 obj#=74591 tim=3649721771141
WAIT #4: nam='direct path read' ela= 3113 file number=4 first dba=1248 block cnt=32 obj#=74591 tim=3649721774514
WAIT #4: nam='direct path read' ela= 3123 file number=4 first dba=1282 block cnt=30 obj#=74591 tim=3649721777891
WAIT #4: nam='direct path read' ela= 4416 file number=4 first dba=1312 block cnt=32 obj#=74591 tim=3649721782548
WAIT #4: nam='direct path read' ela= 3106 file number=4 first dba=1344 block cnt=32 obj#=74591 tim=3649721785917
WAIT #4: nam='direct path read' ela= 4400 file number=4 first dba=1376 block cnt=32 obj#=74591 tim=3649721790574
WAIT #4: nam='direct path read' ela= 3102 file number=4 first dba=1410 block cnt=30 obj#=74591 tim=3649721793944
WAIT #4: nam='direct path read' ela= 3141 file number=4 first dba=1440 block cnt=32 obj#=74591 tim=3649721797323
WAIT #4: nam='direct path read' ela= 4367 file number=4 first dba=1472 block cnt=32 obj#=74591 tim=3649721801989
WAIT #4: nam='direct path read' ela= 3024 file number=4 first dba=1504 block cnt=32 obj#=74591 tim=3649721805349
WAIT #4: nam='direct path read' ela= 4409 file number=4 first dba=1538 block cnt=30 obj#=74591 tim=3649721810028
WAIT #4: nam='direct path read' ela= 3098 file number=4 first dba=1568 block cnt=32 obj#=74591 tim=3649721813378
WAIT #4: nam='direct path read' ela= 3104 file number=4 first dba=1600 block cnt=32 obj#=74591 tim=3649721816745
WAIT #4: nam='direct path read' ela= 4439 file number=4 first dba=1632 block cnt=32 obj#=74591 tim=3649721821436
WAIT #4: nam='direct path read' ela= 3087 file number=4 first dba=1666 block cnt=30 obj#=74591 tim=3649721824781
WAIT #4: nam='direct path read' ela= 4384 file number=4 first dba=1696 block cnt=32 obj#=74591 tim=3649721829436
WAIT #4: nam='direct path read' ela= 1773 file number=4 first dba=1728 block cnt=19 obj#=74591 tim=3649721831424
FETCH #4:c=31250,e=141113,p=1081,cr=1084,cu=0,mis=0,r=1,dep=1,og=1,plh=3617692013,tim=3649721831583
CLOSE #4:c=0,e=5,dep=1,type=3,tim=3649721831678
=====================
Vousconstatezqu'ils'agitd'unepartiedelatraceconcernantl'excutiondelarequte"SELECT*FROMT1WHERENUM=:B1"pourlavaleurNUM=2(voirpartie
intitulBINDS).L'attentepourcetteexcutionconcernelesaccsdisques."DIRECTPATHREAD"indiquequ'ils'agitd'accsdisquesenmodedirectc'estdiresans
passerparlebuffercache.En10gj'auraiseupluttdu"DB_FILESCATTEREDREAD".Cetestvalidebienqu'en11gOraclepeutfairedudirectI/Opourlesaccs
multiblocks(fasttablescan,fastfullindexscan)..
Onvoitaussiquelaplupartdutemps32blockssontrcupresparI/O(blockcnt=32),amatchbienaveclavaleurdemonparamtre
DB_FILE_MULTIBLOCK_READ_COUNTquiestpositionn32surmabase.
MaintenantgnronslerapportTKPROFpourcefichiertrace:
TKPROF orclp850_ora_3588_Ahmed_10046_sql_trace.trc TKPROF_REPORT_17012011.txt sort=exeela aggregate=YES
Lepremierparamtrecorrespondaunomdufichiertracequ'onveuttraiter.Le2meparamtrecorrespondaunomqu'onveutdonneraufichierTKPROFdesortie.
LeparamtreSORTindiquelamaniredontonveutquelesrequtesSQLdanslerapportTKPROFsoienttries.Iciils'agitd'untripartempsconsommpourlaphase
EXECUTION.
LeparamtreAGGREGATEindiquesil'onveutaggrgerlesrequtesidentiquesoupas.
VouspouvezafficherlalistedetouslesparamtresdisponiblesentapantlacommandeTKPROFsansparamtres:
D:\oracle\product\11.2.0>tkprof
Usage: tkprof tracefile outputfile [explain= ] [table= ]
[print= ] [insert= ] [sys= ] [sort= ]
17/7/2014 Le blog Oracle d'Ahmed AANGOUR: Trace 10046 et TKPROF
http://ahmedaangour.blogspot.com/2011/01/trace-10046-et-tkprof.html 3/5
table=schema.tablename Use 'schema.tablename' with 'explain=' option.
explain=user/password Connect to ORACLE and issue EXPLAIN PLAN.
print=integer List only the first 'integer' SQL statements.
aggregate=yes|no
insert=filename List SQL statements and data inside INSERT statements.
sys=no TKPROF does not list SQL statements run as user SYS.
record=filename Record non-recursive statements found in the trace file.
waits=yes|no Record summary for any wait events found in the trace file.
sort=option Set of zero or more of the following sort options:
prscnt number of times parse was called
prscpu cpu time parsing
prsela elapsed time parsing
prsdsk number of disk reads during parse
prsqry number of buffers for consistent read during parse
prscu number of buffers for current read during parse
prsmis number of misses in library cache during parse
execnt number of execute was called
execpu cpu time spent executing
exeela elapsed time executing
exedsk number of disk reads during execute
exeqry number of buffers for consistent read during execute
execu number of buffers for current read during execute
exerow number of rows processed during execute
exemis number of library cache misses during execute
fchcnt number of times fetch was called
fchcpu cpu time spent fetching
fchela elapsed time fetching
fchdsk number of disk reads during fetch
fchqry number of buffers for consistent read during fetch
fchcu number of buffers for current read during fetch
fchrow number of rows fetched
userid userid of user that parsed the cursor
VoyonsmaintenantcequecontientlerapportTKPROFpournotreexemple.
L'enttedufichiercontientlesinformationssuivantes:
TKPROF: Release 11.2.0.1.0 - Development on Mar. Janv. 18 10:44:51 2011
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Trace file: orclp850_ora_3588_Ahmed_10046_sql_trace.trc
Sort options: exeela
********************************************************************************
count = number of times OCI procedure was executed
cpu = cpu time in seconds executing
elapsed = elapsed time in seconds executing
disk = number of physical reads of buffers from disk
query = number of buffers gotten for consistent read
current = number of buffers gotten in current mode (usually for update)
rows = number of rows processed by the fetch or execute call
********************************************************************************
Onadesinformationssurlaversiondelabase,lenomdufichiertraceutilispourcerapport,l'optionSORTutilisetunedfinitiondesindicateursqu'onretrouvera
danslerapport.Parexempleonvoitquel'indicateurDISKcorrepsondaunombred'I/Oeffectuspourunerequte.
Lasuitedurapportnousdonnelesinformationssurlarequtequ'onaexcut100foisdansnotreexempleprcdent:
SQL ID: ask3fx3hnag0a
Plan Hash: 3617692013
SELECT *
FROM
T1 WHERE NUM=:B1
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.00 0.00 0 0 0 0
Execute 100 0.04 0.03 0 1 0 0
Fetch 100 1.53 21.57 108100 108400 0 100
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 201 1.57 21.60 108100 108401 0 100
Misses in library cache during parse: 1
Optimizer mode: ALL_ROWS
Parsing user id: 84 (recursive depth: 1)
Rows Row Source Operation
------- ---------------------------------------------------
1 TABLE ACCESS FULL T1 (cr=1084 pr=1081 pw=0 time=0 us cost=303 size=2640 card=12)
Elapsed times include waiting on following events:
Event waited on Times Max. Wait Total Waited
---------------------------------------- Waited ---------- ------------
reliable message 1 0.00 0.00
enq: KO - fast object checkpoint 1 0.00 0.00
direct path read 3843 0.26 19.77
asynch descriptor resize 96 0.00 0.00
********************************************************************************
Section"statistiquesd'excution"
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.00 0.00 0 0 0 0
Execute 100 0.04 0.03 0 1 0 0
Fetch 100 1.53 21.57 108100 108400 0 100
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 201 1.57 21.60 108100 108401 0 100
Leslignesdutableaucorrespondentaux3phasesd'unerequteSQL:
17/7/2014 Le blog Oracle d'Ahmed AANGOUR: Trace 10046 et TKPROF
http://ahmedaangour.blogspot.com/2011/01/trace-10046-et-tkprof.html 4/5
Parsing:phasedurantlaquellelepland'excutionestcalcul
Execute:phasedurantlaquellelarequteestexcute(concernesurtoutlesrequtesDML)
Fetch:phasedurantlaquelleleslignesdsiressontretournes(concernesurtoutlesrequtesSELECT)
Pourchacunedecesphasesonadesinformationssurletempstotalconsomm(colonneELAPSED),letempsCPUconsomm(colonneCPU),lenombredelectures
physiques(colonneDISK),lenombrede
lectureslogiques(colonneQUERY+CURRENT)etlenombredelignestraites(colonneROWS).
Dansnotreexempleonvoitquelarequten'atparsequ'uneseulefois(COUNTpourPARSE=1)pour100excutions(COUNTpourEXECUTE=100).Sionavait
un"countpourPARSE"de100pour100excutionsaauraitclairementmisenvidenceunedfaillanceauniveaudel'utilisationdesvariablesbindesdansnotre
application.
Onvoitaussiqueles100requtessesontexcutesen26.6secondesdont1.57seccorresponddutempsCPU.Lerestecorrespondautempsd'attentequ'onretrouve
plusbasdanslapartie"EVENTWAITEDON".
Section"pland'excution"
Rows Row Source Operation
------- ---------------------------------------------------
1 TABLE ACCESS FULL T1 (cr=1084 pr=1081 pw=0 time=0 us cost=303 size=2640 card=12)
Aprsletableaudesstatistiquesd'excutiononretrouveleplanrellementutilisaumomentdel'excutiondelarequteavecuncertainnombred'informations:
ROWS:correspondauxlignesrellementtraiteschaqueoprationduplan
CR:correspondauxnombredelogicalreads.
PR:correspondauxnombredephysicalreads.
PW:correspondauxnombredephysicalwrites.
TIME:correspondautempspasssurcetteoprationenmicrosecondes
COST=correspondaucotpourcetteopration
SIZE:correspondaunombred'octectstraitslorsdecetteoperation.
CARD:correspondaunombredelignesestimesparleCBO.
Encomparantleslignesrellementprocesses(ROWS)etlenombredelignesestimesparleCBO(card)onpeutfacilementdtecterquelleestlapartieduplano
l'optimiseurs'esttromp.
Anoteraussiquelesstatistiquessontcellespouruneseuleexcution,c'estpourcelaquelenombredephysicalreadsestde1081(=108401/100).
Section"vnementsd'attente"
Elapsed times include waiting on following events:
Event waited on Times Max. Wait Total Waited
---------------------------------------- Waited ---------- ------------
reliable message 1 0.00 0.00
enq: KO - fast object checkpoint 1 0.00 0.00
direct path read 3843 0.26 19.77
asynch descriptor resize 96 0.00 0.00
Aprslepland'excutiononpeutvoirlalistedesvnementsd'attenteassocisl'excutiondecetterequte.Onnoteiciquesur21.6secondesOracleapass19.77
secondessurdel'attented'I/O.
Pourchaquewaiteventonretrouvelesinformationssuivantes:
TimesWaited:Nombredefoisoonaattendusurcetvnement
Max.Wait:Tempsd'attentemaximalconstatpourcetvnement
TotalWaited:Tempstotalensecondesconstatpourcetvnement
Ensuitepourchaquerequteonretrouveralesmmessectionsquejeviensdedcriresavoir:tableaudesstatsd'excution,planreld'excutionetdtaildestemps
d'attente.
Alafindurapportonretrouveletotaldesstatistiquescollectesdanslatrace:
OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 2 0.00 0.01 0 3 0 0
Execute 2 0.03 0.03 0 108509 0 1
Fetch 0 0.00 0.00 0 0 0 0
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 4 0.03 0.05 0 108512 0 1
Misses in library cache during parse: 1
Elapsed times include waiting on following events:
Event waited on Times Max. Wait Total Waited
---------------------------------------- Waited ---------- ------------
SQL*Net message to client 2 0.00 0.00
SQL*Net message from client 2 110.55 113.51
OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 4 0.01 0.00 0 0 0 0
Execute 119 0.04 0.03 0 1 0 0
Fetch 135 1.56 21.82 108453 108511 0 117
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 258 1.62 21.86 108453 108512 0 117
17/7/2014 Le blog Oracle d'Ahmed AANGOUR: Trace 10046 et TKPROF
http://ahmedaangour.blogspot.com/2011/01/trace-10046-et-tkprof.html 5/5
Articleplusrcent Articleplusancien Accueil
Inscription:Publierlescommentaires(Atom)
PubliparAhmedAANGOUR15:27
Misses in library cache during parse: 2
Misses in library cache during execute: 1
Elapsed times include waiting on following events:
Event waited on Times Max. Wait Total Waited
---------------------------------------- Waited ---------- ------------
db file scattered read 43 0.02 0.16
db file sequential read 11 0.01 0.03
reliable message 1 0.00 0.00
enq: KO - fast object checkpoint 1 0.00 0.00
direct path read 3843 0.26 19.77
asynch descriptor resize 96 0.00 0.00
103 user SQL statements in session.
18 internal SQL statements in session.
121 SQL statements in session.
Onconstatequelesrequtesrcursivesetnonrcursivescorrespondent2sectionsdistinctes.
CONCLUSION:
UnrapportTKPROFpartird'unetrace10046estd'uneaideinestimablepouranalyserlesproblmesdeperformances.Ilpeutnousaidermettreenvidenceles
requteslesplusconsommatrices,lesproblmesdehardparses,lesvnementsd'attenteslesplusimportants.Ilpermetaussid'avoirpourchaquerequteleplan
rellementexcutaveclescardinalitsrellementprocessespourchaqueopration.Aussietsurtoutc'estunoutilgratuit.Ilpeutdonctreutilissurn'importequelle
basemmesivousn'avezpaspaydelicencediagnosticpackoutuningpack.
Saisissezvotrecommentaire
Commentaire: CompteGoogle
Publier

Aperu
Aucuncommentaire:
Enregistreruncommentaire
ModleSimple.FourniparBlogger.