55
www.sagecomputing.com.au www.sagecomputing.com.au Lost Without a Trace Penny Cookson - Managing Director SAGE Computing Services SAGE Computing Services Customised Oracle Training Workshops Customised Oracle Training Workshops and Consulting and Consulting www.sagecomputing.com.au www.sagecomputing.com.au

Lost without a trace

Embed Size (px)

Citation preview

Page 1: Lost without a trace

www.sagecomputing.com.auwww.sagecomputing.com.au

Lost Without a Trace

Penny Cookson - Managing Director

SAGE Computing ServicesSAGE Computing ServicesCustomised Oracle Training WorkshopsCustomised Oracle Training Workshops

and Consultingand Consultingwww.sagecomputing.com.auwww.sagecomputing.com.au

Page 2: Lost without a trace

www.sagecomputing.com.auwww.sagecomputing.com.au

Using trace 10053Using trace 10046Including bind variableSetting application detailsConsolidating trace filesWriting applications that allow tracing

Page 3: Lost without a trace

www.sagecomputing.com.auwww.sagecomputing.com.au

Trace 10053

Page 4: Lost without a trace

www.sagecomputing.com.auwww.sagecomputing.com.au

Trace optimiser decisionsNot formatted with tkprofALTER SESSION SET EVENTS '10053 trace name context forever, level 1‘ALTER SESSION SET EVENTS '10053 trace name context off';File in user_dump_destOnly on hard parse

Trace 10053Trace 10053

Page 5: Lost without a trace

www.sagecomputing.com.auwww.sagecomputing.com.au

SELECT b.resource_code, b.costFROM events e, bookings bWHERE e.event_no = b.event_noAND e.org_id = 1030;

Trace 10053 Trace 10053 -- ExampleExample

ALTER SESSION SET EVENTS ‘10053 trace name context forever, level 1’;

ora10g_ora_3028.trc

Page 6: Lost without a trace

www.sagecomputing.com.auwww.sagecomputing.com.au

Trace 10053 File Trace 10053 File ––InitialisationInitialisation ParametersParameters

Check for Optimizer Mode and other session variables

Page 7: Lost without a trace

www.sagecomputing.com.auwww.sagecomputing.com.au

Trace 10053 File Trace 10053 File –– Table, Table, Column and Index StatsColumn and Index Stats

Page 8: Lost without a trace

www.sagecomputing.com.auwww.sagecomputing.com.au

Trace 10053 File Trace 10053 File –– Single Single Table Access PathsTable Access Paths

Page 9: Lost without a trace

www.sagecomputing.com.auwww.sagecomputing.com.au

Trace 10053 File Trace 10053 File –– Join Join Order and Mechanism [1]Order and Mechanism [1]

Page 10: Lost without a trace

www.sagecomputing.com.auwww.sagecomputing.com.au

Trace 10053 File Trace 10053 File –– Join Join Order and Mechanism [2]Order and Mechanism [2]

Page 11: Lost without a trace

www.sagecomputing.com.auwww.sagecomputing.com.au

Trace 10053 File Trace 10053 File ––Best So FarBest So Far

Page 12: Lost without a trace

www.sagecomputing.com.auwww.sagecomputing.com.au

Trace 10053 File Trace 10053 File –– Final PlanFinal Plan

Page 13: Lost without a trace

www.sagecomputing.com.auwww.sagecomputing.com.au

Trace 10046

Page 14: Lost without a trace

www.sagecomputing.com.auwww.sagecomputing.com.au

user_dump_destLocation for trace filesSet at system level only

SELECT isses_modifiable, issys_modifiable,isinstance_modifiable

FROM v$parameterWHERE name = 'user_dump_dest'

ISSES ISSYS_MOD ISINS----- --------- -----FALSE IMMEDIATE TRUE

Initialisation ParametersInitialisation Parameters

Page 15: Lost without a trace

www.sagecomputing.com.auwww.sagecomputing.com.au

max_dump_file_sizeMaximum size of trace file in OS blocksCan be set at session level

SELECT isses_modifiable, issys_modifiable,isinstance_modifiable

FROM v$parameterWHERE name = ‘max_dump_file_size'

