+ All Categories
Home > Documents > Sr.$Technical$Consultant - Redgate€¦ · How$to$Gather$SQL$Resource$...

Sr.$Technical$Consultant - Redgate€¦ · How$to$Gather$SQL$Resource$...

Date post: 04-Jun-2020
Category:
Upload: others
View: 2 times
Download: 0 times
Share this document with a friend
49
How to Gather SQL Resource Consump6on Metrics in Oracle Karen Morton Sr. Technical Consultant 1
Transcript
Page 1: Sr.$Technical$Consultant - Redgate€¦ · How$to$Gather$SQL$Resource$ Consump6on$Metrics$in$Oracle$ Karen$Morton$ Sr.$Technical$Consultant 1

How  to  Gather  SQL  Resource  Consump6on  Metrics  in  Oracle  

Karen  Morton  Sr.  Technical  Consultant  

1  

Page 2: Sr.$Technical$Consultant - Redgate€¦ · How$to$Gather$SQL$Resource$ Consump6on$Metrics$in$Oracle$ Karen$Morton$ Sr.$Technical$Consultant 1

karenmorton.blogspot.com  

karen_morton  

[email protected]  

Page 3: Sr.$Technical$Consultant - Redgate€¦ · How$to$Gather$SQL$Resource$ Consump6on$Metrics$in$Oracle$ Karen$Morton$ Sr.$Technical$Consultant 1

If  you  can’t  measure  it,  you  can’t  manage  it.    

―David  Garvin    

3  

Page 4: Sr.$Technical$Consultant - Redgate€¦ · How$to$Gather$SQL$Resource$ Consump6on$Metrics$in$Oracle$ Karen$Morton$ Sr.$Technical$Consultant 1

There  are  two  types  of  performance  problems  in  this  

world...  

Page 5: Sr.$Technical$Consultant - Redgate€¦ · How$to$Gather$SQL$Resource$ Consump6on$Metrics$in$Oracle$ Karen$Morton$ Sr.$Technical$Consultant 1

1    Response  6me  

problems.  

Page 6: Sr.$Technical$Consultant - Redgate€¦ · How$to$Gather$SQL$Resource$ Consump6on$Metrics$in$Oracle$ Karen$Morton$ Sr.$Technical$Consultant 1

2    Inefficiencies  that  aren’t  response  

6me  problems.  Yet.  

Page 7: Sr.$Technical$Consultant - Redgate€¦ · How$to$Gather$SQL$Resource$ Consump6on$Metrics$in$Oracle$ Karen$Morton$ Sr.$Technical$Consultant 1

Therefore...  

Page 8: Sr.$Technical$Consultant - Redgate€¦ · How$to$Gather$SQL$Resource$ Consump6on$Metrics$in$Oracle$ Karen$Morton$ Sr.$Technical$Consultant 1

 You  must  be  able  to  aOack  response  6me  problems  for  

specific  tasks  that  the  business  cares  about...  

Page 9: Sr.$Technical$Consultant - Redgate€¦ · How$to$Gather$SQL$Resource$ Consump6on$Metrics$in$Oracle$ Karen$Morton$ Sr.$Technical$Consultant 1

…even  if  they  are  inefficiencies  that  aren’t  yet  no6ceable  as  user  

response  6me  problems.  

Page 10: Sr.$Technical$Consultant - Redgate€¦ · How$to$Gather$SQL$Resource$ Consump6on$Metrics$in$Oracle$ Karen$Morton$ Sr.$Technical$Consultant 1

Why  should  you  care?  

Page 11: Sr.$Technical$Consultant - Redgate€¦ · How$to$Gather$SQL$Resource$ Consump6on$Metrics$in$Oracle$ Karen$Morton$ Sr.$Technical$Consultant 1
Page 12: Sr.$Technical$Consultant - Redgate€¦ · How$to$Gather$SQL$Resource$ Consump6on$Metrics$in$Oracle$ Karen$Morton$ Sr.$Technical$Consultant 1

Because      

costs  you  money  

waste  

Page 13: Sr.$Technical$Consultant - Redgate€¦ · How$to$Gather$SQL$Resource$ Consump6on$Metrics$in$Oracle$ Karen$Morton$ Sr.$Technical$Consultant 1

TCO  $$  

Waste  

Labor  $$  

Hardware  $$  

SoWware  $$  

Page 14: Sr.$Technical$Consultant - Redgate€¦ · How$to$Gather$SQL$Resource$ Consump6on$Metrics$in$Oracle$ Karen$Morton$ Sr.$Technical$Consultant 1

And  waste...  

Page 15: Sr.$Technical$Consultant - Redgate€¦ · How$to$Gather$SQL$Resource$ Consump6on$Metrics$in$Oracle$ Karen$Morton$ Sr.$Technical$Consultant 1

...makes  other  work  go  slower…  

Page 16: Sr.$Technical$Consultant - Redgate€¦ · How$to$Gather$SQL$Resource$ Consump6on$Metrics$in$Oracle$ Karen$Morton$ Sr.$Technical$Consultant 1

