Sie sind auf Seite 1von 62

Zeroing in on Performance in Oracle 10g

James F. Koopmann
Founder & President

jkoopmann@pinehorse.com
www.pinehorse.com

www.pinehorse.com www.dbcorral.com
James F. Koopmann
Where to Find Me on the NET
 N-years of IT/core RDBMS experience  Speaker
 Oracle (V6-10g) 8i & 9i OCP
 Contributing Author
technical articles a month 2 / Month
Forum expert / moderator Daily

Database centric vendor reviews As Needed


Columnist – New Column Coming in March 1 / Month

Database general interest issues Bimonthly


Blogger (SQL Script-a-Day) Daily (in March/April)

Blogger (An Expert’s Guide to Database Solutions) 3-5 / Week

Various Ghost Writing ???

Various Technical Publications 1-2 / Year


================
10 / Month

www.pinehorse.com www.dbcorral.com
Content

The Database System

System Statistics
Session Statistics
Merging System & Session Statistics

zz
www.pinehorse.com
Session Tracing

TKPROF

www.dbcorral.com
The Database System
It’s All About Throughput
User / Job Throughput
Request
(workload) Database User User
Completes Decides Queues
Request What to Next
Sorts, Reads, Writes, Enqueues, Redo log file sync, Do Next Transaction
activity, Buffer cache activity, Parsing,… db file sequential read,…

Resource Usage Wait Times Coffee/Tea Think


Break Time
(v$sysstat) (v$system_event)
(V$SESSION, V$SESSION_EVENT, V$SESSION_WAIT, V$SESSTAT,V$SESS_IO)

Database Response Time

Can we relate the workload in our systems against the statistics that inhibit its’ throughput
SYSTEM .vs. SESSION Statistics

www.pinehorse.com www.dbcorral.com
SYSTEM Statistics
Buffer Cache
Why: Disk is slow, memory is fast
The more information in memory, the better performance we
will experience

What: Use to size the buffer caches


Size Internal structures to increase performance

When: Performance .vs. Curiosity

Where: V$BUFFER_POOL_STATISTICS
V$DB_CACHE_ADVICE
(2K, 4K, 8K, 16K, 32K, KEEP, RECYCLE)

What should I expect if I change my buffer cache sizes?

www.pinehorse.com www.dbcorral.com
SYSTEM Statistics
Buffer Cache - Advisory
SQL> SELECT name, block_size, size_for_estimate,
estd_physical_read_factor, estd_physical_reads
FROM V$DB_CACHE_ADVICE
WHERE advice_status = 'ON';

How to get the statistics


1. Set the db_cache_advice to ‘READY’
2. Set the db_cache_advice to ‘ON’
3. Run a valid workload through the system
4. Oracle populates V$DB_CACHE_ADVICE with samples / usage patterns
5. Just issue the SQL to see report

www.pinehorse.com www.dbcorral.com
SYSTEM Statistics
Buffer Cache - Advisory Report
BLOCK Cache Estd Phys Estd Phys
NAME SIZE Size Read Factor Reads Its all about reads
-------- ----- ----- ----------- ----------
DEFAULT 8192 48 2.1133 343669940
DEFAULT 8192 96 1.7266 280783364
DEFAULT 8192 144 1.4763 240091867
DEFAULT 8192 192 1.3573 220733606 1. Don’t reduce the size of
DEFAULT 8192 240 1.2801 208181172
DEFAULT 8192 288 1.2165 197842182 your cache if you are
DEFAULT 8192 336 1.1686 190052917 going to incur more
DEFAULT 8192 384 1.1202 182180544
DEFAULT 8192 432 1.0877 176884743 physical reads
DEFAULT 8192 480 1.0602 172420984
DEFAULT 8192 528 1.0196 165812231
DEFAULT 8192 544 1.00
1 162626093 CURRENT
DEFAULT 8192 576 .9765 158797352
DEFAULT 8192 624 .9392 152735392
DEFAULT 8192 672 .9216 149879874 2. Don’t increase the size of
DEFAULT 8192 720 .9013 146571255 your cache if you are not
DEFAULT 8192 768 .885 143928671
DEFAULT 8192 816 .8726 141908868 going to reduce the
DEFAULT 8192 864 .8607 139972381 number of reads

What is the cost savings for less physical reads

www.pinehorse.com www.dbcorral.com
SYSTEM Statistics
Segment Level Statistics
Why: Know thy transaction better by understanding segment access and
reduce ‘hot tables / objects”

Detection of what tables or indexes are being accessed the most will
allow you to fine tune memory structures and access methodologies.

What: Use to tune memory structures and access methodologies


When: General Investigation
Where: V$SEGSTAT &
V$SEGMENT_STATISTICS

What is my code doing

www.pinehorse.com www.dbcorral.com
SYSTEM Statistics
V$SEGMENT_STATISTICS : reads / writes
SQL> > SELECT owner,object_type,object_name,value
FROM V$SEGMENT_STATISTICS
WHERE (statistic_name like '%read%‘
OR statistic_name like '%write%')
ORDER BY value desc

How to get the statistics


1. Set STATISTICS_LEVEL to TYPICAL or ALL
2. Run a valid workload through system
3. Issue above SQL

www.pinehorse.com www.dbcorral.com
SYSTEM Statistics
V$SEGMENT_STATISTICS : reads / writes

OWNER OBJECT_TYPE
------- -------------
OBJECT_NAME
-------------------
VALUE
--------
Result
OCPOLTP TABLE OLTP_MANAGER 15752896 What objects are causing
OCPOLTP INDEX PK_OLTP_MANAGER 10716704 the performance
OCPOLTP INDEX PK_OLTP_SALES 10615296
bottleneck in relation
OCPOLTP TABLE OLTP_SALES_VALUE 8491008
OCPOLTP TABLE OLTP_SALES 7050448 to reads and writes.

Who, What, ?When?, and ?Impact?

www.pinehorse.com www.dbcorral.com
SESSION Statistics
V$SESSION
Column Description
SADDR Identifies a unique Oracle session address

SID Identifies a unique Oracle session

USERNAME The Oracle user (same as from dba_users)

STATUS Tells us the status of the session. We will be concerned with ACTIVE sessions, those
that are executing SQL

PROCESS This is the operating system process id for the connection. Only given here as a
reference so that you can go look on the O/S side.

TYPE The type of session connected to the database

SQL_ADDRESS Used with SQL_HASH_VALUE to identify the SQL statement that is currently being
executed.

SQL_HASH_VALUE Used with SQL_ADDRESS to identify the SQL statement that is currently being
executed. This SQL_HASH_VALUE is unique, or should be unique, to the same SQL
statement no matter when it is executed. Thus ‘select * from dual’ will always produce
the same SQL_HASH_VALUE.

Jump’n off point, OK, Who’s out there

www.pinehorse.com www.dbcorral.com
SESSION Statistics
Sessions Activity
SELECT sid,
to_char(logon_time,'MMDDYYYY:HH24:MI') logon_time,
username,
type,
status,
process,
sql_address,
sql_hash_value
FROM v$session
WHERE username is not null

Inactive session with no SQL executing


