KoopmannZeroingInOnPerformanceInOracle10g
Transcript of KoopmannZeroingInOnPerformanceInOracle10g
www.pinehorse.com www.dbcorral.com
Zeroing in on Performance in Oracle 10g
James F. KoopmannFounder & President
www.pinehorse.com www.dbcorral.com
� N-years of IT/core RDBMS experience� Oracle (V6-10g) 8i & 9i OCP� Contributing Author
Where to Find Me on the NET� Speaker
James F. Koopmann
2 / Month
Daily
technical articles a month
Forum expert / moderator
Various Technical Publications
Various Ghost Writing
Blogger (An Expert’s Guide to Database Solutions)
Database general interest issues
Blogger (SQL Script-a-Day)
Database centric vendor reviews
Columnist – New Column Coming in March
1-2 / Year
================
10 / Month
???
3-5 / Week
Bimonthly
Daily (in March/April)
As Needed
1 / Month
www.pinehorse.com www.dbcorral.com
The Database System
System Statistics
Session Statistics
Merging System & Session Statistics
Session Tracing
TKPROF
Content
zz
www.pinehorse.com www.dbcorral.com
User / Job
Request
(workload) User
Decides
What to
Do Next
Database
Completes
Request
Database Response Time
Coffee/Tea Break
Resource Usage
(v$sysstat)
Sorts, Reads, Writes, Enqueues, Redo activity, Buffer cache activity, Parsing,…
User
Queues
Next
Transaction
Think
Time
log file sync,
db file sequential read,…
Wait Times
(v$system_event)
Throughput
The Database System
It’s All About Throughput
Can we relate the workload in our systems against the statistics that inhibit its’ throughputSYSTEM .vs. SESSION Statistics
(V$SESSION, V$SESSION_EVENT, V$SESSION_WAIT, V$SESSTAT,V$SESS_IO)
www.pinehorse.com www.dbcorral.com
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)
Buffer Cache
SYSTEM Statistics
What should I expect if I change my buffer cache sizes?
www.pinehorse.com www.dbcorral.com
SQL> SELECT name, block_size, size_for_estimate,
estd_physical_read_factor, estd_physical_reads
FROM V$DB_CACHE_ADVICE
WHERE advice_status = 'ON';
Buffer Cache - Advisory
How to get the statistics1. 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
SYSTEM Statistics
www.pinehorse.com www.dbcorral.com
BLOCK Cache Estd Phys Estd PhysNAME SIZE Size Read Factor Reads-------- ----- ----- ----------- ----------DEFAULT 8192 48 2.1133 343669940DEFAULT 8192 96 1.7266 280783364DEFAULT 8192 144 1.4763 240091867DEFAULT 8192 192 1.3573 220733606DEFAULT 8192 240 1.2801 208181172DEFAULT 8192 288 1.2165 197842182DEFAULT 8192 336 1.1686 190052917DEFAULT 8192 384 1.1202 182180544DEFAULT 8192 432 1.0877 176884743DEFAULT 8192 480 1.0602 172420984DEFAULT 8192 528 1.0196 165812231DEFAULT 8192 544 1 162626093DEFAULT 8192 576 .9765 158797352DEFAULT 8192 624 .9392 152735392DEFAULT 8192 672 .9216 149879874DEFAULT 8192 720 .9013 146571255DEFAULT 8192 768 .885 143928671DEFAULT 8192 816 .8726 141908868DEFAULT 8192 864 .8607 139972381
DEFAULT 8192 544 1.00 162626093 CURRENT
Its all about reads
1. Don’t reduce the size of
your cache if you are
going to incur more
physical reads
2. Don’t increase the size of
your cache if you are not
going to reduce the
number of reads
Buffer Cache - Advisory Report
SYSTEM Statistics
What is the cost savings for less physical reads
www.pinehorse.com www.dbcorral.com
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
Segment Level Statistics
SYSTEM Statistics
What is my code doing
www.pinehorse.com www.dbcorral.com
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
V$SEGMENT_STATISTICS : reads / writes
SYSTEM Statistics
www.pinehorse.com www.dbcorral.com
OWNER OBJECT_TYPE OBJECT_NAME VALUE
------- ------------- ------------------- --------
OCPOLTP TABLE OLTP_MANAGER 15752896
OCPOLTP INDEX PK_OLTP_MANAGER 10716704
OCPOLTP INDEX PK_OLTP_SALES 10615296
OCPOLTP TABLE OLTP_SALES_VALUE 8491008
OCPOLTP TABLE OLTP_SALES 7050448
…
Result
What objects are causing the performance bottleneck in relation to reads and writes.
V$SEGMENT_STATISTICS : reads / writes
SYSTEM Statistics
Who, What, ?When?, and ?Impact?
www.pinehorse.com www.dbcorral.com
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.
SQL_HASH_VALUE
Used with SQL_HASH_VALUE to identify the SQL statement that is currently being
executed.
SQL_ADDRESS
The type of session connected to the databaseTYPE
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.
PROCESS
Tells us the status of the session. We will be concerned with ACTIVE sessions, those
that are executing SQL
STATUS
The Oracle user (same as from dba_users)USERNAME
Identifies a unique Oracle sessionSID
Identifies a unique Oracle session addressSADDR
DescriptionColumn
V$SESSION
Jump’n off point, OK, Who’s out there
SESSION Statistics
www.pinehorse.com www.dbcorral.com
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
Sessions Activity
SESSION Statistics
We have lift-off
www.pinehorse.com www.dbcorral.com
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
V$SESSION_WAIT
SESSION Statistics
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
Where did it go
www.pinehorse.com www.dbcorral.com
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
V$SESS_IO
SESSION Statistics
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
Yup, Active sessions are do’n I/O. Anyone STUCK in the mud?
www.pinehorse.com www.dbcorral.com
V$SQLAREA
10g
10g
The accumulated microseconds elapsed time used by the SQLELAPSED_TIME
The accumulated microseconds of CPU time used by the SQLCPU_TIME
This is the hash value to the parent statement in the library cacheHASH_VALUE
This is the address to the parent of this cursor/sqlADDRESS
The optimizer mode being utilized by the queryOPTIMIZER_MODE
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.
SQL_TEXT
DescriptionColumn
Where are Reads, Writes, and Gets
SESSION Statistics
www.pinehorse.com www.dbcorral.com
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
Extracting the active SQL a user is executing
SESSION Statistics
Look (quick) what I’m doing Ma
www.pinehorse.com www.dbcorral.com
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
Extracting the active SQL a user is executing
Same old join to get SQL with a #$(& bind variable
SESSION Statistics
www.pinehorse.com www.dbcorral.com
V$SQL_BIND_CAPTURE
This is the hash value to the parent statement in the library cache
HASH_VALUE
10g
Value of the bind variableVALUE_STRING
The name of the bind variable.NAME
This is the address to the parent of this cursor/sqlADDRESS
DescriptionColumn
STATISTICS_LEVEL=ALL
SESSION Statistics
www.pinehorse.com www.dbcorral.com
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
Extracting bind variable contents for SQL that is executing
Look ma, no traces
SESSION Statistics
www.pinehorse.com www.dbcorral.com
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
Extracting the active SQL a user is executing
Same old join to get SQL with a #$(& bind variable
SESSION Statistics
www.pinehorse.com www.dbcorral.com
Additional V$SESSION column information
10g
10g
A child number of a SQL statement that is currently being executed
SQL_CHILD_NUMBER
An identifier to the SQL currently executing. SQL_ID
Along with SID uniquely identifies a session and the objects it uses.
SERIAL#
DescriptionColumn
New columns, Hold on!
SESSION Statistics
www.pinehorse.com www.dbcorral.com
9i
SELECT * FROM table(DBMS_XPLAN.DISPLAY_CURSOR((’<SQL_ID>'),<SQL_CHILD_NUMBER>));
SELECT * FROM table(DBMS_XPLAN.DISPLAY_CURSOR(('5qk509xugpmpv'),1));
Extract the EXACT Execution Plan
Tired of extracting raw SQL_TEXT, formatting, and producing explain plans
SESSION Statistics
www.pinehorse.com www.dbcorral.com
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 | NESTED LOOPS OUTER | | 1 | 59 | 191 (1)| 03 |
| 8 | NESTED LOOPS | | 1 | 54 | 191 (1)| 03 |
|* 9 | HASH JOIN | | 8 | 368 | 183 (1)| 03 |
| 10 | NESTED LOOPS | | 7 | 119 | 4 (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 |
----------------------------------------------------------------------------------------------------
Extract the EXACT Execution Plan
WOW !!
SESSION Statistics
www.pinehorse.com www.dbcorral.com
V$SQL_PLAN_STATISTICS
10g
9i
Number of physical disk reads for the last run of the plan for a given step
LAST_DISK_READS
Number of consistent gets for the last run of the plan for a given step.
LAST_CR_BUFFER_GETS
The number of rows returned OUTPUT_ROWS
The number for each step in the execution planOPERATION_ID
Plan hash valuePLAN_HASH_VALUE
This is the hash value to the parent statement in the library cache
HASH_VALUE
This is the address to the parent of this cursor/sqlADDRESS
DescriptionColumn
No more global accumulated statistics from V$SQLAREA
SESSION Statistics
www.pinehorse.com www.dbcorral.com
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
Extracting plan statistics for execution of a SQL statement
True statistical values accumulated for a SQL statement and each step of the Execution Plan
SESSION Statistics
www.pinehorse.com www.dbcorral.com
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 26 643 0 0
Extracting plan statistics for execution of a SQL statement
SESSION Statistics
www.pinehorse.com www.dbcorral.com
$SQL_OPTIMIZER_ENV10g
Parameter valueVALUE
Show if the parameter is set to it’s default value.ISDEFAULT
Parameter nameNAME
This is the hash value to the parent statement in the library cacheHASH_VALUE
This is the address to the parent of this cursor/sqlADDRESS
DescriptionColumn
Does your environment change depending on application or user sessionHow many times have you chased an issue only to find out the user changed environmentsHave any third party products. Do they do this.
SESSION Statistics
www.pinehorse.com www.dbcorral.com
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
Optimizer environment settings for Executing SQL
This is YOUR environment
SESSION Statistics
www.pinehorse.com www.dbcorral.com
Up to now it has been “REAL-TIME” monitoring
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)
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
?.?
8.0
7.1
Merging SYSTEM and SESSION Statistics
www.pinehorse.com www.dbcorral.com
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
Things to Overcome
Merging SYSTEM and SESSION Statistics
www.pinehorse.com www.dbcorral.com
� 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.
Why Do We Care
Merging SYSTEM and SESSION Statistics
www.pinehorse.com www.dbcorral.com
SQL is being executed from sqlplusO/S, DB, Session defined user
Change SQL, Application or tune resource
SQL is coming from two machinesTop SQL is sorted to top
Research resource consumed
(row cache lock)
This SQL statement is consuming 29.14 minutes across all sessions
SQL HASH VALUE
Look at SQL through Hash Value
(1245814300)
Four sessions are executing this SQL statement
Time Slice
Action PlanTo NoticeDefined Connection
www.pinehorse.com www.dbcorral.com
New top SQL & resource to work onO/S, DB, Session defined user
Almost complete removal of resource (row cach lock)
Top SQL is sorted to top
Research resource consumed
(db file sequential read)
Total Resource for SQL (124581430) is under 10 minutes
SQL HASH VALUE
Look at New SQL through Hash Value (1195313771)
Our tuning of SQL (124581430) paid off
Time Slice
Action PlanTo NoticeDefined Connection
www.pinehorse.com www.dbcorral.com
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)
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
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
‘True’ Session Wait Activity
True Session Wait Activity
10g
8.0
7.1
www.pinehorse.com www.dbcorral.com
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
V$ACTIVE_SESSION_HISTORY
True Session Wait Activity
All you mice out there, Tom & Jerry – Watch Out! ………well…..….sort of
www.pinehorse.com www.dbcorral.com
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
What resource is/was currently in high demand
SYSTEM_EVENT type Statistics for the last 30 minutes (timed based statistics)
True Session Wait Activity
www.pinehorse.com www.dbcorral.com
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
What user is/was waiting the most?
SESSTAT type Statistics for last 30 minutes, Who/What is my hog at a particular time
True Session Wait Activity
www.pinehorse.com www.dbcorral.com
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
What SQL is “currently” using the most resources?
Just Plain New (No more FALSE top 10 SQL hogs from V$SQLAREA)
True Session Wait Activity
www.pinehorse.com www.dbcorral.com
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
What object is causing the highest resource waits
Just Plain New (much better segment level statistics)
True Session Wait Activity
www.pinehorse.com www.dbcorral.com
V$SESSION
Oracle Session Tracing
Identifier to represent the client sessionMonitor an individual or group of usersUsed to initiate traces and statistical gathering
CLIENT_IDENTIFIER
Name to represent the action being performed by the module.Monitor resources used by statement being executedUsed to initiate traces and statistical gathering
ACTION
Name to represent the module or code being executed. Monitor resources used by section of codeUsed to initiate traces and statistical gathering
MODULE
Service name of the session and represents the database connected to.SERVICE_NAME
Serial number of the connected. SERIAL#
Identifier for the connected session.SID
DescriptionSession Variable
Get a handle on the globalization of sessions
www.pinehorse.com www.dbcorral.com
Set ACTION
Oracle Session Tracing
EXEC DBMS_APPLICATION_INFO.SET_ACTION (action_name);
EXEC DBMS_APPLICATION_INFO.SET_MODULE(module_name, action_name);
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
Set MODULE & ACTION
Your Current MODULE & ACTION
www.pinehorse.com www.dbcorral.com
Set your CLIENT_IDENTIFIER
Oracle Session Tracing
EXEC DBMS_SESSION.SET_IDENTIFIER(v_user_identifier);
SELECT SYS_CONTEXT('USERENV','CLIENT_IDENTIFIER') CLIENT_IDENTIFIER FROM DUAL;
CLIENT_IDENTIFIER
------------------------------------
James?F.?Koopmann:PINEHORSE\FINE-ALE
EXEC DBMS_SESSION.CLEAR_IDENTIFIER
Check your CLIENT_IDENTIFIER
Clear your CLIENT_IDENTIFIER
www.pinehorse.com www.dbcorral.com
Logon Trigger
Oracle Session Tracing
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;
/
Setting CLIENT_IDENTIFIER, MODULE & ACTION
www.pinehorse.com www.dbcorral.com
V$SESSION After Setting MODULE & ACTION name
Oracle Session Tracing
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
Individual Session Activity History
Oracle Session Tracing
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
Accumulated Wait Activity for User Defined Area
Oracle Session Tracing
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
What Code consumes most resources
Oracle Session Tracing
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
DBMS_MONITOR Package
Oracle Session Tracing
SESSION_TRACE_EISABLE
• Session must exist• Traces only a given session• Enables / Disables a trace for the instance submitter is connected to.
Enable / Disable Tracing for a session identifier (SID)
SESSION_TRACE_ENABLE
SERV_MOD_ACT_TRACE_DISABLE
• Trace data may be written to many trace files as the trace may effect multiple connected sessions with the same Service Name, Module, or Action.
Enable / DisableTracing for (Service Name/MODULE/ACTION) combination.
SERV_MOD_ACT_TRACE_ENABLE
SERV_MOD_ACT_STAT_DISABLE
• Statistics can be seen through V$SERV_MOD_ACT_STATS.
Enable / DisableStatistics gathering for (Service Name/MODULE/ACTION) combination.
SERV_MOD_ACT_STAT_ENABLE
CLIENT_ID_TRACE_DISABLE
• Trace data may be written to many trace files as the trace may effect multiple connected sessions with the same client identifier.
Enable / DisableTracing for A given Client Identifier
CLIENT_ID_TRACE_ENABLE
CLIENT_ID_STAT_DISABLE
• Statistics can be seen through V$CLIENT_STATS.Enable / DisableStatistics gathering for A given Client Identifier
CLIENT_ID_STAT_ENABLE
NotesDescriptionProgram
Remember to DISABLE what you ENABLE
www.pinehorse.com www.dbcorral.com
Determine Connected Sessions for Tracing
Oracle Session 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
DBMS_MONITOR Package
Oracle Session Tracing
SERV_MOD_ACT_STAT_DISABLE
DBMS_MONITOR.SERV_MOD_ACT_STAT_ENABLE(service_name, module_name, action_name);
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.
SERV_MOD_ACT_STAT_ENABLE
CLIENT_ID_STAT_DISABLE
DBMS_MONITOR.CLIENT_ID_STAT_ENABLE(client_identifier);CLIENT_ID_STAT_ENABLE
Example How to EnableProgram
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
DBA_ENABLED_AGGREGATIONS
Oracle Session Tracing
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
The action nameQUALIFIER_ID2
The module nameQUALIFIER_ID1
This is the CLIENT_IDENTIFIER or SERVICE_NAME in the callPRIMARY_ID
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
AGGREGATION_TYPE
DescriptionColumn
www.pinehorse.com www.dbcorral.com
Views that Contain Statistical Information
Oracle Session Tracing
•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.
V$SERV_MOD_ACT_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$SERVICE_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$CLIENT_STATS
•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.
DBA_HIST_ACTIVE_SESS_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.
V$ACTIVE_SESSION_HISTORY
DescriptionTable
www.pinehorse.com www.dbcorral.com
DBMS_MONITOR Package (Trace Control)
Oracle Session Tracing
SESSION_TRACE_DISABLE
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. If session_id and serial_number are NULL than you trace your own current session.
SESSION_TRACE_ENABLE
SERV_MOD_ACT_TRACE_DISABLE
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 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.
SERV_MOD_ACT_TRACE_ENABLE
CLIENT_ID_TRACE_DISABLE
DBMS_MONITOR.CLIENT_ID_TRACE_ENABLE(client_id, waits, binds);waits : If TRUE, wait information is present in the trace.Binds : If TRUE, bind information is present in the trace.
CLIENT_ID_TRACE_ENABLE
Example How to EnableProgram
Enable tracing for CLIENT_IDENTIFIER with wait information but no bind informationEXECUTE 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
DBA_ENABLED_TRACES
Oracle Session Tracing
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
Instance name for tracing restricted to named instances INSTANCE_NAME
Indicates whether binds are traced (TRUE) or not (FALSE) BINDS
Indicates whether waits are traced (TRUE) or not (FALSE) WAITS
The action nameQUALIFIER_ID2
The module nameQUALIFIER_ID1
This is the CLIENT_IDENTIFIER or SERVICE_NAME in the callPRIMARY_ID
Type of the trace: (CLIENT_ID, SERVICE, SERVICE_MODULE, SERVICE_MODULE_ACTION)NOT SESSION
TRACE_TYPE
DescriptionColumn
www.pinehorse.com www.dbcorral.com
Where is My Trace File
Oracle Session Tracing
USER_DUMP_DEST is the location on disk where Oracle will write out your enabled trace information.
SQL > SHOW PARAMETER user_dump_destNAME 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
SQL > ALTER SESSION SET TRACEFILE_IDENTIFIER = ‘SomeIdentifier;
Give Your Trace File Meaning
www.pinehorse.com www.dbcorral.com
Part of a Trace File
Oracle Session Tracing
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
Syntax & Example for trcsess
Oracle Session Tracing
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
What Can TKPROF Do
Oracle Session Tracing
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
Syntax & Example for TKPROF
Oracle Session Tracing
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
TKPROF Report
Oracle Session Tracing
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
Tracing Enhancements
Oracle Session Tracing
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. KoopmannFounder & President