...even  your  fast  stuff  

Page 17: Sr.$Technical$Consultant - Redgate€¦ · How$to$Gather$SQL$Resource$ Consump6on$Metrics$in$Oracle$ Karen$Morton$ Sr.$Technical$Consultant 1

Why  guess?  When  you  can  know.  

Page 18: Sr.$Technical$Consultant - Redgate€¦ · How$to$Gather$SQL$Resource$ Consump6on$Metrics$in$Oracle$ Karen$Morton$ Sr.$Technical$Consultant 1

Resource  Consump6on  Metrics  

Page 19: Sr.$Technical$Consultant - Redgate€¦ · How$to$Gather$SQL$Resource$ Consump6on$Metrics$in$Oracle$ Karen$Morton$ Sr.$Technical$Consultant 1

   Time                  

Resources  &  

Page 20: Sr.$Technical$Consultant - Redgate€¦ · How$to$Gather$SQL$Resource$ Consump6on$Metrics$in$Oracle$ Karen$Morton$ Sr.$Technical$Consultant 1

Start  simple  with  

AUTOTRACE  

Page 21: Sr.$Technical$Consultant - Redgate€¦ · How$to$Gather$SQL$Resource$ Consump6on$Metrics$in$Oracle$ Karen$Morton$ Sr.$Technical$Consultant 1

SQL>  SET  TIMING  ON    SQL>  ALTER  SESSION  SET        STATISTICS_LEVEL  =  ALL;  

Can  also  use  /*+  gather_plan_sta;s;cs  */  hint  

Page 22: Sr.$Technical$Consultant - Redgate€¦ · How$to$Gather$SQL$Resource$ Consump6on$Metrics$in$Oracle$ Karen$Morton$ Sr.$Technical$Consultant 1

SQL>  SET  AUTOTRACE  TRACEONLY  

Page 23: Sr.$Technical$Consultant - Redgate€¦ · How$to$Gather$SQL$Resource$ Consump6on$Metrics$in$Oracle$ Karen$Morton$ Sr.$Technical$Consultant 1
Page 24: Sr.$Technical$Consultant - Redgate€¦ · How$to$Gather$SQL$Resource$ Consump6on$Metrics$in$Oracle$ Karen$Morton$ Sr.$Technical$Consultant 1

24  Elapsed  6me:  34.10  seconds  

Page 25: Sr.$Technical$Consultant - Redgate€¦ · How$to$Gather$SQL$Resource$ Consump6on$Metrics$in$Oracle$ Karen$Morton$ Sr.$Technical$Consultant 1

25  

Page 26: Sr.$Technical$Consultant - Redgate€¦ · How$to$Gather$SQL$Resource$ Consump6on$Metrics$in$Oracle$ Karen$Morton$ Sr.$Technical$Consultant 1

26  

Page 27: Sr.$Technical$Consultant - Redgate€¦ · How$to$Gather$SQL$Resource$ Consump6on$Metrics$in$Oracle$ Karen$Morton$ Sr.$Technical$Consultant 1

Want  more?  

Page 28: Sr.$Technical$Consultant - Redgate€¦ · How$to$Gather$SQL$Resource$ Consump6on$Metrics$in$Oracle$ Karen$Morton$ Sr.$Technical$Consultant 1

Mine  Shared  Pool  V$  Views  

Page 29: Sr.$Technical$Consultant - Redgate€¦ · How$to$Gather$SQL$Resource$ Consump6on$Metrics$in$Oracle$ Karen$Morton$ Sr.$Technical$Consultant 1

Find  the  sql_id  &  child_number  

Put  a  recognizable  comment  in  your  SQL  to  make  it  easy  to  find.  

Page 30: Sr.$Technical$Consultant - Redgate€¦ · How$to$Gather$SQL$Resource$ Consump6on$Metrics$in$Oracle$ Karen$Morton$ Sr.$Technical$Consultant 1

Retrieve  plan  using  DBMS_XPLAN.display_cursor  

