当前位置:网站首页>Oracle Performance Analysis 3: introduction to tkprof

Oracle Performance Analysis 3: introduction to tkprof

2022-07-06 21:57:00 Full stack programmer webmaster

Hello everyone , I meet you again , I'm the king of the whole stack .

tkprof It is Oracle It comes with a command in line tool , Its main function is to trace the original file to the type of text file , for example , The easiest way , Use the following :

tkprof ly_ora_128636.trc ly_ora_128636.txt

tkprof With many parameters , In most cases , Using these parameters will be very helpful for your analysis .

tkprof Parameters

Suppose it is executed without any parameters tkprof, It will print out the complete parameter list , With a simple description . The following is a description of the parameters :

explain For every one SQL Statement provides a run plan .

This parameter needs to specify the user 、 password . You can also specify the database connection string , Such as :explain=user/[email protected]_string perhaps explain=user/password.

table Carton explain Parameters , Used to specify the table used to generate the run plan , It is usually not necessary to specify , Only when users cannot create tables ( In the absence of create table jurisdiction ). print Used to restrict output file generation SQL Number of statements , such as :print=10. aggregate Specify whether to process the same content separately SQL sentence . By default, it is not handled separately . Designated as aggregate=no, Look at each one alone SQL sentence .

insert Generate SQL Script ,SQL Scripts can be used to store information into databases ,SQL The name of the script is specified by the parameter , Such as :insert=load.sql. sys Appoint sys User executed SQL Whether the statement is also written to the output file , Default yes.

record Generate SQL Script . Included in trace All non recursive statements found in the file , The script name is specified by the parameter itself . such as :record=replay.sql.

waits Whether to add information about waiting events , Default join . sort Specify the SQL Order of statements . The default is trace Found in the document SQL The order .

Here's an example :

tkprof {input trace file} {output file} sys=no sort=prsela,exeela,fchela

prsela: The first cursor parsing takes time exeela: Time spent running against cursor fchela: The time it takes the cursor to get the data row

tkprof Output

The output file has a header , There are descriptions of parameters . For example, the following :

**********************************************************************
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
**********************************************************************

count: Number of database calls run cpu: Processing data calls takes CPU Time , In seconds elapsed: Total time spent processing database calls , In seconds disk: Number of data blocks physically read , Suppose it is greater than the number of logical reads (disk>query+current), Indicates that a temporary table space is used .

query: The number of fast reads from the cache logic in consistent mode . Used as a query . current: The number of blocks read from the cache logic in the current mode , be used for insert、delete、merge as well as update Wait for the operation . rows: Number of data rows processed . The query represents the number of rows obtained . and insert、delete、merge as well as update Etc. indicates the number of rows affected .

Here is a detailed example :

call     count       cpu    elapsed       disk      query    current        rows
------- ------  -------- ---------- ---------- ---------- ----------  ----------
Parse        1      0.00       0.00          0          0          0           0
Execute      1      0.00       0.00          0          0          0           0
Fetch      501      0.03       0.15          0       1465          0       50001
------- ------  -------- ---------- ---------- ---------- ----------  ----------
total      503      0.03       0.15          0       1465          0       50001

The above corresponds to parse、execute and fetch this 3 Stages . stay fetch Phase is running 501 Time fetch, Got 50001 Row data , Every time fetch obtain 100 Row data . Next is :

Misses in library cache during parse: 1
Misses in library cache during execute: 1
Optimizer mode: ALL_ROWS
Parsing user id: 5 

The first two lines indicate the number of hard parsing that occurs in the parsing and running call phases . Suppose there is no hard parsing . There is no . “Optimizer mode” Represents the optimizer pattern .

“Parsing user id” It's parsing SQL The user of the statement . After that, you can see the operation plan , Here is just a simple explanation :

Rows     Row Source Operation
-------  ---------------------------------------------------
  50001  COUNT STOPKEY (cr=1465 pr=0 pw=0 time=300125 us)
  50001   VIEW  (cr=1465 pr=0 pw=0 time=200088 us)
  50001    INDEX FULL SCAN IDX_HISTORYALARM$CLEAR (cr=1465 pr=0 pw=0 time=100049 us)(object id 53743)

cr: Number of data blocks read out logically in consistency mode pr: The number of data blocks physically read from the disk pw: Number of data blocks physically written to disk time: The total time-consuming in subtle terms , Note that the data is inaccurate cost: The evaluation cost of the operation ( only 11g To provide ) size: The predicted amount of data returned by the operation ( Number of bytes )( only 11g To provide ) card: The expected number of rows returned by the operation ( only 11g To provide )

Next is waiting for the event :

  Event waited on                             Times Waited   Max. Wait  Total Waited
  ----------------------------------------------------------------------------------
  SQL*Net message to client                        502           0.00          0.00
  SQL*Net message from client                      502           0.08         15.42
  SQL*Net more data to client                      500           0.00          0.01

Times Waited: Waiting time takes up time Max. Wait: Maximum waiting time for a single waiting event , The unit is in seconds Total Waited: Total waiting seconds for a waiting event . Imprecise

Here you can see the waiting events encountered during the operation , Through the analysis of these waiting events . It helps you understand what resources you are waiting for , The bottleneck of query , Targeted optimization .

In the Oracle Database Reference In a short narrative, the manual in the appendix describes the most common waiting events .

Copyright notice : This article is the original article of the blogger . Blog , Do not reprint without permission .

Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/117071.html Link to the original text :https://javaforall.cn

原网站

版权声明
本文为[Full stack programmer webmaster]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/187/202207061343426110.html