ISSES ISSYS_MOD ISINS----- --------- -----TRUE IMMEDIATE TRUE

Initialisation ParametersInitialisation Parameters

Page 16: Lost without a trace

www.sagecomputing.com.auwww.sagecomputing.com.au

timed_statisticsAutomatically on if statistics_level = TYPICAL or ALLNeeded for cpu/elapsed times

sql_trace = trueSets tracing on at instance level

Can be set at session levelSELECT isses_modifiable,

issys_modifiable,isinstance_modifiable

FROM v$parameterWHERE name = ‘sql_trace'

ISSES ISSYS_MOD ISINS----- --------- -----TRUE IMMEDIATE TRUE

Initialisation ParametersInitialisation Parameters

Page 17: Lost without a trace

www.sagecomputing.com.auwww.sagecomputing.com.au

Identify location of user_dump_destCheck max_dump_file_sizeTurn tracing on for the instance (performance overhead) or session

ALTER SESSION SET SQL_TRACE=TRUE;

ALTER SYSTEM SET SQL_TRACE=TRUE;

Turning Trace 10046 OnTurning Trace 10046 On

Page 18: Lost without a trace

www.sagecomputing.com.auwww.sagecomputing.com.au

tkproftkprof

tkprof ora10g_ora_4216.trc trace16.lst sort=execpu,prscpu,fchcpu, sys=no

Page 19: Lost without a trace

www.sagecomputing.com.auwww.sagecomputing.com.au

Trace levels1 Trace resources4 Trace resources and bind variable values8 Trace resources and wait events12 Trace resources, bind variables and wait

eventsALTER SYSTEM SET EVENTS ‘10046 trace name context forever, level 12’ALTER SESSION SET EVENTS ‘10046 trace name context forever, level 12’

Trace 10046 LevelsTrace 10046 Levels

Page 20: Lost without a trace

www.sagecomputing.com.auwww.sagecomputing.com.au

ALTER session SET EVENTS ‘10046 tracename context forever, level 12’

DECLAREv_event_no NUMBER :=2264;v_count NUMBER;BEGINSELECT COUNT(e.comments)INTO v_countFROM events e, bookings bWHERE e.event_no = b.event_noAND e.org_id = v_event_no;END;

Trace 10046 ExampleTrace 10046 Example

Page 21: Lost without a trace

www.sagecomputing.com.auwww.sagecomputing.com.au

Trace 10046 ExampleTrace 10046 Example

Page 22: Lost without a trace

www.sagecomputing.com.auwww.sagecomputing.com.au

tkproftkprof

tkprof ora10g_ora_456.trc trace1.prf

Page 23: Lost without a trace

www.sagecomputing.com.auwww.sagecomputing.com.au

trcsess used to consolidate a number of trace filesBased on

ServiceClientidModuleAction

DBMS_APPLICATION_INFO package can be used to set the module and action from within an application

TrcessTrcess

Page 24: Lost without a trace

www.sagecomputing.com.auwww.sagecomputing.com.au

trcsess output=output_filesession=session_idclientid=client_idservice=service_nameaction=action_namemodule=module_nametrace_files =tracefilenames

trcesstrcess -- SyntaxSyntax

Page 25: Lost without a trace

www.sagecomputing.com.auwww.sagecomputing.com.au

dbms_application_info.set_module(module_name=>'RESBOOK',action_name=>'UPDATEBOOK');

Setting Module and ActionSetting Module and Action

SELECT module, actionFROM v$sessionWHERE module IS NOT NULLMODULE ACTION ---------------- ---------------SQL*PlusRESBOOK UPDATEBOOK SQL*Plus

Page 26: Lost without a trace

www.sagecomputing.com.auwww.sagecomputing.com.au

Setting Module and ActionSetting Module and Action

Set Module and Action in your program code

Page 27: Lost without a trace

www.sagecomputing.com.auwww.sagecomputing.com.au

Create Trace FilesCreate Trace Files

ALTER SYSTEM SET EVENTS ‘10046 trace name context forever, level 12’BEGINupdate_bookings2;END;

Execute this from 3 sessions

