Professional Documents
Culture Documents
Tanel Poder
• Tanel Põder
• Oracle Database Performance geek (18+ years)
• Exadata Performance geek
• Linux Performance geek
• Hadoop Performance geek
Instant
promotion
SID 11 SELECT X
Time
V$SQL, V$SQLSTATS, Statspack/AWR Top SQL reports measure SQL performance, not
sessions’ performance
SID 11 SELECT X
Time
Session-level detail
Breakdown by SQL Statements +
Breakdown by Wait Events
Basic performance counters (logical IOs, parses etc)
Full chronological detail of session activity
No instance-wide coverage in realistic cases
Getting the Most Out of ASH blog.tanelpoder.com
© Tanel Poder
6
What is Oracle Database activity about?
1. A bunch of sessions
• You need a session for doing anything in Oracle
Oracle
Process
V$SESSION (thread)
MMNL Active session
process SID
SID 1 SID 2 SID 3 ...
samples 999
SID 11 SELECT X
Time
Sample session 3 x SELECT A 3 x UPDATE C
Count the number of
2 x SELECT A
(active) sessions each
activity over
time ->
1 x SELECT X
1 x SELECT Y
1 x SELECT X
1 x SELECT Y
… 1 x SELECT X
1 x SELECT Y sample,
1 x SELECT N 1 x SELECT N group by SQL ID
(v$session)
Getting the Most Out of ASH blog.tanelpoder.com
© Tanel Poder
13
Sampling session activity – Working or Waiting?
SID 11 SELECT X
CPU Time
User IO
Session
Locks
count
Commit
Time
Getting the Most Out of ASH blog.tanelpoder.com
© Tanel Poder
14
On-line Active Session History and historical ASH
• In-memory array
• One in each instance
• Designed to keep at least 1 hour of history in memory
• MMNL process copies active session info from V$SESSION and an "ASHLoc"
memory structure there once per second
• 1 sample = 1 second
• V$ACTIVE_SESSION_HISTORY
• Long-term history
• One per database
• Retention configured using the AWR retention parameter
• Only 10% of samples saved by default to save space This is used when
switching to
• 1 sample = 10 seconds Historical view in
• DBA_HIST_ACTIVE_SESS_HISTORY OEM
, SUM(time_waited) 1 SELECT
seconds 2 sql_id
3 , SUM(time_waited) this_is_wrong
FROM
4 FROM
v$active_session_history 5 v$active_session_history
WHERE 6 WHERE
7 sample_time > SYSDATE-1/24/12
sample_time BETWEEN … 8 AND sql_id = '2vp4k2kgy2wm4'
ORDER BY 9 GROUP BY
10 sql_id
seconds DESC 11 ORDER BY
ASH does not trace every single wait there is! 12* this_is_wrong DESC
SQL> /
Therefore information about many short waits that
happened between ASH samples is lost! SQL_ID THIS_IS_WRONG
------------- -------------
However, counting the number of samples where a 2vp4k2kgy2wm4 0
session was active gives a good approximation of
where was the DB time spent
Getting the Most Out of ASH blog.tanelpoder.com
© Tanel Poder
17
A simple ASH drilldown example Who’s
running
SELECT SQL> SELECT
this SQL?
dimension1 2 sql_id
3 , session_id,session_serial#
, dimension2 4 , COUNT(*) seconds
, COUNT(*) seconds 5 FROM
6 v$active_session_history
FROM 7 WHERE
v$active_session_history 8 sample_time > SYSDATE-1/24/12
9 AND sql_id = '2vp4k2kgy2wm4'
WHERE
10 GROUP BY
sample_time BETWEEN … 11 sql_id
12 , session_id,session_serial#
AND sql_id = ‘2vp4k2kgy2wm4’
13 ORDER BY
ORDER BY 14* seconds DESC
seconds DESC SQL> /
You can drill down into a single SQL, single SQL_ID SIDSERIAL SECONDS
application or a session by just adding WHERE ------------- ---------- ----------
conditions for filtering data. 2vp4k2kgy2wm4 789,14653 62
2vp4k2kgy2wm4 789,14631 59
You can see more detail by just adding ASH 2vp4k2kgy2wm4 803,61957 56
dimension fields to the GROUP BY clause ...
Getting the Most Out of ASH blog.tanelpoder.com
© Tanel Poder
18
WHERE
SELECT ...
sample_time
COUNT(*)
BETWEEN ...
FROM ash
GROUP BY
wait_class
GROUP BY
sample_time GROUP BY
SESSION_ID,
GROUP BY USERNAME ...
GROUP BY
wait_class
SQL_ID ...
Time spent by
background processes,
it's not a direct
indicator of user
response time
Getting the Most Out of ASH blog.tanelpoder.com
© Tanel Poder
21
Basic Troubleshooting Examples
Throughput has
dropped!
We are doing
less I/Os?!
Throughput has
dropped!
A single SQL
consuming 80% of
wait time
No single session
waiting much
more than others
Getting the Most Out of ASH blog.tanelpoder.com
© Tanel Poder
32
Drill down into the problem SQL
First impression:
This SQL has not
been executed or
not used much
resource in past?
After
Before
Same data,
broken down by
plan hash value
• You can break down the time consumption using GROUP BY on ASH
dimension attribute columns, to get TOP-reports:
• SQL ID
• Wait event
• User ID
• Session ID
• Program
Getting the Most Out of ASH blog.tanelpoder.com
© Tanel Poder
43
Top-activity by ASH dimensions
Basic ASH
attributes to
group TOP
activity by
1. Which DB operation?
• Login, Cursor open/close, Parse, SQL Execute, PL/SQL Execute, LOB access?
Time Model,
1. Which SQL statement? top_level_call_name
sql_opname
• Or PL/SQL procedure
• Which execution plan version? SQL_ID
TOP_LEVEL_SQL_ID
PL_SQL_OBJECT_ID
1. Working on CPU or Waiting? ...
• If waiting, for what?
SESSION_STATE
EVENT
2. When? P1,P2,P3
• sample_time
==============================================================================================
== SQLs with many child cursors under a parent (use nonshared*.sql to find the reasons) ==
==============================================================================================
Sequence altered.
Getting the Most Out of ASH blog.tanelpoder.com
© Tanel Poder
57
Time Model Hierarchy
1) background elapsed time DB Time is the total
2) background cpu time time the DB spent
3) RMAN cpu time (backup/restore) servicing application
calls in DB
1) DB time
2) DB CPU
2) connection management call elapsed time Use the "parse
2) sequence load elapsed time elapsed time"
2) sql execute elapsed time numbers for
2) parse time elapsed estimating parsing
3) hard parse elapsed time overhead.
4) hard parse (sharing criteria) elapsed time
5) hard parse (bind mismatch) elapsed time
3) failed parse elapsed time
4) failed parse (out of shared memory) elapsed time
2) PL/SQL execution elapsed time
2) inbound PL/SQL rpc elapsed time Check
2) PL/SQL compilation elapsed time
v$sess_time_model in
Oracle Reference
2) Java execution elapsed time
docs:
2) repeated bind elapsed time
http://bit.ly/11pkGjS
Getting the Most Out of ASH blog.tanelpoder.com
© Tanel Poder
58
Wait Events
1. The SQL is doing too much IO (bad plan, too much data, etc)
• Revert back to the good plan
• Drill down into the SQL query and optimize it
• Locks taken and released at will by the application code (TM,TX) are
listed in Application wait class (not Concurrency)
• If there's a single session causing most of the blocking,
see what that session was doing while others waited Common cause for TM
on its lock locks is DML on parent
tables with unindexed
• Just query ASH data for that session only (within the foreign keys:
blocking time range) http://bit.ly/aeANst
SQL> @bclass 1
Find the hot block
CLASS UNDO_SEGMENT_ID using P1/P2 and
------------------ --------------- block type with P3
data block
OWNER SEGMENT_NAME
------------------------------ ------------
SOE LOGON
• 11.2+
SQL> SELECT inst_id, oldest_sample_time, sysdate - oldest_sample_time ash_in_memory
FROM gv$ash_info;
• 10g+
SQL> SELECT inst_id, min(sample_time), sysdate - MIN(sample_time) ash_in_memory
FROM gv$active_session_history GROUP BY inst_id;
2. Activity % breakdown
• If DB Time was spent mostly on CPU then look into CPU Activity % column
• If DB Time was spent mostly on waiting then Wait Activity % column
• This tells you in which execution plan line(s) most of the time was spent
• If you open a cursor and don't fetch for a while, the Duration still keeps
increasing
• So if you run an 1-hour DML statement with 8 parallel slaves, you may see DB
Time up to 9hours (up to 1h for the QC, up to 8h for all PX slaves)
DB Time = 1.3
seconds
(time spent inside
DB)
Duration = 9 seconds
(wall-clock time)
DB Time = ~36
seconds
(time spent inside
Parallel Execution! DB)
• Every single bind variable value put in place during the tracing
• Some exotic datatypes can’t be dumped human-readably though
• Use ASH data to identify problem SQL and drill down with SQL trace
• If needed...
• Either use a login trigger or ALTER SYSTEM
SQL> ALTER SESSION SET EVENTS 'sql_trace[SQL: 32cqz71gd8wy3 ] -
plan_stat=all_executions,wait=true,bind=true';
Session altered.
Session altered.
• http://www.nocoug.org/download/2013-
08/NOCOUG_201308_ASH_Architecture_and_Advanced%20Usage.pdf
• Or just google for ASH Architecture and Advanced Usage
• V$EVENT_NAME
• Includes wait_class, P1,P2,P3 meanings
• Just query it or use @sed.sql
Getting the Most Out of ASH blog.tanelpoder.com
© Tanel Poder
87
Thanks!
http://blog.tanelpoder.com
tanel@tanelpoder.com
New World!
http://gluent.com