SID LOGON_TIME USERNAME TYPE STATUS PROCESS SQL_ADDR SQL_HASH_VALUE
---- -------------- --------- ---- -------- ------------ -------- --------------
140 06252004:06:23 JKOOPMANN USER INACTIVE 3528:3036 00 0

Active session with SQL executing


SID LOGON_TIME USERNAME TYPE STATUS PROCESS SQL_ADDR SQL_HASH_VALUE
---- -------------- --------- ---- -------- ------------ -------- --------------
140 06252004:06:23 JKOOPMANN USER ACTIVE 3528:3036 6879D780 2803425422

We have lift-off

www.pinehorse.com www.dbcorral.com
SESSION Statistics
V$SESSION_WAIT
SELECT a.sid,
c.username,
SQL_HASH_VALUE,
b.event,
b.state,
b.wait_time,
b.p1,
b.p2,
b.p
FROM V$SESSION a, V$SESSION_WAIT b, DBA_USERS c, V$PROCESS d
WHERE a.sid = b.sid
AND a.user# = c.user_id
AND a.paddr = d.addr

SQL_HASH Wait Time


SID User VALUE Wait Event Wait State (ms) P1 P2 P3
--- ----- -------------- ------------------------ ---------- ------ -------------- ------ ---
146 SCOTT 1610159152 SQL*Net message from client WAITING 0 1413697536 1 0
153 JOHN 1610159152 db file scattered read WAITING 0 1 54377 16
241 ALFY 1610159152 db file scattered read WAITING 0 1 54377 16
132 BETTY 1610159152 ksfd: async disk IO WAITED SHO -1 4294967295 32 432

Where did it go

www.pinehorse.com www.dbcorral.com
SESSION Statistics
V$SESS_IO
SELECT sess_io.sid,
sess_io.block_gets,
sess_io.consistent_gets,
sess_io.physical_reads,
sess_io.block_changes,
sess_io.consistent_change
FROM V$SESS_IO sess_io,
V$SESSION session
WHERE sesion.sid = sess_io.sid
AND sesion.username is not null

First poll for i/o


SID BLOCK_GETS CONSISTENT_GETS PHYSICAL_READS BLOCK_CHANGES CONSISTENT_CHANGES
--- ---------- --------------- -------------- ------------- ------------------
150 4 470149 446 4 0
Second poll for i/o
SID BLOCK_GETS CONSISTENT_GETS PHYSICAL_READS BLOCK_CHANGES CONSISTENT_CHANGES
--- ---------- --------------- -------------- ------------- ------------------
150 4 1002523 448 4 0

Yup, Active sessions are do’n I/O. Anyone STUCK in the mud?

www.pinehorse.com www.dbcorral.com
SESSION Statistics
V$SQLAREA
Column Description

SQL_TEXT This is the first 1000 characters of the SQL being executed by the user.
If more than 1000 characters you should use V$SQL_TEXT which is
described latter in the article.
OPTIMIZER_MODE The optimizer mode being utilized by the query

ADDRESS This is the address to the parent of this cursor/sql

HASH_VALUE This is the hash value to the parent statement in the library cache

10g CPU_TIME The accumulated microseconds of CPU time used by the SQL

10g ELAPSED_TIME The accumulated microseconds elapsed time used by the SQL

Where are Reads, Writes, and Gets

www.pinehorse.com www.dbcorral.com
SESSION Statistics
Extracting the active SQL a user is executing
SELECT sesion.sid,
sesion.username,
optimizer_mode,
hash_value,
address,
cpu_time,
elapsed_time,
sql_text
FROM v$sqlarea sqlarea, v$session sesion
WHERE sesion.sql_hash_value = sqlarea.hash_value
AND sesion.sql_address = sqlarea.address
AND sesion.username is not null

Active session and the SQL it is executing


SID USERNAME OPTIMIZER_MODE HASH_VALUE ADDRESS CPU_TIME ELAPSED_TIME
---- --------- --------------- ---------- -------- ---------- ------------
150 JKOOPMANN ALL_ROWS 2803425422 6879D780 11923758 12106196

SQL_TEXT
--------------------------------------------------
select a.table_name from dba_tables a,dba_tables b
Look (quick) what I’m doing Ma

www.pinehorse.com www.dbcorral.com
SESSION Statistics
Extracting the active SQL a user is executing
SELECT sesion.sid,
sesion.serial#,
sesion.username,
sesion.sql_id,
sesion.sql_child_number,
optimizer_mode,
hash_value,
address,
sql_text
FROM v$sqlarea sqlarea, v$session sesion
WHERE sesion.sql_hash_value = sqlarea.hash_value
AND sesion.sql_address = sqlarea.address
AND sesion.username is not null

Active session and the SQL it is executing


SID SERIAL# USERNAME SQL_ID SQL_CHILD_NUMBER OPTIMIZER_MODE HASH_VALUE ADDRESS
--- ------- --------- ------------- ---------------- -------------- ---------- --------
149 8 JKOOPMANN 5qk509xugpmpv 1 FIRST_ROWS 1962593979 69A7558C

SQL_TEXT
--------------------------------------------------
SELECT count(*) FROM sys.dba_tables WHERE owner = :1
Same old join to get SQL with a #$(& bind variable

www.pinehorse.com www.dbcorral.com
SESSION Statistics
V$SQL_BIND_CAPTURE
10g Column Description

ADDRESS This is the address to the parent of this cursor/sql

HASH_VALUE This is the hash value to the parent statement in the library
cache
NAME The name of the bind variable.

VALUE_STRING Value of the bind variable

STATISTICS_LEVEL=ALL

www.pinehorse.com www.dbcorral.com
SESSION Statistics
Extracting bind variable contents for SQL that is executing
SELECT sesion.sid,
sesion.username,
sesion.sql_id,
sesion.sql_child_number,
sql_bind_capture.name,
sql_bind_capture.value_string
FROM v$sql_bind_capture sql_bind_capture, v$session sesion
WHERE sesion.sql_hash_value = sql_bind_capture.hash_value
AND sesion.sql_address = sql_bind_capture.address
AND sesion.username is not null

Active session and the SQL it is executing


SID USERNAME SQL_ID SQL_CHILD_NUMBER NAME VALUE_STRING
---- ------------ ------------- ---------------- ---- ------------
149 JKOOPMANN 5qk509xugpmpv 1 :1 ORDEROWNER

Look ma, no traces

www.pinehorse.com www.dbcorral.com
SESSION Statistics
Extracting the active SQL a user is executing
SELECT sesion.sid,
sesion.serial#,
sesion.username,
sesion.sql_id,
sesion.sql_child_number,
optimizer_mode,
hash_value,
address,
sql_text
FROM v$sqlarea sqlarea, v$session sesion
WHERE sesion.sql_hash_value = sqlarea.hash_value
AND sesion.sql_address = sqlarea.address
AND sesion.username is not null

Active session and the SQL it is executing


SID SERIAL# USERNAME SQL_ID SQL_CHILD_NUMBER OPTIMIZER_MODE HASH_VALUE ADDRESS
--- ------- --------- ------------- ---------------- -------------- ---------- --------
149 8 JKOOPMANN 5qk509xugpmpv 1 FIRST_ROWS 1962593979 69A7558C