Page 28: Lost without a trace

www.sagecomputing.com.auwww.sagecomputing.com.au

Trace FilesTrace Files

Page 29: Lost without a trace

www.sagecomputing.com.auwww.sagecomputing.com.au

Consolidate Trace FilesConsolidate Trace Files

trcsess output=trace4.trc module=RESBOOK

tkprof trace4.trc trace4.lst sys=no

trcsess output=trace4.trc module=RESBOOK

Page 30: Lost without a trace

www.sagecomputing.com.auwww.sagecomputing.com.au

TraceSessionService/Module/ActionClient ID

Gather statistics forSessionService/Module/ActionClient ID

Set Module/Action with dbms_application_infoSet Client Id with dbms_session

DBMS_MONITORDBMS_MONITOR

Page 31: Lost without a trace

www.sagecomputing.com.auwww.sagecomputing.com.au

Gather Stats for a Gather Stats for a Module/ActionModule/Action

Page 32: Lost without a trace

www.sagecomputing.com.auwww.sagecomputing.com.au

Find Active StatsFind Active Stats

SELECT * FROMDBA_ENABLED_AGGREGATIONS

AGGREGATION_TYPE---------------------PRIMARY_ID------------------------------------------------------------QUALIFIER_ID1------------------------------------------------QUALIFIER_ID2--------------------------------SERVICE_MODULE_ACTIONora10g.sagecomputing.com.auRESBOOKUPDATEBOOK

Page 33: Lost without a trace

www.sagecomputing.com.auwww.sagecomputing.com.au

View StatsView Stats

SELECT stat_name, valueFROM v$serv_mod_actsWHERE service_name =

'ora10g.sagecomputing.com.au'AND module = 'RESBOOK'AND action = 'UPDATEBOOK'AND value != 0/

Page 34: Lost without a trace

www.sagecomputing.com.auwww.sagecomputing.com.au

View StatsView Stats

STAT_NAME VALUE---------------------------------------------------------------- ----------user calls 4DB time 859564DB CPU 250180parse count (total) 9parse time elapsed 916execute count 24sql execute elapsed time 573749opened cursors cumulative 9session logical reads 31912redo size 5770380user commits 1db block changes 49480

Page 35: Lost without a trace

www.sagecomputing.com.auwww.sagecomputing.com.au

Trace a ClientTrace a Client

Page 36: Lost without a trace

www.sagecomputing.com.auwww.sagecomputing.com.au

Find Active TracesFind Active Traces

SELECT * FROMDBA_ENABLED_TRACES

TRACE_TYPE---------------------PRIMARY_ID-------------------------------------------------------------QUALIFIER_ID1------------------------------------------------QUALIFIER_ID2 WAITS BINDS INSTANCE_NAME-------------------------------- ----- ----- ----------------CLIENT_IDPENNY

TRUE TRUE

Page 37: Lost without a trace

www.sagecomputing.com.auwww.sagecomputing.com.au

Trace a ClientTrace a Client

Page 38: Lost without a trace

www.sagecomputing.com.auwww.sagecomputing.com.au

Consolidate Trace FilesConsolidate Trace Files

trcsess output=trace4.trc module=RESBOOK

tkprof trace5.trc trace5.lst sys=no

trcsess output=trace5.trc clientid=‘PENNY’

Page 39: Lost without a trace

www.sagecomputing.com.auwww.sagecomputing.com.au

DB SESSIONS

End to End MonitoringEnd to End Monitoring

GENERIC

GENERIC

GENERIC

GENERIC

APPUSER1

APPUSER2

APPUSER3

APPUSER4

APPUSER5

Page 40: Lost without a trace

www.sagecomputing.com.auwww.sagecomputing.com.au

End to End MonitoringEnd to End Monitoring

GENERICAPPUSER1

V$SESSIONCLIENT_IDSERVICE_NAMEMODULEACTION

Page 41: Lost without a trace

www.sagecomputing.com.auwww.sagecomputing.com.au

End to End MonitoringEnd to End Monitoring

GENERIC

V$SESSIONCLIENT_ID = APPUSER1SERVICE_NAME=ora10gMODULE=RESBOOKACTION=UPDATE_BOOK