('&sql_id','&child_no',  'ALLSTATS  LAST  +COST  +BYTES’)  

Other  op6ons  available:  +PEEKED_BINDS  +OUTLINE  +ADVANCED,  etc.  

Page 31: Sr.$Technical$Consultant - Redgate€¦ · How$to$Gather$SQL$Resource$ Consump6on$Metrics$in$Oracle$ Karen$Morton$ Sr.$Technical$Consultant 1

31  

-­‐-­‐Es6mates-­‐-­‐   -­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐Actuals-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐  

Page 32: Sr.$Technical$Consultant - Redgate€¦ · How$to$Gather$SQL$Resource$ Consump6on$Metrics$in$Oracle$ Karen$Morton$ Sr.$Technical$Consultant 1

Want  more?  

Page 33: Sr.$Technical$Consultant - Redgate€¦ · How$to$Gather$SQL$Resource$ Consump6on$Metrics$in$Oracle$ Karen$Morton$ Sr.$Technical$Consultant 1

SQL  Monitor  Reports  

Page 34: Sr.$Technical$Consultant - Redgate€¦ · How$to$Gather$SQL$Resource$ Consump6on$Metrics$in$Oracle$ Karen$Morton$ Sr.$Technical$Consultant 1

Automa6cally  generated  when  SQL  consumes  5  seconds  or  higher  of  CPU  or  IO  6me  

No  need  for  /*+  gather_plan_sta;s;cs  */  hint                or  STATISTICS_LEVEL  =  ALL  

Page 35: Sr.$Technical$Consultant - Redgate€¦ · How$to$Gather$SQL$Resource$ Consump6on$Metrics$in$Oracle$ Karen$Morton$ Sr.$Technical$Consultant 1

Can  use  /*+  monitor  */  

hint  

Can  turn  off  using  /*+  no_monitor  */  hint  

Page 36: Sr.$Technical$Consultant - Redgate€¦ · How$to$Gather$SQL$Resource$ Consump6on$Metrics$in$Oracle$ Karen$Morton$ Sr.$Technical$Consultant 1

36  

select  dbms_sqltune.report_sql_monitor  (report_level=>'ALL',    type=>'TEXT',    sql_id=>'6x2sh0kvzac0t')  monitor_report    from  dual;    

Types  =  (11.1)  TEXT,  HTML,  XML,  plus  (11.2)  EM,  ACTIVE.  

Generate  Report  for  any  SQL_ID  

Page 37: Sr.$Technical$Consultant - Redgate€¦ · How$to$Gather$SQL$Resource$ Consump6on$Metrics$in$Oracle$ Karen$Morton$ Sr.$Technical$Consultant 1

37  

select  dbms_sqltune.report_sql_monitor  (report_level=>'ALL',    type=>'TEXT',    session_id=>sys_context('userenv','sid')  )  monitor_report    from  dual;    

Generate  Report  for  current  session  

Page 38: Sr.$Technical$Consultant - Redgate€¦ · How$to$Gather$SQL$Resource$ Consump6on$Metrics$in$Oracle$ Karen$Morton$ Sr.$Technical$Consultant 1

38  

Page 39: Sr.$Technical$Consultant - Redgate€¦ · How$to$Gather$SQL$Resource$ Consump6on$Metrics$in$Oracle$ Karen$Morton$ Sr.$Technical$Consultant 1

39  

Page 40: Sr.$Technical$Consultant - Redgate€¦ · How$to$Gather$SQL$Resource$ Consump6on$Metrics$in$Oracle$ Karen$Morton$ Sr.$Technical$Consultant 1

40  

Page 41: Sr.$Technical$Consultant - Redgate€¦ · How$to$Gather$SQL$Resource$ Consump6on$Metrics$in$Oracle$ Karen$Morton$ Sr.$Technical$Consultant 1

41  

Page 42: Sr.$Technical$Consultant - Redgate€¦ · How$to$Gather$SQL$Resource$ Consump6on$Metrics$in$Oracle$ Karen$Morton$ Sr.$Technical$Consultant 1

Want  more?  

Page 43: Sr.$Technical$Consultant - Redgate€¦ · How$to$Gather$SQL$Resource$ Consump6on$Metrics$in$Oracle$ Karen$Morton$ Sr.$Technical$Consultant 1

Ac6ve  Session  History  (ASH)  &  

Automa6c  Workload  Repository  (AWR)  

Must  have  license  for  Diagnos;cs/Tuning  Pack  

Page 44: Sr.$Technical$Consultant - Redgate€¦ · How$to$Gather$SQL$Resource$ Consump6on$Metrics$in$Oracle$ Karen$Morton$ Sr.$Technical$Consultant 1

SQL>  @ashrp6    SQL>  @awrsqrpt  

Page 45: Sr.$Technical$Consultant - Redgate€¦ · How$to$Gather$SQL$Resource$ Consump6on$Metrics$in$Oracle$ Karen$Morton$ Sr.$Technical$Consultant 1

Want  more?  

Page 46: Sr.$Technical$Consultant - Redgate€¦ · How$to$Gather$SQL$Resource$ Consump6on$Metrics$in$Oracle$ Karen$Morton$ Sr.$Technical$Consultant 1

Extended  SQL  Trace  dbms_monitor  

session_trace_enable  

Page 47: Sr.$Technical$Consultant - Redgate€¦ · How$to$Gather$SQL$Resource$ Consump6on$Metrics$in$Oracle$ Karen$Morton$ Sr.$Technical$Consultant 1

47  

Remember:  The  more  data  you  have,  

the  easier  problem  diagnosis  will  be.  

Page 48: Sr.$Technical$Consultant - Redgate€¦ · How$to$Gather$SQL$Resource$ Consump6on$Metrics$in$Oracle$ Karen$Morton$ Sr.$Technical$Consultant 1

48  

How  you  get  the  data  doesn’t  really  maOer.  

Just  get  it.  

Page 49: Sr.$Technical$Consultant - Redgate€¦ · How$to$Gather$SQL$Resource$ Consump6on$Metrics$in$Oracle$ Karen$Morton$ Sr.$Technical$Consultant 1

Ques6ons  &  Answers  


Recommended