SQL_TEXT
--------------------------------------------------
SELECT count(*) FROM sys.dba_tables WHERE owner = :1
Same old join to get SQL with a #$(& bind variable

www.pinehorse.com www.dbcorral.com
SESSION Statistics
Additional V$SESSION column information
Column Description

SERIAL# Along with SID uniquely identifies a session and


the objects it uses.
10g SQL_ID An identifier to the SQL currently executing.

10g SQL_CHILD_NUMBER A child number of a SQL statement that is


currently being executed

New columns, Hold on!

www.pinehorse.com www.dbcorral.com
SESSION Statistics
Extract the EXACT Execution Plan

9i

SELECT * FROM table(DBMS_XPLAN.DISPLAY_CURSOR((’<SQL_ID>'),<SQL_CHILD_NUMBER>));

SELECT * FROM table(DBMS_XPLAN.DISPLAY_CURSOR(('5qk509xugpmpv'),1));

Tired of extracting raw SQL_TEXT, formatting, and producing explain plans

www.pinehorse.com www.dbcorral.com
SESSION Statistics
Extract the EXACT Execution Plan
PLAN_TABLE_OUTPUT
----------------------------------------------------------------------------------------------------
SQL_ID 5qk509xugpmpv, child number 1
-------------------------------------
SELECT count(*) FROM sys.dba_tables WHERE owner = :1
Plan hash value: 580517646
----------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|Time|
----------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | | 242 (100)| |
| 1 | SORT AGGREGATE | | 1 | 149 | | |
| 2 | NESTED LOOPS | | 1 | 149 | 242 (1)| 03 |
| 3 | MERGE JOIN CARTESIAN | | 1 | 136 | 218 (1)| 03 |
| 4 | NESTED LOOPS OUTER | | 1 | 81 | 194 (1)| 03 |
| 5 | NESTED LOOPS OUTER | | 1 | 78 | 193 (1)| 03 |
| 6 | NESTED LOOPS OUTER | | 1 | 70 | 192 (1)| 03 |
|
|
7 |
8 |
|* 9 |
| 10 |
NESTED LOOPS OUTER
NESTED LOOPS
HASH JOIN
NESTED LOOPS
WOW !!
|
|
|
|
|
|
|
|
1 |
1 |
8 |
7 |
59 |
54 |
368 |
119 |
191
191
183
4
(1)| 03 |
(1)| 03 |
(1)| 03 |
(0)| 01 |
| 11 | TABLE ACCESS BY INDEX ROWID| USER$ | 1 | 14 | 1 (0)| 01 |
|* 12 | INDEX UNIQUE SCAN | I_USER1 | 1 | | 0 (0)| |
| 13 | TABLE ACCESS FULL | TS$ | 7 | 21 | 3 (0)| 01 |
|* 14 | TABLE ACCESS FULL | TAB$ | 16 | 464 | 178 (0)| 03 |
|* 15 | TABLE ACCESS BY INDEX ROWID | OBJ$ | 1 | 8 | 1 (0)| 01 |
|* 16 | INDEX UNIQUE SCAN | I_OBJ1 | 1 | | 0 (0)| |
|* 17 | INDEX UNIQUE SCAN | I_OBJ1 | 1 | 5 | 0 (0)| |
| 18 | TABLE ACCESS CLUSTER | SEG$ | 1 | 11 | 1 (0)| 01 |
|* 19 | INDEX UNIQUE SCAN | I_FILE#_BLOCK# | 1 | | 0 (0)| |
| 20 | TABLE ACCESS BY INDEX ROWID | OBJ$ | 1 | 8 | 1 (0)| 01 |
|* 21 | INDEX UNIQUE SCAN | I_OBJ1 | 1 | | 0 (0)| |
| 22 | TABLE ACCESS CLUSTER | USER$ | 1 | 3 | 1 (0)| 01 |
|* 23 | INDEX UNIQUE SCAN | I_USER# | 1 | | 0 (0)| |
| 24 | BUFFER SORT | | 1 | 55 | 217 (1)| 03 |
|* 25 | FIXED TABLE FULL | X$KSPPI | 1 | 55 | 24 (0)| 01 |
|* 26 | FIXED TABLE FIXED INDEX | X$KSPPCV (ind:2) | 1 | 13 | 24 (0)| 01 |
----------------------------------------------------------------------------------------------------
www.pinehorse.com www.dbcorral.com
SESSION Statistics
V$SQL_PLAN_STATISTICS
9i Column Description

ADDRESS This is the address to the parent of this cursor/sql

HASH_VALUE This is the hash value to the parent statement in the


library cache
10g PLAN_HASH_VALUE Plan hash value

OPERATION_ID The number for each step in the execution plan

OUTPUT_ROWS The number of rows returned

LAST_CR_BUFFER_GETS Number of consistent gets for the last run of the


plan for a given step.
LAST_DISK_READS Number of physical disk reads for the last run of the
plan for a given step

No more global accumulated statistics from V$SQLAREA

www.pinehorse.com www.dbcorral.com
SESSION Statistics
Extracting plan statistics for execution of a SQL statement
SELECT sesion.sid,
sesion.username,
sql_plan_statistics.operation_id “Plan Id",
sql_plan_statistics.last_output_rows "Rows",
sql_plan_statistics.last_cr_buffer_gets "Consistent Gets",
sql_plan_statistics.last_disk_reads "Disk Reads"
FROM v$sql_plan_statistics sql_plan_statistics,
v$session sesion
WHERE sesion.sql_hash_value = sql_plan_statistics.hash_value
AND sesion.sql_address = sql_plan_statistics.address
AND sesion.username is not null

True statistical values accumulated for a SQL statement and each step of the Execution Plan

www.pinehorse.com www.dbcorral.com
SESSION Statistics
Extracting plan statistics for execution of a SQL statement
SID USERNAME Plan Id Rows Consistent Gets Disk Reads
--- -------------- ---------- ---------- --------------- ----------
149 JKOOPMANN 1 1 8594 0
149 JKOOPMANN 2 643 8594 0
149 JKOOPMANN 3 643 8594 0
149 JKOOPMANN 4 643 8594 0
149 JKOOPMANN 5 643 7540 0
149 JKOOPMANN 6 643 6369 0
149 JKOOPMANN 7 643 4614 0
149 JKOOPMANN 8 643 3969 0
149 JKOOPMANN 9 1572 823 0
149 JKOOPMANN 10 7 11 0
149 JKOOPMANN 11 1 2 0
149 JKOOPMANN 12 1 1 0
149 JKOOPMANN 13 7 9 0
149 JKOOPMANN 14 1572 812 0
149 JKOOPMANN 15 643 3146 0
149 JKOOPMANN 16 1572 1574 0
149 JKOOPMANN 17 50 645 0
149 JKOOPMANN 18 555 1755 0
149 JKOOPMANN 19 555 645 0
149 JKOOPMANN 20 526 1171 0
149 JKOOPMANN 21 526 645 0
149 JKOOPMANN 22 526 1054 0
149 JKOOPMANN 23 526 2 0
149 JKOOPMANN 24 643 0 0
149 JKOOPMANN 25 1 0 0
149 JKOOPMANN
www.pinehorse.com 26 643 0 0 www.dbcorral.com
SESSION Statistics
$SQL_OPTIMIZER_ENV
10g Column Description

ADDRESS This is the address to the parent of this cursor/sql

HASH_VALUE This is the hash value to the parent statement in the library cache

NAME Parameter name

ISDEFAULT Show if the parameter is set to it’s default value.

VALUE Parameter value

Does your environment change depending on application or user session


How many times have you chased an issue only to find out the user changed environments
Have any third party products. Do they do this.

www.pinehorse.com www.dbcorral.com
SESSION Statistics
Optimizer environment settings for Executing SQL
SELECT sesion.sid,
sesion.username,
name,
isdefault,
value
FROM v$sql_optimizer_env sql_optimizer_env, v$session sesion
WHERE sesion.sql_hash_value = sql_optimizer_env.hash_value
AND sesion.sql_address = sql_optimizer_env.address
AND sesion.username is not null

Optimizer environment settings for current active SQL


SID USERNAME NAME ISD VALUE
---- ------------ ---------------------------------------- --- ----------
149 JKOOPMANN parallel_execution_enabled YES true
149 JKOOPMANN optimizer_features_enable YES 10.1.0
149 JKOOPMANN cpu_count YES 2
149 JKOOPMANN active_instance_count YES 1
149 JKOOPMANN parallel_threads_per_cpu YES 2
149 JKOOPMANN hash_area_size YES 131072
149 JKOOPMANN bitmap_merge_area_size YES 1048576
149 JKOOPMANN sort_area_size YES 65536
149 JKOOPMANN sort_area_retained_size YES 0

This is YOUR environment

www.pinehorse.com www.dbcorral.com
Merging SYSTEM and SESSION Statistics
Up to now it has been “REAL-TIME” monitoring
7.1 The Good Old Days
 Catching a session waiting on a resource was literally hit and miss.
 DBAs would sit in front of the terminal screen and continually hit the ENTER key to watch
activity in the V$SESSION_WAIT view trying to get a glimpse of a bottleneck.
 This in itself was a very tedious task
 Paranoia would set in (was I going to miss something)

8.0 Not So Long Ago


 DBAs very quickly got smarter and started to sample the data in the V$SESSION_WAIT
table.
 They would write it out to another table or dump it to an external list file.
 This was fine but the overhead was high

?.? Does Anyone Really Monitor Databases Like THIS Any More
 We NOW use or build our own monitoring tools to simulate resource capturing

www.pinehorse.com www.dbcorral.com
Merging SYSTEM and SESSION Statistics
Things to Overcome
Throughput of our workload is all that matters
• What workload is in our system (SQL)
• When did it happen
• How long did it happen
• What resources where consumed
• How much resources where consumed
• To Whom did it happen
• How was the user effected

The Solution
• Proper mapping of resources to workload

www.pinehorse.com www.dbcorral.com
Merging SYSTEM and SESSION Statistics
Why Do We Care
 SYSTEM
HIGH level statistics have been global in nature and do not give the granularity needed
to tune for throughput.

 SESSION
Low level statistics have been too granular and we have not had the ability to tie them
to true workloads submitted to our systems.

 The MERGE
Your ability as a DBA/Developer to detect who/what is accessing the database, the
SQL being executed, and the exact resources consumed over a period of time is
paramount in your ability to properly manage and tune your database.

www.pinehorse.com www.dbcorral.com
Defined Connection To Notice Action Plan
Time Slice Four sessions are executing this SQL Look at SQL through Hash Value
statement (1245814300)
SQL HASH VALUE This SQL statement is consuming Research resource consumed
29.14 minutes across all sessions (row cache lock)
Top SQL is sorted to top SQL is coming from two machines Change SQL, Application or tune
O/S, DB, Session defined user SQL is being executed from sqlplus resource

www.pinehorse.com www.dbcorral.com
Defined Connection To Notice Action Plan
Time Slice Our tuning of SQL (124581430) paid Look at New SQL through Hash
off Value (1195313771)
SQL HASH VALUE Total Resource for SQL (124581430) is Research resource consumed
under 10 minutes (db file sequential read)
Top SQL is sorted to top Almost complete removal of resource
(row cach lock)
O/S, DB, Session defined user New top SQL & resource to work on

www.pinehorse.com www.dbcorral.com
True Session Wait Activity
‘True’ Session Wait Activity
7.1 The Good Old Days
 Catching a session waiting on a resource was literally hit and miss.
 DBAs would sit in front of the terminal screen and continually hit the ENTER key to
watch activity in the V$SESSION_WAIT view trying to get a glimpse of a bottleneck.
 This in itself was a very tedious task
 Paranoia would set in (was I going to miss something)

8.0 Not So Long Ago


 DBAs very quickly got smarter and started to sample the data in the
V$SESSION_WAIT table.
 They would write it out to another table or dump it to an external list file.
 This was fine but the overhead was high

10g Times Are Changing


 Oracle is starting to listen to what vendors have been providing for years
 Oracle may have given us a better mousetrap for wait events

www.pinehorse.com www.dbcorral.com
True Session Wait Activity
V$ACTIVE_SESSION_HISTORY
To The Rescue
 Oracle samples statistical data through kernel code for V$SESSION_WAIT type statistics
 Stores the statistics in a rotating buffer space, 2 Meg per CPU
 Access these statistics through V$ACTIVE_SESSION_HISTORY
 One row of sampled activity for each session that was active
 As this buffer gets full because of the activity on the system, Oracle will move the captured
statistics to disk as part of the Automatic Workload Repository (AWR) snapshot mechanism
and it will now be available through the DBA_HIST_ACTIVE_SESS_HISTORY view.
 Depending on the activity of your system you may need to go to both views
 We can go back in time and look at the true cause of performance bottlenecks

Warning :
 Statistics may be lost if the buffer rotates before the AWR snapshot mechanism kicks in.
 The snapshot mechanism only takes a sampling of the data in $ACTIVE_SESS_HISTORY

All you mice out there, Tom & Jerry – Watch Out! ………well…..….sort of

www.pinehorse.com www.dbcorral.com
True Session Wait Activity
What resource is/was currently in high demand
SELECT active_session_history.event,
SUM(active_session_history.wait_time +
active_session_history.time_waited) ttl_wait_time
FROM v$active_session_history active_session_history
WHERE active_session_history.sample_time
BETWEEN TO_DATE('20050208:0540','YYYYMMDD:HH24MI')
AND TO_DATE('20050208:0550','YYYYMMDD:HH24MI')
GROUP BY active_session_history.event
ORDER BY 2 desc

EVENT TTL_WAIT_TIME
------------------------------ -------------
log file switch completion 2673862
row cache lock 1934383
log file parallel write 1072568
log file sequential read 715168
control file sequential read 429337
db file sequential read 229237
db file parallel write 168395
latch: redo allocation 18783
db file scattered read 14254
buffer busy waits 7624

SYSTEM_EVENT type Statistics for the last 30 minutes (timed based statistics)

www.pinehorse.com www.dbcorral.com
True Session Wait Activity
What user is/was waiting the most?
SELECT active_session_history.session_id, dba_users.username,
SUM(active_session_history.wait_time +
active_session_history.time_waited) ttl_wait_time
FROM v$active_session_history active_session_history,
dba_users
WHERE active_session_history.sample_time
BETWEEN TO_DATE('20050208:0540','YYYYMMDD:HH24MI')
AND TO_DATE('20050208:0550','YYYYMMDD:HH24MI')
AND active_session_history.user_id = dba_users.user_id
GROUP BY active_session_history.session_id, dba_users.username
ORDER BY 3 DESC

SESSION_ID USERNAME TTL_WAIT_TIME


---------- ------------------------------ -------------
142 JKOOPMANN 1656292
148 JKOOPMANN 1150036
140 JKOOPMANN 999166
161 JKOOPMANN 738630
145 JKOOPMANN 332066

SESSTAT type Statistics for last 30 minutes, Who/What is my hog at a particular time

www.pinehorse.com www.dbcorral.com
True Session Wait Activity
What SQL is “currently” using the most resources?
SELECT active_session_history.user_id,
dba_users.username,
sqlarea.sql_text,
SUM(active_session_history.wait_time +
active_session_history.time_waited) ttl_wait_time
FROM v$active_session_history active_session_history,
v$sqlarea sqlarea,
dba_users
WHERE active_session_history.sample_time
BETWEEN TO_DATE('20050208:0540','YYYYMMDD:HH24MI')
AND TO_DATE('20050208:0550','YYYYMMDD:HH24MI')
AND active_session_history.sql_id = sqlarea.sql_id
AND active_session_history.user_id = dba_users.user_id
GROUP BY active_session_history.user_id,sqlarea.sql_text, dba_users.username
ORDER BY 4

USER_ID User SQL_TEXT TTL_WAIT_TIME


------- --------- ---------------------------------------------- -------------
142 JKOOPMANN select workseq.nextval into transnbr from dual 823023

Just Plain New (No more FALSE top 10 SQL hogs from V$SQLAREA)

www.pinehorse.com www.dbcorral.com
True Session Wait Activity
What object is causing the highest resource waits
SELECT dba_objects.object_name,
dba_objects.object_type,
active_session_history.event,
SUM(active_session_history.wait_time +
active_session_history.time_waited) ttl_wait_time
FROM v$active_session_history active_session_history,
dba_objects
WHERE active_session_history.sample_time
BETWEEN TO_DATE('20050208:0540','YYYYMMDD:HH24MI')
AND TO_DATE('20050208:0550','YYYYMMDD:HH24MI')
AND active_session_history.current_obj# = dba_objects.object_id
GROUP BY dba_objects.object_name, dba_objects.object_type,
active_session_history.event
ORDER BY 4 DESC

OBJECT_NAME OBJECT_TYPE EVENT TTL_WAIT_TIME


------------------------------ ------------------- ------------------------------ -------------
TRANS_LOG TABLE log file switch completion 1990217
TRANS_LOG TABLE row cache lock 1579727
TRANS_LOG TABLE latch: library cache 65325
TRANS_LOG TABLE db file sequential read 25533
TRANS_LOG TABLE enq: TX - contention 24870
Just Plain New (much better segment level statistics)

www.pinehorse.com www.dbcorral.com
Oracle Session Tracing
V$SESSION
Session Variable Description
SID Identifier for the connected session.
SERIAL# Serial number of the connected.
SERVICE_NAME Service name of the session and represents the database connected to.
MODULE Name to represent the module or code being executed.
Monitor resources used by section of code
Used to initiate traces and statistical gathering
ACTION Name to represent the action being performed by the module.
Monitor resources used by statement being executed
Used to initiate traces and statistical gathering
CLIENT_IDENTIFIER Identifier to represent the client session
Monitor an individual or group of users
Used to initiate traces and statistical gathering

Get a handle on the globalization of sessions

www.pinehorse.com www.dbcorral.com
Oracle Session Tracing
Set ACTION
EXEC DBMS_APPLICATION_INFO.SET_ACTION (action_name);

Set MODULE & ACTION


EXEC DBMS_APPLICATION_INFO.SET_MODULE(module_name, action_name);

Your Current MODULE & ACTION


CREATE OR REPLACE PROCEDURE PROCX AS
v_module_name varchar2(64);
v_action_name varchar2(64);
BEGIN
DBMS_APPLICATION_INFO.SET_MODULE(
module_name => 'MyModuleName',
action_name => 'MyActionName');
DBMS_APPLICATION_INFO.READ_MODULE(v_module_name, v_action_name);
DBMS_OUTPUT.PUT_LINE('Module : '||v_module_name);
DBMS_OUTPUT.PUT_LINE('Action : '||v_action_name);
DBMS_APPLICATION_INFO.SET_MODULE(NULL,NULL);
END;
/
SQL> EXEC PROCX
Module : MyModuleName
Action : MyActionName

www.pinehorse.com www.dbcorral.com
Oracle Session Tracing
Set your CLIENT_IDENTIFIER
EXEC DBMS_SESSION.SET_IDENTIFIER(v_user_identifier);

Check your CLIENT_IDENTIFIER


SELECT SYS_CONTEXT('USERENV','CLIENT_IDENTIFIER') CLIENT_IDENTIFIER FROM DUAL;

CLIENT_IDENTIFIER
------------------------------------
James?F.?Koopmann:PINEHORSE\FINE-ALE

Clear your CLIENT_IDENTIFIER


EXEC DBMS_SESSION.CLEAR_IDENTIFIER

www.pinehorse.com www.dbcorral.com
Oracle Session Tracing
Logon Trigger
Setting CLIENT_IDENTIFIER, MODULE & ACTION
CREATE OR REPLACE TRIGGER LOGON_TRIGGER
AFTER LOGON ON DATABASE
DECLARE
v_user_identifier varchar2(64);
BEGIN

DBMS_APPLICATION_INFO.SET_MODULE(
module_name => 'LOGON_TRIGGER',
action_name => 'SELECT FROM DUAL');

SELECT SYS_CONTEXT('USERENV', 'OS_USER')||':'||


SYS_CONTEXT('USERENV', 'HOST')
INTO v_user_identifier
FROM dual;

DBMS_SESSION.SET_IDENTIFIER(v_user_identifier);
dbms_lock.sleep(5);
DBMS_APPLICATION_INFO.SET_MODULE(NULL,NULL);
END;
/

www.pinehorse.com www.dbcorral.com
Oracle Session Tracing
V$SESSION After Setting MODULE & ACTION name
SELECT sid,
client_identifier,
action,
module
FROM V$SESSION

SID CLIENT_IDENTIFIER ACTION MODULE


---- ----------------------------------------- -------------------- ----------------
133 James?F.?Koopmann:PINEHORSE\FINE-ALE SELECT FROM DUAL LOGON_TRIGGER
135 James?F.?Koopmann:PINEHORSE\FINE-ALE mmc.exe
149 James?F.?Koopmann:PINEHORSE\FINE-ALE SQL*Plus
132 PAULANER\Administrator:PINEHORSE\PAULANER SQL*Plus

Proper setting of the ACTION and MODULE name are imperative for collecting
statistics around specific code functions and transactions. Once they are set you
can now begin getting those fine grain details about the area of code that is
performing poorly. Next time we start looking at how to actually pull out of
current sessions that fine grain information to zero in on where we need to
concentrate our tuning efforts.

www.pinehorse.com www.dbcorral.com
Oracle Session Tracing
Individual Session Activity History
SELECT session_id, client_id, event,
SUM(wait_time + time_waited) ttl_wait_time
FROM v$active_session_history active_session_history
WHERE active_session_history.sample_time
BETWEEN TO_DATE('20050208:0540','YYYYMMDD:HH24MI')
AND TO_DATE('20050208:0550','YYYYMMDD:HH24MI')
GROUP BY session_id, client_id, event
ORDER BY 4 DESC

SESSION_ID CLIENT_ID EVENT TTL_WAIT_TIME


---------- ------------------------------------------ ------------------------------ -------------
142 James?F.?Koopmann:PINEHORSE\FINE-ALE log file switch completion 1221966
148 James?F.?Koopmann:PINEHORSE\FINE-ALE log file switch completion 734903
161 PAULANER\Administrator:PINEHORSE\PAULANER row cache lock 670669
140 PAULANER\Administrator:PINEHORSE\PAULANER log file switch completion 487042
140 PAULANER\Administrator:PINEHORSE\PAULANER row cache lock 442928
142 James?F.?Koopmann:PINEHORSE\FINE-ALE row cache lock 430928
148 James?F.?Koopmann:PINEHORSE\FINE-ALE row cache lock 389858
161 PAULANER\Administrator:PINEHORSE\PAULANER latch: library cache 31923
161 PAULANER\Administrator:PINEHORSE\PAULANER db file sequential read 25533
140 PAULANER\Administrator:PINEHORSE\PAULANER enq: TX - contention 24870
140 PAULANER\Administrator:PINEHORSE\PAULANER latch: library cache 21783
148 James?F.?Koopmann:PINEHORSE\FINE-ALE latch: library cache 16703
140 PAULANER\Administrator:PINEHORSE\PAULANER db file sequential read 14965
161 PAULANER\Administrator:PINEHORSE\PAULANER buffer busy waits 7616
148 James?F.?Koopmann:PINEHORSE\FINE-ALE read by other session 6820
140 PAULANER\Administrator:PINEHORSE\PAULANER latch: shared pool 4185
140 PAULANER\Administrator:PINEHORSE\PAULANER latch: undo global data 3090

www.pinehorse.com www.dbcorral.com
Oracle Session Tracing
Accumulated Wait Activity for User Defined Area
SELECT client_id, event,
SUM(wait_time + time_waited) ttl_wait_time
FROM v$active_session_history active_session_history
WHERE active_session_history.sample_time
BETWEEN TO_DATE('20050208:0540','YYYYMMDD:HH24MI')
AND TO_DATE('20050208:0550','YYYYMMDD:HH24MI')
GROUP BY client_id, event
ORDER BY 3 DESC

CLIENT_ID EVENT TTL_WAIT_TIME


------------------------------------------ ------------------------------ -------------
James?F.?Koopmann:PINEHORSE\FINE-ALE log file switch completion 1956869
PAULANER\Administrator:PINEHORSE\PAULANER row cache lock 1113597
James?F.?Koopmann:PINEHORSE\FINE-ALE row cache lock 820786
PAULANER\Administrator:PINEHORSE\PAULANER log file switch completion 487042
PAULANER\Administrator:PINEHORSE\PAULANER latch: library cache 53706
PAULANER\Administrator:PINEHORSE\PAULANER db file sequential read 40498
PAULANER\Administrator:PINEHORSE\PAULANER enq: TX - contention 24870
James?F.?Koopmann:PINEHORSE\FINE-ALE latch: library cache 19672
PAULANER\Administrator:PINEHORSE\PAULANER buffer busy waits 7616
James?F.?Koopmann:PINEHORSE\FINE-ALE read by other session 6830
PAULANER\Administrator:PINEHORSE\PAULANER latch: shared pool 4426
PAULANER\Administrator:PINEHORSE\PAULANER latch: undo global data 3090
PAULANER\Administrator:PINEHORSE\PAULANER latch free 2765
James?F.?Koopmann:PINEHORSE\FINE-ALE latch: enqueue hash chains 5
James?F.?Koopmann:PINEHORSE\FINE-ALE latch: cache buffers chains 5
PAULANER\Administrator:PINEHORSE\PAULANER latch: row cache objects 4

www.pinehorse.com www.dbcorral.com
Oracle Session Tracing
What Code consumes most resources
SELECT module, action,
SUM(wait_time + time_waited) ttl_wait_time
FROM v$active_session_history active_session_history
WHERE active_session_history.sample_time
BETWEEN TO_DATE('20050208:0540','YYYYMMDD:HH24MI')
AND TO_DATE('20050208:0550','YYYYMMDD:HH24MI')
GROUP BY module,action
ORDER BY 3 DESC

MODULE ACTION TTL_WAIT_TIME


------------------------------ --------------- -------------
LoadTransx INSERT 2627984
GetTransactionNumber SELECTSeqNbr 1914840
GetTranssxssageumber INSERT 1300

www.pinehorse.com www.dbcorral.com
Oracle Session Tracing
DBMS_MONITOR Package
Notes
Program Description
CLIENT_ID_STAT_ENABLE Enable / Disable • Statistics can be seen through V$CLIENT_STATS.
Statistics gathering for
CLIENT_ID_STAT_DISABLE A given Client Identifier
CLIENT_ID_TRACE_ENABLE Enable / Disable • Trace data may be written to many trace files as the
Tracing for trace may effect multiple connected sessions with
CLIENT_ID_TRACE_DISABLE A given Client Identifier the same client identifier.
SERV_MOD_ACT_STAT_ENABLE Enable / Disable • Statistics can be seen through
Statistics gathering for V$SERV_MOD_ACT_STATS.
SERV_MOD_ACT_STAT_DISABLE (Service Name/MODULE/ACTION)
combination.
SERV_MOD_ACT_TRACE_ENABLE Enable / Disable • Trace data may be written to many trace files as the
Tracing for trace may effect multiple connected sessions with
SERV_MOD_ACT_TRACE_DISABLE (Service Name/MODULE/ACTION) the same Service Name, Module, or Action.
combination.
SESSION_TRACE_ENABLE Enable / Disable • Session must exist
Tracing for • Traces only a given session
SESSION_TRACE_EISABLE a session identifier (SID) • Enables / Disables a trace for the instance
submitter is connected to.

Remember to DISABLE what you ENABLE

www.pinehorse.com www.dbcorral.com
Oracle Session Tracing
Determine Connected Sessions for Tracing
SELECT sid, serial#,
client_identifier,
service_name,
action,
module
FROM V$SESSION

SID SERIAL# CLIENT_IDENTIFIER SERVICE_NAME ACTION MODULE


--- ------ ----------------------------------------- -------------- ------------- --------------------
161 118 PAULANER\Administrator:PINEHORSE\PAULANER pinehorse.com INSERT LoadTransx
142 1137 James?F.?Koopmann:PINEHORSE\FINE-ALE pinehorse.com SELECTSeqNbr GetTransactionNumber
148 1306 James?F.?Koopmann:PINEHORSE\FINE-ALE pinehorse.com SELECTSeqNbr GetTransactionNumber
140 308 PAULANER\Administrator:PINEHORSE\PAULANER pinehorse.com BuildTransx BuildLogMessage

www.pinehorse.com www.dbcorral.com
Oracle Session Tracing
DBMS_MONITOR Package
Program Example How to Enable
CLIENT_ID_STAT_ENABLE DBMS_MONITOR.CLIENT_ID_STAT_ENABLE(client_identifier);
CLIENT_ID_STAT_DISABLE

SERV_MOD_ACT_STAT_ENABLE DBMS_MONITOR.SERV_MOD_ACT_STAT_ENABLE(service_name, module_name, action_name);

SERV_MOD_ACT_STAT_DISABLE Action_name, may be an empty field if not defined for the session.
•Use DBMS_MONITOR.ALL_ACTIONS variable to reference ALL sessions that have an
action_name defined.
•To reference ALL sessions that do not have this variable defined, use NULL.
•The contents of this field is actually ‘###ALL_ACTIONS’ and you should avoid naming any
actions or module names with this.

Enable statistics gathering for CLIENT_IDENTIFIER.


EXEC DBMS_MONITOR.CLIENT_ID_STAT_ENABLE(‘PAULANER\Administrator:PINEHORSE\PAULANER’);
EXEC DBMS_MONITOR.CLIENT_ID_STAT_ENABLE(‘James?F.?Koopmann:PINEHORSE\FINE-ALE’);

www.pinehorse.com www.dbcorral.com
Oracle Session Tracing
DBA_ENABLED_AGGREGATIONS
SELECT * FROM DBA_ENABLED_AGGREGATIONS ;

AGGREGATION_TYPE PRIMARY_ID QUALIFIER_ID1 QUALIFIER_ID2


--------------- ----------------------------------------- -------------------- ---------------
CLIENT_ID James?F.?Koopmann:PINEHORSE\FINE-ALE
CLIENT_ID PAULANER\Administrator:PINEHORSE\PAULANER
SERVICE_MODULE pinehorse.com BuildLogMessage
SERVICE_MODULE pinehorse.com GetTransactionNumber
SERVICE_MODULE pinehorse.com LoadTransx

Column Description
AGGREGATION_TYPE This is the type of statistical aggregation being done. This relates to the actual
procedure called in the DBMS_MONITOR package. In Listing 1 I we have called the
CLIENT_ID_STAT_ENABLE and SERV_MOD_ACT_STAT_ENABLE procedures

PRIMARY_ID This is the CLIENT_IDENTIFIER or SERVICE_NAME in the call

QUALIFIER_ID1 The module name

QUALIFIER_ID2 The action name

www.pinehorse.com www.dbcorral.com
Oracle Session Tracing
Views that Contain Statistical Information
Table Description
V$ACTIVE_SESSION_HISTORY •The V$ACTIVE_SESSION_HISTORY view is a holding area for sampled session data
performed on your behalf from the Oracle engine. This data is sampled once per second
and is a great resource for determining where the true bottleneck lies in your system.
•Use this view in conjunction with setting the CLIENT_IDENTIFIER, ACTION, and MODULE
to aggregate (GROUP BY) and find the largest consumers of resources within your system.
DBA_HIST_ACTIVE_SESS_HISTORY •This view is just a historical representation of the V$ACTIVE_SESSION_HISTORY view
above. While it is good for some historical information, be warned that it does not contain
all the collected statistics that were captured in the V$ACTIVE_SESSION_HISTORY view.
V$CLIENT_STATS •If you have enabled any statistics for a CLIENT_IDENTIFIER you will see the aggregated
statistics for that CLIENT_IDENTIFIER in this view that are currently active.
•These statistics are only good for current activity and troubleshooting and thus should
only be used for getting a glimpse of what clients are consuming the most resources.
•Very valuable for a quick current view but if you need to drill to a particular client you will
end up going to V$ACTIVE_SESSION_HISTORY.
V$SERVICE_STATS •Provides a reduced set of statistics that can be used to determine how well an instance is
performing for the requests made upon it.
•This is typically the SID_NAME but beware it may be different if you are not connecting
through TNS.
V$SERV_MOD_ACT_STATS •This view provides an aggregated view for the combination of SERVICE_NAME, MODULE,
and ACTION you have defined when you enabled aggregated statistics.
Just be careful to name these aggregates appropriately so that you can quickly determine
where bottlenecks reside.
www.pinehorse.com www.dbcorral.com
Oracle Session Tracing
DBMS_MONITOR Package (Trace Control)
Program Example How to Enable
CLIENT_ID_TRACE_ENABLE DBMS_MONITOR.CLIENT_ID_TRACE_ENABLE(client_id, waits, binds);
CLIENT_ID_TRACE_DISABLE waits : If TRUE, wait information is present in the trace.
Binds : If TRUE, bind information is present in the trace.
SERV_MOD_ACT_TRACE_ENABLE DBMS_MONITOR.SERV_MOD_ACT_TRACE_ENABLE
(service_name, module_name, action_name, waits, binds, instance_name);
•Use DBMS_MONITOR.ALL_ACTIONS variable to reference ALL sessions that have an
SERV_MOD_ACT_TRACE_DISABLE
action name defined.
•To reference ALL sessions that do not have this variable defined, use NULL.
•The contents of this field is actually ‘###ALL_ACTIONS’ and you should avoid naming any
actions or module names with this.
instance_name restricts tracing to the named instance_name.
SESSION_TRACE_ENABLE DBMS_MONITOR.SESSION_TRACE_ENABLE(session_id, serial_number, waits, binds)
session_id, Must provide. If just a session_id is given than all serial numbers will be traced.
SESSION_TRACE_DISABLE If session_id and serial_number are NULL than you trace your own current session.

Enable tracing for CLIENT_IDENTIFIER with wait information but no bind information
EXECUTE DBMS_MONITOR.CLIENT_ID_TRACE_ENABLE(‘PAULANER\Administrator:PINEHORSE\PAULANER’,TRUE,FALSE);
EXECUTE DBMS_MONITOR.CLIENT_ID_TRACE_ENABLE(‘James?F.?Koopmann:PINEHORSE\FINE-ALE’,TRUE,FALSE);

www.pinehorse.com www.dbcorral.com
Oracle Session Tracing
DBA_ENABLED_TRACES
SELECT * FROM DBA_ENABLED_TRACES ;

TRACE_TYPE PRIMARY_ID QULIFY1 QULIFY2 WAITS BINDS INSTANCE_NAME


---------- ----------------------------------------- ------- ------- ----- ----- ----------
CLIENT_ID PAULANER\Administrator:PINEHORSE\PAULANER TRUE FALSE
CLIENT_ID James?F.?Koopmann:PINEHORSE\FINE-ALE TRUE FALSE

Column Description
TRACE_TYPE Type of the trace:
(CLIENT_ID, SERVICE, SERVICE_MODULE, SERVICE_MODULE_ACTION)
NOT SESSION
PRIMARY_ID This is the CLIENT_IDENTIFIER or SERVICE_NAME in the call

QUALIFIER_ID1 The module name

QUALIFIER_ID2 The action name

WAITS Indicates whether waits are traced (TRUE) or not (FALSE)

BINDS Indicates whether binds are traced (TRUE) or not (FALSE)

INSTANCE_NAME Instance name for tracing restricted to named instances


www.pinehorse.com www.dbcorral.com
Oracle Session Tracing
Where is My Trace File
USER_DUMP_DEST is the location on disk where Oracle will write out your enabled trace information.

SQL > SHOW PARAMETER user_dump_dest


NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
user_dump_dest string D:\ORACLE\PRODUCT\10.1.0\ADMIN\LAGER\UDUMP

SQL > SELECT value FROM v$parameter WHERE name = ‘user_dump_dest’;


VALUE
-----------------------------------
D:\ORACLE\PRODUCT\10.1.0\ADMIN\LAGER\UDUMP

Give Your Trace File Meaning


SQL > ALTER SESSION SET TRACEFILE_IDENTIFIER = ‘SomeIdentifier;

www.pinehorse.com www.dbcorral.com
Oracle Session Tracing
Part of a Trace File
Dump file d:\oracle\product\10.1.0\admin\lager\udump\lager_ora_162.trc
*** ACTION NAME:() 2005-02-08 05:29:13.515
*** MODULE NAME:(SQL*Plus) 2005-02-08 05:29:13.515
*** SERVICE NAME:(pinehorse.com) 2005-02-08 05:29:13.515
*** CLIENT ID:(PAULANER\Administrator:PINEHORSE\PAULANER) 2005-02-08 05:29:
*** SESSION ID:(161.20) 2005-02-08 05:29:13.515
=====================
PARSING IN CURSOR #1 len=18 dep=0 uid=64 oct=47 lid=64 tim=2985552493 hv=21
BEGIN work; END;
END OF STMT
PARSE #1:c=0,e=208,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=1,tim=2985552444
*** ACTION NAME:(SELECTSeqNbr) 2005-02-08 05:29:13.578
*** MODULE NAME:(GetTransactionNumber) 2005-02-08 05:29:13.578
=====================
PARSING IN CURSOR #2 len=32 dep=1 uid=64 oct=3 lid=64 tim=2985568906 hv=124
SELECT WORKSEQ.NEXTVAL FROM DUAL
END OF STMT
PARSE #2:c=0,e=165,p=0,cr=0,cu=0,mis=0,r=0,dep=1,og=1,tim=2985568889
EXEC #2:c=0,e=257,p=0,cr=0,cu=0,mis=0,r=0,dep=1,og=1,tim=2985571308
=====================
PARSING IN CURSOR #3 len=129 dep=2 uid=0 oct=6 lid=0 tim=2985572102 hv=2635
update seq$ set increment$=:2,minvalue=:3,maxvalue=:4,cycle#=:5,order$=:6,c
END OF STMT
PARSE #3:c=0,e=159,p=0,cr=0,cu=0,mis=0,r=0,dep=2,og=4,tim=2985572087
EXEC #3:c=15625,e=790,p=0,cr=1,cu=2,mis=0,r=1,dep=2,og=4,tim=2985581702
STAT #3 id=1 cnt=1 pid=0 pos=1 obj=0 op='UPDATE (cr=1 pr=0 pw=0 time=592 u
FETCH #2:c=15625,e=15799,p=0,cr=1,cu=3,mis=0,r=1,dep=1,og=1,tim=2985587476
*** ACTION NAME:(INSERT) 2005-02-08 05:29:13.593
*** MODULE NAME:(LoadTransx) 2005-02-08 05:29:13.593
Can you say grep –i {search_pattern} *.trc

www.pinehorse.com www.dbcorral.com
Oracle Session Tracing
Syntax & Example for trcsess
trcsess [output = output_file_name]
[session = session_Id]
[clientid = client_Id]
[service = service_name]
[action = action_name]
[module = module_name]
[trace_files]

Example:
Consolidate all trace files for everyone that has been in the Transaction Module (GetTransactionNumber).

C:\> trcsess output=GetTransactionNumber.trc module=GetTransactionNumber *.trc

www.pinehorse.com www.dbcorral.com
Oracle Session Tracing
What Can TKPROF Do
1. Formats all the cryptic information in a more readable form that is understandable for you
and me.

2. Breaks out each statement executed during the trace period and presents various
statistics that enable us to determine where bottlenecks lay and where we might spend our
time tuning application code.

3. Can generate a SQL script that allows us to store the captured statistics into a database.

4. Will determine the explain plan for executed SQL statements.

5. Provides for summary as well as detail information for collected statistics

www.pinehorse.com www.dbcorral.com
Oracle Session Tracing
Syntax & Example for TKPROF
tkprof trace_file report_file
[waits = yes|no]
[sort = option]
[print = n]
[aggregate = yes|no]
[insert = filename3]
[sys = yes|no]
[table = schema.table]
[explain = user/password]
[record = filename4]
[width = n]

Example:
Produce report for all users within the Transaction Module (GetTransactionNumber).

C:\> tkprof GetTransactionNumber.trc GetTransactionNumber.rpt

www.pinehorse.com www.dbcorral.com
Oracle Session Tracing
TKPROF Report
TKPROF: Release 10.1.0.2.0 - Production on Tue Feb 8 20:29:57 2005

Copyright (c) 1982, 2004, Oracle. All rights reserved.

Trace file: GetTransactionNumber.trc


Sort options: default

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

SELECT WORKSEQ.NEXTVAL FROM DUAL

call count cpu elapsed disk query current rows


------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 4 0.01 0.00 0 0 0 0
Execute 85071 516.03 3221.43 27 122597 605469 0
Fetch 85067 111.60 175.19 0 54 85173 85063
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 170142 627.65 3396.63 27 122651 690642 85063

WOW! Just what I wanted

www.pinehorse.com www.dbcorral.com
Oracle Session Tracing
Tracing Enhancements
The world of tracing Oracle sessions has changed drastically with Oracle 10g.

Not so much the mechanisms but in the way we can initiate a trace for one session or a group of
sessions.

We are now able to "tag" sessions as they are connected to Oracle and move through
applications.

We can now accurately pinpoint where in the application a session is, the amount of resources
being consumed, and more importantly if the session is having difficulty and is in need of
tuning.

This is extremely important in a multi-tier environment where connection polling takes place and
we would be lost if it where not for these new tracing features.

www.pinehorse.com www.dbcorral.com
Zeroing in on Performance in Oracle 10g

James F. Koopmann
Founder & President

jkoopmann@pinehorse.com
www.pinehorse.com

www.pinehorse.com www.dbcorral.com

Das könnte Ihnen auch gefallen