GENERIC

V$SESSIONCLIENT_ID = APPUSER1SERVICE_NAME=ora10gMODULE=RESBOOKACTION=UPDATE_BOOK

GENERIC

V$SESSIONCLIENT_ID = APPUSER1SERVICE_NAME=ora10gMODULE=RESBOOKACTION=UPDATE_BOOK

GENERIC

V$SESSIONCLIENT_ID = APPUSER1SERVICE_NAME=ora10gMODULE=RESBOOKACTION=UPDATE_BOOK

ora10g_ora_7888.trc

ora10g_ora_6734.trc

ora10g_ora_3562.trc

ora10g_ora_9846.trc

trcsess output=appuser1.trc clientid=APPUSER1

appuser1.trc

tkprof appuser1.trc appuser1.lst

appuser1.lst

Page 42: Lost without a trace

www.sagecomputing.com.auwww.sagecomputing.com.au

Example Example -- HTMLDBHTMLDB

Page 43: Lost without a trace

www.sagecomputing.com.auwww.sagecomputing.com.au

Example HTMLDBExample HTMLDB

SELECT service_name, client_identifier, module, action,usernameFROM v$sessionWHERE username = 'HTMLDB_PUBLIC_USER'

SERVICE_NAME--------------------------------------------------------------CLIENT_IDENTIFIER--------------------------------------------------------------MODULE------------------------------------------------ACTION USERNAME-------------------------------- -----------------------------ora10g.sagecomputing.com.au

HTML DBapplication 118, page 13, sessio HTMLDB_PUBLIC_USER

Page 44: Lost without a trace

www.sagecomputing.com.auwww.sagecomputing.com.au

Example Example -- HTMLDBHTMLDB

Page 45: Lost without a trace

www.sagecomputing.com.auwww.sagecomputing.com.au

Example HTMLDBExample HTMLDB

SELECT service_name, client_identifier, module, action,usernameFROM v$sessionWHERE username = 'HTMLDB_PUBLIC_USER'

SERVICE_NAME--------------------------------------------------------------CLIENT_IDENTIFIER--------------------------------------------------------------MODULE------------------------------------------------ACTION USERNAME-------------------------------- -----------------------------ora10g.sagecomputing.com.au

HTML DBapplication 118, page 13, sessio HTMLDB_PUBLIC_USER

Page 46: Lost without a trace

www.sagecomputing.com.auwww.sagecomputing.com.au

Example HTMLDBExample HTMLDB

Page 47: Lost without a trace

www.sagecomputing.com.auwww.sagecomputing.com.au

Using Enterprise ManagerUsing Enterprise Manager

Page 48: Lost without a trace

www.sagecomputing.com.auwww.sagecomputing.com.au

Using Enterprise ManagerUsing Enterprise Manager

Page 49: Lost without a trace

www.sagecomputing.com.auwww.sagecomputing.com.au

Using Enterprise ManagerUsing Enterprise Manager

Page 50: Lost without a trace

www.sagecomputing.com.auwww.sagecomputing.com.au

Using Enterprise ManagerUsing Enterprise Manager

Page 51: Lost without a trace

www.sagecomputing.com.auwww.sagecomputing.com.au

Using Enterprise ManagerUsing Enterprise Manager

Page 52: Lost without a trace

www.sagecomputing.com.auwww.sagecomputing.com.au

Using Enterprise ManagerUsing Enterprise Manager

Page 53: Lost without a trace

www.sagecomputing.com.auwww.sagecomputing.com.au

Using Enterprise ManagerUsing Enterprise Manager

Page 54: Lost without a trace

www.sagecomputing.com.auwww.sagecomputing.com.au

Using Enterprise ManagerUsing Enterprise Manager

Page 55: Lost without a trace

www.sagecomputing.com.auwww.sagecomputing.com.au

Thank YouFor Your Attention

[email protected]

SAGE Computing ServicesSAGE Computing ServicesCustomised Oracle Training WorkshopsCustomised Oracle Training Workshops

and Consultingand Consultingwww.sagecomputing.com.auwww.sagecomputing.com.au