Oaktable World 2014 Toon Koppelaars: database constraints polite excuse
Oracle 10g Performance: chapter 01 ash
1. ASH – Active Session History
Feel the Power
Kyle Hailey
http://perfvision.com
#.1
2. Why should you care?
Because ASH can Change your life …
10g immediately Accessible
Geeks: Via scripts in SQL
Managers : Graphical OEM
Stuck on Oracle 7,8,9 ?
… my apologies because 10g rocks, but …
no worries, the data is accessible for you too via scripts
http://perfvision.com/sash.php
Copyright 2006 Kyle Hailey #.2
3. Revolution and an Evolution
Oracle 6 … ie the dark ages … there
was once the Cache Buffer Hit Ratio
Oracle 7 … turned the lights on … Wait
Events … hallelujah I can see the light
Oracle 10g … ASH has landed
(like the wheels on the suitcases)
Copyright 2006 Kyle Hailey #.3
4. Sampling
New Paradigm
Clear Vision of the future
Use new sampling technology
Lets go of the need to know 100%
Statistical approximation
Cheaper
Richer Multidimensional Data
Identifies
SQL
Sessions
Objects
Machine
User
Copyright 2006 Kyle Hailey #.4
5. Identify Players before ASH
Sessions v$sesstat, v$session_event
# sessions x (# wait events + statistics)
Example (150 x (800+200) = 150,000 )
SQL
v$sql
Could be 10000s
Takes out latches that compete with other sql executions
Objects
Also files v$filestat
V$segstat 9i+
Could be 1000s of objects
Expensive !
Copyright 2006 Kyle Hailey #.5
6. ASH
Intelligence for the new Millennium
Intelligently Collects Data
Samples once a second
Collects active sessions only
Collects Session/SQL/Wait
More activity, more data collected
Less activity, less data collected
Those old methods collected everything
Obfuscated the problem, too many statistics too late
Costly
Too Granular – once an hour ?! Give me a break
Collects fine grain multidimensional data
Copyright 2006 Kyle Hailey #.6
7. ASH Fields
SQL> v$active_session_history
Name Null? Type
SAMPLE_ID NUMBER
SAMPLE_TIME TIMESTAMP(3)
SESSION_ID NUMBER
SESSION_SERIAL# NUMBER
USER_ID NUMBER
SQL_ID VARCHAR2(13)
SQL_CHILD_NUMBER NUMBER
SQL_PLAN_HASH_VALUE NUMBER
SQL_OPCODE NUMBER
SERVICE_HASH NUMBER
SESSION_TYPE VARCHAR2(10)
SESSION_STATE VARCHAR2(7)
QC_SESSION_ID NUMBER
QC_INSTANCE_ID NUMBER
EVENT VARCHAR2(64)
EVENT_ID NUMBER
EVENT# NUMBER
SEQ# NUMBER
P1 NUMBER
P2 NUMBER
P3 NUMBER
WAIT_TIME NUMBER
TIME_WAITED NUMBER
CURRENT_OBJ# NUMBER
CURRENT_FILE# NUMBER
CURRENT_BLOCK# NUMBER
PROGRAM VARCHAR2(48)
MODULE VARCHAR2(48)
ACTION VARCHAR2(32)
CLIENT_ID Copyright 2006 Kyle Hailey VARCHAR2(64 #.7
8. v$active_session_history
When SAMPLE_ID
SAMPLE_TIME
NUMBER
TIMESTAMP(3)
SESSION_ID NUMBER
SESSION_SERIAL# NUMBER
Session USER_ID
SERVICE_HASH
NUMBER
NUMBER
SESSION_TYPE VARCHAR2(10)
PROGRAM VARCHAR2(64)
MODULE VARCHAR2(48)
ACTION VARCHAR2(32)
CLIENT_ID VARCHAR2(64)
State SESSION_STATE VARCHAR2(7)
WAIT_TIME NUMBER
EVENT VARCHAR2(64)
EVENT_ID NUMBER
EVENT# NUMBER
SEQ# NUMBER
Wait P1 NUMBER
P2 NUMBER
P3 NUMBER
WAIT_TIME NUMBER
TIME_WAITED NUMBER
CURRENT_OBJ# NUMBER
CURRENT_FILE# NUMBER
CURRENT_BLOCK# NUMBER0
SQL_ID VARCHAR2(13)
SQL_CHILD_NUMBER NUMBER
SQL SQL_PLAN_HASH_VALUE
SQL_OPCODE
NUMBER
NUMBER
QC_SESSION_ID NUMBER
QC_INSTANCE_ID NUMBER
Duration TIME_WAITED Copyright 2006 Kyle Hailey
NUMBER #.8
9. Primary Fields of ASH
Activity : Who, What, When, How
When SAMPLE_TIME Time
Who SESSION_ID Session
SESSION_STATE State
How
EVENT Wait
What SQL_ID SQL
Copyright 2006 Kyle Hailey #.9
10. Amazing things YOU can do
Top SQL Top Consumers Top Resources
SQL ID Session • CPU
Plan X User
Object X • Waits
Child#
Module.Action
• Event (800*)
Program • I/O
Service • File
Client • Block
Wait • Time
And Aggregated over any time Period
(32 columns in ASH 10.1)
Copyright 2006 Kyle Hailey #.10
11. Multi-dimensional
SQL
F1qcyh20550cf
Package
Procedure fj6gjgsshtxyx
Plan 0cjsxw5ndqdbc
Child #
8t8as9usk11qw
dr1rkrznhh95b
W
St a
10dkqv3kr8xa5
C at its
38zhkf4jdyff4 En PU ist
298wmz1kxjs1m
S q:
db QL TX
ics
db fil *Ne –
25 34 36 38 45 63 65 87 fil e s t b row
Sessions e ca r e
se tt a loc
qu ere k/r k
en d es co
Program Sqlplus Toad t i a re e t n t e
l r ad to nt
ea c l io
d ie n
nt
User Sys Scott System
Ap
pl
Service ic
GL OE IO at
io
n
#.11
13. Top CPU Session
Top CPU consuming Session in last 5 minutes
Select
Select
session_id, Who is the rogue session ?
session_id,
count(*)
count(*)
from
from
v$active_session_history
v$active_session_history
where
where
session_state= ‘ON CPU‘ and
session_state= ‘ON CPU‘ and
SAMPLE_TIME > sysdate – (5/(24*60))
SAMPLE_TIME > sysdate – (5/(24*60))
group by
group by
session_id
session_id
order by
order by
count(*) desc;
count(*) desc;
Copyright 2006 Kyle Hailey #.13
16. Top Waiting Session
Top Waiting Session in last 5 minutes
Select
Select
session_id,
session_id,
count(*)
count(*)
from
from
v$active_session_history
v$active_session_history
where
where
session_state=‘WAITING’ and
session_state=‘WAITING’ and
SAMPLE_TIME > SYSDATE -- (5/(24*60))
SAMPLE_TIME > SYSDATE (5/(24*60))
group by
group by
session_id
session_id
order by
order by
count(*) desc;
count(*) desc;
Copyright 2006 Kyle Hailey #.16
18. Top SQL from ASH
select
select
ash.SQL_ID , ,
ash.SQL_ID
sum(decode(ash.session_state,'ON CPU',1,0))
sum(decode(ash.session_state,'ON CPU',1,0)) "CPU",
"CPU",
sum(decode(ash.session_state,'WAITING',1,0))
sum(decode(ash.session_state,'WAITING',1,0)) --
sum(decode(ash.session_state,'WAITING', decode(en.wait_class, 'User I/O',1,0),0))
sum(decode(ash.session_state,'WAITING', decode(en.wait_class, 'User I/O',1,0),0)) "WAIT" , ,
"WAIT"
sum(decode(ash.session_state,'WAITING', decode(en.wait_class, 'User I/O',1,0),0))
sum(decode(ash.session_state,'WAITING', decode(en.wait_class, 'User I/O',1,0),0)) "IO" , ,
"IO"
sum(decode(ash.session_state,'ON CPU',1,1)) "TOTAL"
sum(decode(ash.session_state,'ON CPU',1,1)) "TOTAL"
from v$active_session_history ash,
from v$active_session_history ash,
v$event_name en
v$event_name en
where SQL_ID is not NULL and en.event#=ash.event#
where SQL_ID is not NULL and en.event#=ash.event#
group by sql_id
group by sql_id
order by sum(decode(session_state,'ON CPU',1,1)) desc
order by sum(decode(session_state,'ON CPU',1,1)) desc
Copyright 2006 Kyle Hailey #.18
22. Top Session w/ Username
select
select
decode(nvl(to_char(s.sid),-1),-1,'DISCONNECTED','CONNECTED')
decode(nvl(to_char(s.sid),-1),-1,'DISCONNECTED','CONNECTED')
"STATUS",
"STATUS",
topsession.session_id
topsession.session_id "SESSION_ID",
"SESSION_ID",
u.name "NAME",
u.name "NAME",
topsession.program
topsession.program "PROGRAM",
"PROGRAM",
max(topsession.CPU)
max(topsession.CPU) "CPU",
"CPU",
max(topsession.WAITING)
max(topsession.WAITING) "WAITING","WAITING",
max(topsession.IO)
max(topsession.IO) "IO",
"IO",
max(topsession.TOTAL)
max(topsession.TOTAL) "TOTAL"
"TOTAL"
from ( ( {previous query} ) ) topsession,
from {previous query} topsession,
v$session s,
v$session s,
user$ uu
user$
where
where
u.user# =topsession.user_id and
u.user# =topsession.user_id and
/*/* outerjoin to v$session because the session might be disconnected */*/
outer join to v$session because the session might be disconnected
topsession.session_id
topsession.session_id == s.sid
s.sid (+) and
(+) and
topsession.session_serial# ==s.serial# (+)
topsession.session_serial# s.serial# (+)
group by topsession.session_id, topsession.session_serial#, topsession.user_id,
group by topsession.session_id, topsession.session_serial#, topsession.user_id,
topsession.program, s.username,s.sid,s.paddr,u.name
topsession.program, s.username,s.sid,s.paddr,u.name
order by max(topsession.TOTAL) desc
order by max(topsession.TOTAL) desc
Copyright 2006 Kyle Hailey #.22
23. Top Session
Finding a Rogue User
STATUS SESSION_ID NAME PROGRAM CPU WAITING
STATUS SESSION_ID NAME PROGRAM CPU WAITING IOIO
--------------- ---------- ---------- ------------------------- ----- ---------- ----
--------------- ---------- ---------- ------------------------- ----- ---------- ----
CONNECTED 247 CPU_Monger ChMgr304.exe 11704 00 00
CONNECTED 247 CPU_Monger ChMgr304.exe 11704
CONNECTED 277 SYS oracle@labsfrh903 (LGWR) 14 19 00
CONNECTED 277 SYS oracle@labsfrh903 (LGWR) 14 19
CONNECTED 278 SYS oracle@labsfrh903 (DBW0) 29 00 00
CONNECTED 278 SYS oracle@labsfrh903 (DBW0) 29
CONNECTED 276 SYS oracle@labsfrh903 (CKPT) 18 99 00
CONNECTED 276 SYS oracle@labsfrh903 (CKPT) 18
CONNECTED 280 SYS oracle@labsfrh903 (PMON) 20 00 00
CONNECTED 280 SYS oracle@labsfrh903 (PMON) 20
DISCONNECTED 255 SYSTEM Executor.exe 11 44 55
DISCONNECTED 255 SYSTEM Executor.exe 11
DISCONNECTED 257 SYSTEM Executor.exe 13 00 33
DISCONNECTED 257 SYSTEM Executor.exe 13
DISCONNECTED 255 SYSTEM Executor.exe 14 00 22
DISCONNECTED 255 SYSTEM Executor.exe 14
DISCONNECTED 257 SYSTEM Executor.exe 13 00 33
DISCONNECTED 257 SYSTEM Executor.exe 13
Copyright 2006 Kyle Hailey #.23
24. Many Ways to Attack Problems
Confusing
How to Attack the problem?
Top SQL?
Top wait for that SQL?
Top Waiting Session ?
Top Waits for that Session
Top Waits for Database?
Top Session waiting for that wait
Top SQL for that wait
Solution - Graphics
Copyright 2006 Kyle Hailey #.24
25. Mining Data is Non Trivial
Many Dimensions to consider
Constantly Varying time frames
Luckily 10g automates all of this functionality.
collectsall of the data
analyses all the wait events
reports on bottlenecks
supplies solutions
Graphics add tremendous ease and power
Copyright 2006 Kyle Hailey #.25
27. ASH Sampling Cheap
Cost
1. With PL/SQL it’s less that 1 % CPU with 10 average
active sessions
2. DMA - direct memory attach to SGA Using C code 200x
Cheaper
3. ASH in 10g should be even cheaper than DMA because
it’s done in the kernel
Size
Circular Buffer - 1M to 128M (~2% of SGA)
Avg row around 150bytes
3600 secs in an hour
~ ½ Meg per Active Session per hour
Copyright 2006 Kyle Hailey #.27
28. How ASH works
V$session_wait
+ v$session +
extras
MMON/
MMNL
v$active_session_history Only writes out 1 in 10 rows
via direct path inserts
wrh$_active_session_history
MMON - manageability monitor, AWR
M000 – MMON background slave, runs snapshots
MMNL - MMON lite, flushes ASH to disk
Copyright 2006 Kyle Hailey #.28
29. ASH buffer
Select reads
backwards Insert point Insert one direction
-No latching Touch up wait times
-Index on time
-No read consistency
Copyright 2006 Kyle Hailey #.29
30. Family of ASH Tables
Real time
v$session (before 10g v$session_wait)
Last 10 waits
v$session_wait_history
~2 hours
v$active_session_history
1 week
DBA_HIST_ACTIVE_SESS_HISTORY
wrh$active_session_history
Copyright 2006 Kyle Hailey #.30
31. Oradebug
Dump to trace file
SQL> oradebug dump ashdump 5
SQL> oradebug dump ash 5
SQL> Alter session set events ‘immediate
SQL> Alter session set events ‘immediate
trace name ashdump level 5’;
tracename ashdump level 5’;
level 5 = # of minutes
loader file rdbms/demo/ashldr.ctl
Copyright 2006 Kyle Hailey #.31
32. INIT.ORA
statistics_level = Typical (default)
PARAMETER SESSION_VALUE INSTANCE_VAL
----------------------- ---------- ------------
_ash_sampling_interval 1000 1000
milliseconds
_ash_size 1048618 1048618
ASH buffer size
_ash_enable TRUE TRUE
Turn on/off ASH sampling, flushing and the V$ views on ASH
_ash_disk_write_enable TRUE TRUE
Flush to disk
_ash_disk_filter_ratio 10 10
write 1 in 10 points
_ash_sample_all FALSE FALSE
Sample including idle waits
Copyright 2006 Kyle Hailey #.32
33. 10.2 ASH Extras
Blocking Session !
BLOCKING_SESSION RAC event Fixup
BLOCKING_SESSION_STATUS Plan Hash Fix up
10gR1 - during parsing no plan,
BLOCKING_SESSION_SERIAL# good way to find parsing
Parameter Names problems
P1TEXT , P2TEXT, P3TEXT
10gR2 – get plan hash fixup –
good but lose some ability to find
Wait Grouping parsing problems
WAIT_CLASS
WAIT_CLASS_ID
XID
FORCE_MATCHING_SIGNATURE
Cursor sharing
02/20/13 #.33
33
38. ASH Across Versions
When
Who
SQL
ASH
instrumentation
is exploding
across the
versions
Waits
Statistics
Blocker
10.1 10.2 10.2.0.3 11.1 11.2
Copyright 2006 Kyle Hailey #.38
39. How Many Active Sessions?
How much data does ASH Collect ?
1 CPU means max 1 Avg Active Session unless
there is a bottleneck
Big site examples:
Oracle 4 way RAC internal apps
10,000 connected, 200 active
One Site
3000 connected, 30 Active
Site
12,000 connected, 100 active
Copyright 2006 Kyle Hailey #.39
40. ASH Summary
Rich & Multidimensional
Overview of system load
Drilldowns into problems
Sql
Session
Wait event
Details information on problem resolution
Sampling is the future
Took clean vision to create - Bit of a leap of faith
Less Accurate but more powerful than past
Inaccuracies unimportant for the most part
Feasible since version 7
You can implement it yourself
OEM simplifies mining of ASH data
Copyright 2006 Kyle Hailey #.40
41. Q1
How can you immediately find the top IO consuming SQ
statement in the last 60 seconds
a. v$active_session_history
b. v$sqlstats answer
c. v$sql a only
d. v$sqlarea others
b,c,d - only have cumulative values
since database startup
Copyright 2006 Kyle Hailey #.41
42. Q2
Which view can you query directly to
get the specific waits that occurred
30 minutes ago:
a. v$active_session_history
b. v$waitclassmetric
c. v$system_event
d. v$session_wait_history
e. v$waitclassmetric_history
a only
b - last 60 seconds only
c - cumulative info since db startup
d - last 10 waits only
e - only wait groups, not wait events, but has
the history for last hour
Copyright 2006 Kyle Hailey #.42
43. Q3
ASH (v$active_session_history) is a revolutionary data
source for monitoring and analyzing database
performance. The view v$active_session_history is new
in 10g, but most of the data needed in order to simulate
v$active_session_history by hand has been available
since which version
b - since version 7 when wait events
a. 6 were introduced along with the view
b. 7 v$session_wait
c. 8
d. 9 which is the foundation for ASH
e. 10
Copyright 2006 Kyle Hailey #.43
Notes de l'éditeur
Sampling is a leap in performance tuning technology. It took a clear vision of the future and a bit of a leap of faith to let go of the compulsive need to have exact measurements and instead embrace sampling a technology that statistically approximates the same value with little loss of accuracy but at the same time brings a much great wealth of information necessary for analyzing the performance of a database.
WAIT_TIME is time of last wait, > 0 , means on CPU TIME_WAITED is the actual wait time
Select session_id, session_serial# , count(*) , round((count(*)*100)/(5*60),0) "%", lpad('*',round((count(*)*10)/(5*60),0),'*') "Bar" from v$active_session_history where session_state= 'ON CPU' and SAMPLE_TIME > sysdate - (5/(24*60)) group by session_id, session_serial# order by count(*) desc /
Graphics – humans can process 400,000 times as much data graphically as textually Think of a map of the US and all the counties with birth rates colored from low to high. It’s a massive about of information textually but it can all be seen on one page of a map Select session_id, session_serial# , count(*) , round((count(*)*100)/(5*60),0) "%", lpad('*',round((count(*)*10)/(5*60),0),'*') "Bar" from v$active_session_history where session_state= 'ON CPU' and SAMPLE_TIME > sysdate - (5/(24*60)) group by session_id, session_serial# order by count(*) desc /
ASH _ash_enable = false; [ A dynamic parameter will turn off ASH sampling, flushing and the V$ views on ASH ] ADDM _addm_auto_enable = false; [ A dynamic parameter to turn off automatic ADDM runs after every AWR snapshot ] AWR "_swrf_mmon_flush" = FALSE ; AWR metrics "_swrf_mmon_metrics" = FALSE ; METRICS DB Feature Usage "_swrf_mmon_dbfus" = FALSE ; DB Feature Usage "_swrf_on_disk_enabled" = FALSE ; disable all (on disk, including manual) AWR operations:
set linesize 120 col entry_package for a25 col entry_procedure for a25 col cur_package for a25 col cur_procedure for a25 col calling_code for a70 select procs1.object_name || decode(procs1.procedure_name,'','','.')|| procs1.procedure_name ||' '|| decode(procs2.object_name,procs1.object_name,'',procs2.object_name) || decode(procs2.procedure_name,procs1.procedure_name,'', decode(procs2.procedure_name,'','',null,'','.')||procs2.procedure_name) "calling_code", sql_id, count(*) from v$active_session_history ash, all_procedures procs1, all_procedures procs2 where ash.PLSQL_ENTRY_OBJECT_ID = procs1.object_id (+) and ash.PLSQL_ENTRY_SUBPROGRAM_ID = procs1.SUBPROGRAM_ID (+) and ash.PLSQL_OBJECT_ID = procs2.object_id (+) and ash.PLSQL_SUBPROGRAM_ID = procs2.SUBPROGRAM_ID (+) and ash.sample_time > sysdate - &minutes/(60*24) group by procs1.object_name, procs1.procedure_name, procs2.object_name, procs2.procedure_name,sql_id order by count(*) /
answer a only others b - last 60 seconds only c - cumulative info since db startup d - last 10 waits only e - only wait groups, not wait events, but has the history for last hour 8 ==================================================================== Chapt 1 ASH ASH (v$active_session_history) is a revolutionary data source for monitoring and analyzing database performance. The view v$active_session_history is new in 10g, but most of the data needed in order to simulate v$active_session_history by hand has been available since which version a. 6 b. 7 c. 8 d. 9 e. 10 answer b - since version 7 when wait events were introduced along with the view v$session_wait which is the foundation for ASH 4 ==================================================================== Chapt 1 ASH How can immediate find the top IO consuming SQL statement in the last 60 seconds a. v$active_session_history b. v$sqlstats c. v$sql d. v$sqlarea answer a only others b,c,d - only have cumulative values since database startup
answer 4 ==================================================================== Chapt 1 ASH How can immediate find the top IO consuming SQL statement in the last 60 seconds a. v$active_session_history b. v$sqlstats c. v$sql d. v$sqlarea answer a only others b,c,d - only have cumulative values since database startup