By Kimberly Floss
alter system set user_dump_dest="c:\kflosstrace";
You can also add your own marker to the trace file names so you can more easily find the generated files. To do so, set the tracefile_identifier initialization parameter before starting a trace:
alter session set
tracefile_identifier ="kfloss_test";
Trace files generated by this command have the string value you set appended to the filenames. Although neither of these alter commands is necessary, both make it easier to find the results of a tracing session.
SQL> exec dbms_monitor.serv_mod_act_trace_enable
(service_name=>'testenv', module_name=>'product_update');
We can turn on tracing for the client:
SQL> exec dbms_monitor.client_id_trace_enable
(client_id=>'kimberly');
Note that all of these settings are persistent—all sessions associated with the service and module will be traced, not just the current sessions.
SQL> select sid, serial#, username
from v$session;
?????? SID???? SERIAL# USERNAME
???? ------??? ------- ------------
?????? 133?????? 4152? SYS
?????? 137?????? 2418? SYSMAN
?????? 139???????? 53? KIMBERLY
?????? 140??????? 561? DBSNMP
?????? 141????????? 4? DBSNMP
. . .
?????? 168????????? 1
?????? 169????????? 1
?????? 170????????? 1
28 rows selected.
With the session ID (SID) and serial number, you can use DBMS_MONITOR to enable tracing for just this session:
SQL> exec dbms_monitor.session_trace_enable(139);
The serial number defaults to the current serial number for the SID (unless otherwise specified), so if that's the session and serial number you want to trace, you need not look any further. Also, by default, WAITS are set to true and BINDS to false, so the syntax above is effectively the same as the following:
SQL> exec dbms_monitor.session_trace_enable
(session_id=>139, serial_num=>53, waits=>true, binds=>false);
Note that WAITS and BINDS are the same parameters that you might have set in the past using DBMS_SUPPORT and the 10046 event.
You can click on the Top Services, Top Modules, Top Actions, Top Clients, or Top Sessions tabs to see the detail for each of these categories of top consumers, and then you can easily enable (or disable) SQL tracing from each of these pages. Simply select the item from the list on the page and then click on Enable SQL Trace to begin the trace (and click on Disable when you're finished).
C:\...\udump> trcsess output="kfloss.trc" service="testenv"
module="product update"
action="batch insert"
You can then run TKPROF against the consolidated trace file to generate a report.
C:\...\udump> tkprof kfloss.trc
output=kfloss_trace_report SORT=(EXEELA, PRSELA, FCHELA)
If you don't disable tracing, every session that runs that service and module will be traced. Thus, when you're finished, be sure to disable tracing by using either Oracle Enterprise Manager or the DBMS_MONITOR package.
--------------------------------------------------------------------------------
Kimberly Floss ( kimberly_floss@ioug.org ) is president of the International Oracle Users Group ( www.ioug.org ). She specializes in Oracle performance tuning and SQL tuning techniques and is also the author of Oracle SQL Tuning and CBO Internals (Rampant TechPress, 2004).
create
or
replace
package
sys.dbms_monitor
is
?
------------
?
--? OVERVIEW
?
--
?
--? This package provides database monitoring functionality, initially
?
--? in the area of statistics aggregation and SQL tracing
?
--? SECURITY
?
--
?
--? runs with SYS privileges.
?
--? CONSTANTS to be used as OPTIONS for various procedures
?
--? refer comments with procedure(s) for more detail
? all_modules???????????????????
CONSTANT
VARCHAR2
(
14
) :=
'###ALL_MODULES'
;
? all_actions???????????????????
CONSTANT
VARCHAR2
(
14
) :=
'###ALL_ACTIONS'
;
?
-- Indicates that tracing/aggregation for a given module should be enabled
?
-- for all actions
?
----------------------------
?
----------------------------
?
--? PROCEDURES AND FUNCTIONS
?
--
?
PROCEDURE
client_id_stat_enable(
??? client_id
IN
VARCHAR2
);
?
--? Enables statistics aggregation for the given Client ID
?
--? Input arguments:
?
--?? client_id?????????? - Client Identifier for which the statistics
?
--???????????????????????? colection is enabled
?
PROCEDURE
client_id_stat_disable(
??? client_id
IN
VARCHAR2
);
?
--? Disables statistics aggregation for the given Client ID
?
--? Input arguments:
?
--?? client_id?????????? - Client Identifier for which the statistics
?
--???????????????????????? colection is disabled
?
PROCEDURE
serv_mod_act_stat_enable(
??? service_name
IN
VARCHAR2
,
??? module_name
IN
VARCHAR2
,
??? action_name
IN
VARCHAR2
DEFAULT
ALL_ACTIONS);
?
--? Enables statistics aggregation for the given service/module/action
?
--? Input arguments:
?
--?? service_name??????? - Service Name for which the statistics
?
--???????????????????????? colection is enabled
?
--?? module_name???????? - Module Name for which the statistics
?
--???????????????????????? colection is enabled
?
--?? action_name???????? - Action Name for which the statistics
?
--????????????? ?????????? colection is enabled. The name is optional.
?
--???????????????????????? if omitted, statistic aggregation is enabled
?
--???????????????????????? for all actions in a given module
?
PROCEDURE
serv_mod_act_stat_disable(
??? service_name
IN
VARCHAR2
,
??? module_name
IN
VARCHAR2
,
??? action_name
IN
VARCHAR2
DEFAULT
ALL_ACTIONS);
?
--? Disables statistics aggregation for the given service/module/action
?
--? Input arguments:
?
--?? service_name??????? - Service Name for which the statistics
?
--???????????????????????? colection is disabled
?
--?? module_name???????? - Module Name for which the statistics
?
--???????????????????????? colection is disabled
?
--?? action_name???????? - Action Name for which the statistics
?
--??????????????????? ???? colection is disabled. The name is optional.
?
--???????????????????????? if omitted, statistic aggregation is disabled
?
--???????????????????????? for all actions in a given module
?
PROCEDURE
client_id_trace_enable(
??? client_id
IN
VARCHAR2
,
??? waits
IN
BOOLEAN
DEFAULT
TRUE
,
??? binds
IN
BOOLEAN
DEFAULT
FALSE
);
?
--? Enables SQL for the given Client ID
?
--? Input arguments:
?
--?? client_id?????????? - Client Identifier for which SQL trace
?
--???????????????????????? is enabled
?
--?? waits?? ??????????? - If TRUE, wait information will be present in the
?
--???????????????????????? the trace
?
--?? binds?????????????? - If TRUE, bind information will be present in the
?
--???????????????????????? the trace
?
PROCEDURE
client_id_trace_disable(
??? client_id
IN
VARCHAR2
);
?
--? Disables SQL trace for the given Client ID
?
--? Input arguments:
?
--?? client_id?????????? - Client Identifier for which SQL trace
?
--???????????????????????? is disabled
?
PROCEDURE
serv_mod_act_trace_enable(
??? service_name
IN
VARCHAR2
,
??? module_name
IN
VARCHAR2
DEFAULT
ALL_MODULES,
??? action_name
IN
VARCHAR2
DEFAULT
ALL_ACTIONS,
??? waits
IN
BOOLEAN
DEFAULT
TRUE
,
??? binds
IN
BOOLEAN
DEFAULT
FALSE
,
??? instance_name
IN
VARCHAR2
DEFAULT
NULL
);
?
--? Enables SQL trace for the given service/module/action
?
--? Input arguments:
?
--?? service_name??????? - Service Name for which SQL trace
?
--???????????????????????? is enabled
?
--?? module_name???????? - Module Name for which SQL trace
?
--???????????????? ??????? is enabled. The name is optional.
?
--???????????????????????? if omitted, SQL trace is enabled
?
--???????????????????????? for all modules and actions actions in a given
?
--???????????????????????? service
?
--?? action_name???????? - Action Name for which SQL trace
?
--???????????????????????? is enabled. The name is optional.
?
--???????????????????????? if omitted, SQL trace is enabled
?
--???????????????????????? for all actions in a given module
?
--?? waits?????????????? - If TRUE, wait information will be present in the
?
--???????????????????????? the trace
?
--?? binds?????????????? - If TRUE, bind information will be present in the
?
--???????????????????????? the trace
?
--?? instance_name?????? - if set, restricts tracing to the named instance
?
PROCEDURE
serv_mod_act_trace_disable(
??? service_name
IN
VARCHAR2
,
??? module_name
IN
VARCHAR2
DEFAULT
ALL_MODULES,
??? action_name
IN
VARCHAR2
DEFAULT
ALL_ACTIONS,
??? instance_name
IN
VARCHAR2
DEFAULT
NULL
);
?
--? Disables SQL trace for the given service/module/action
?
--? Input arguments:
?
--?? service_name??????? - Service Name for which SQL trace
?
--???????????????????????? is disabled
?
--?? module_name???????? - Module Name for which SQL trace
?
--???????????????????????? is disabled. The name is optional.
?
--???????????????????????? if omitted, SQL trace is disabled
?
--???????????????????????? for all modules and actions actions in a given
?
--?? action_name???????? - Action Name for which SQL trace
?
--???????????????????????? is disabled. The name is optional.
?
--???????????????????????? if omitted, SQL trace is disabled
?
--???????????????????????? for all actions in a given module
?
--???????????????????????? the trace
?
--?? instance_name?????? - if set, restricts disabling to the named instance
?
PROCEDURE
session_trace_enable(
??? session_id
IN
BINARY_INTEGER
DEFAULT
NULL
,
??? serial_num
IN
BINARY_INTEGER
DEFAULT
NULL
,
??? waits
IN
BOOLEAN
DEFAULT
TRUE
,
??? binds
IN
BOOLEAN
DEFAULT
FALSE
);
?
--? Enables SQL trace for the given Session ID
?
--? Input arguments:
?
--?? session_id????????? - Session Identifier for which SQL trace
?
--???????????????????????? is enabled. If omitted (or NULL), the
?
--?????? ????????????????? user's own session is assumed
?
--?? serial_num????????? - Session serial number for which SQL trace
?
--???????????????????????? is enabled. If omitted (or NULL), only
?
--???????????????????????? the session ID is used to determine a session
?
--?? waits?????????????? - If TRUE, wait information will be present in the
?
--???????????????????????? the trace
?
--?? binds?????????????? - If TRUE, bind information will be present in the
?
--???????????????????????? the trace
?
PROCEDURE
session_trace_disable(
??? session_id
IN
BINARY_INTEGER
DEFAULT
NULL
,
??? serial_num
IN
BINARY_INTEGER
DEFAULT
NULL
);
?
--? Disables SQL trace for the given Session ID
?
--? Input arguments:
?
--?? session_id????????? - Session Identifier for which SQL trace
?
--???????????????????????? is disabled
?
--?? serial_num????????? - Session serial number for which SQL trace
?
--???????????????????????? is disabled
?
PROCEDURE
database_trace_enable(
??? waits
IN
BOOLEAN
DEFAULT
TRUE
,
??? binds
IN
BOOLEAN
DEFAULT
FALSE
,
??? instance_name
IN
VARCHAR2
DEFAULT
NULL
);
?
--? Enables SQL trace for the whole database or given instance
?
--? Input arguments:
?
--?? waits?????????????? - If TRUE, wait information will be present in the
?
--???????????????????????? the trace
?
--?? binds?????????????? - If TRUE, bind information will be present in the
?
--???????????????????????? the trace
?
--?? instance_name?????? - if set, restricts tracing to the named instance
?
PROCEDURE
database_trace_disable(
??? instance_name
IN
VARCHAR2
DEFAULT
NULL
);
?
--? Disables SQL trace for the whole database or given instance
?
--? Input arguments:
?
--?? instance_name?????? - if set, restricts disabling to the named instance
end ;