Professional Documents
Culture Documents
Agenda
Understanding AWR
Overview of ADDM and ASH reports
Remote Diagnostics Report (RDA)
Understanding event 10046
TKPROF
Explain Plan
SQLTRP
Errorstack tracing
2
Overview of AWR
What is AWR (Automatic workload repository)?
The AWR is an oracle tool starting from oracle 10GR1used to collects
and stores database statistics relating to problem detection and
tuning.
AWR is a replacement for the statspack utility which helps gather
database performance statistics.
The AWR is used to collect performance statistics including:
Wait events used to identify performance problems.
Time model statistics indicating the amount of DB time
associated with a process from the V$SESS_TIME_MODEL and
V$SYS_TIME_MODEL views.
Active Session History (ASH) statistics from the
V$ACTIVE_SESSION_HISTORY view.
Some system and session statistics from the V$SYSSTAT and
V$SESSTAT views.
Object usage statistics, operating system statistics.
Resource intensive SQL statements.
Overview of AWR
What is AWR (Automatic workload repository)?
This information is accumulated in memory and periodically
flush/written to the database; to the tables that make up awr.
The awr is exists as a set of tables and other objects in the SYSAUX
tablespace.
The level of awr statistics gathered is controlled by parameter
STATISTICS_LEVEL (Dynamic).
The parameter STATISTICS_LEVEL can be set BASIC, ALL or
TYPICAL (Typical is the default setting)
Can change on ALTER SYSTEM or ALTER SESSSION level.
Periodically by default once an hour they are flushed to disk, to the
awr which is called snapshot.
the flushing to disk is done by the background process MMON
(Manageability monitor). This use of background process is the key
to the efficiency of the statistics collection process.
Overview of AWR
What is AWR (Automatic workload repository)?
The MMON is having direct access of memory structures that makes
up SGA and therefore the statistics within them.
AWR statistics are save as a snapshot to the awr by MMON
processes by default 60 mins (1 hr).
By default, the snapshots are stored for 8 days before being
overwritten.
The awr is the set of tables located in SYSUX tablespace, these
tables cannot be relocated..
AWR is the set of tables which owned by SYSMAN schema.
Snapshot can be thought as the collection/copy of the contents of
many views at the time of snapshot taken,
These statistics would be gathered with DBMS_STATS .
Overview of AWR
AWR (Automatic workload repository) architecture
Overview of AWR
What is AWR (Automatic workload repository)?
DBMS_WORLOAD for snapshots
Overview of AWR
Workload repository views?
The following workload repository views are available:
Overview of AWR
What is AWR (Automatic workload repository)?
To run AWR report we can use the SQL scripts or use Enterprise
Manager.
Overview of AWR
What is AWR (Automatic workload repository)?
Generate AWR Report using command line
AWRRPT.SQL : Report for current instance youre logged on
AWRRPTI.SQL : Report for any instance in AWR
Listing the last day's Completed Snapshots
Snap
Instance
DB Name
Snap Id
Snap Started
Level
------------ ------------ --------- ------------------ ----V1024
V1024
177 26 May 2009 00:00
1
178 26 May 2009 01:00
1
Specify the Begin and End Snapshot Ids
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Enter value for begin_snap: 177
Begin Snapshot Id specified: 177
Enter value for end_snap: 178
End
Snapshot Id specified: 178
Specify the Report Name
~~~~~~~~~~~~~~~~~~~~~~~
The default report file name is awrrpt_1_177_178.html. To use this name,
press <return> to continue, otherwise enter an alternative.
Enter value for report_name:
10
Overview of AWR
Generating the AWR Report
Generate an AWR Report with Enterprise Manager
11
9
13
14
10
11
15
13
17
14
Primary Sections
Snapshot Overview
Top 5 Timed Events
Init.ora parameters
Secondary Sections
SQL Statistics
Segment Statistics
IO Stats
12
18
15
19
15
21
Hardware changes
Database configuration changes
Schema changes
Application changes
Using other advisors
2003 IBM Corporation
The ASH report utility is useful for determining the amount of active sessions, what they were doing,
and which SQL statements were most active during a period of time. It is especially useful for
analyzing transient performance issues. The ashrpt.sql script is found in the
$ORACLE_HOME/rdbms/admin directory.
NOTE: You must have a license to use this script.
Stores the history of database time
Samples session activity in the system
Comprises of one-second samples of ACTIVE sessions on the instance
It extracts only samples of information from v$instance
We can run ASHRPT.SQL to generate ASH report.
ASH samples are stored in a circular buffer memory
Will be written to the disk during snapshot or if the buffer is full
This buffer is from SGA and is 2MB per CPU ( fixed )
ADDM uses ASH data heavily
Some important attributes of ASH samples are current session id,sql,wait event id.
V$ACTIVE_SESSION_HISTORY/ DBA_HIST_ACTIVE_SESS_HISTORY gives more details
16
22
ASH Report
16
23
It is possible to run a report on the ASH data collected, the report generates information
about SQL that ran during the time you specify and it includes blocking and wait details.
ashrpt.sql- $ORACLE_HOME/rdbms/admin (information on SQL which includes
blocking and wait details, the script will ask what you to specify a time and if the report
is to be generated in text to html.)
2003 IBM Corporation
25
37
26
37
27
38
19
28
20
29
10046
From SQL*Plus
SQL> alter session set events '10046 trace name context forever, level
12';
SQL> issue some SQL . . .
SQL> select close the cursor from dual; -- closes cursor for prev.
query
SQL> alter session set events '10046 trace name context off';
Using DBMS_SYSTEM.SET_EV
21
30
10046
Using ORADEBUG:
22
31
33
24
34
25
Overall Pattern
=====================
PARSING IN CURSOR #1 len=69 dep=0 uid=26 oct=42 lid=26 tim=1773902376 hv=1509700594
ad='7b526d78'
alter session set events '10046 trace name context forever, level 12'
END OF STMT
EXEC #1:c=0,e=0,p=0,cr=0,cu=0,mis=1,r=0,dep=0,og=4,tim=1773812376
WAIT #1: nam='SQL*Net message to client' ela= 22 p1=1111838976 p2=1 p3=0
=====================
PARSING IN CURSOR #2 len=34 dep=1 uid=26 oct=3 lid=26 tim=1774173376 hv=677152330 ad='7b584040'
SELECT c1 from fred where c2 = :b1
END OF STMT
PARSE #2:c=0,e=0,p=0,cr=0,cu=0,mis=1,r=0,dep=1,og=0,tim=1774173376
BINDS #2:
bind 0: dty=2 mxl=22(21) mal=00 scl=00 pre=00 oacflg=13 oacfl2=1 size=24 offset=0
bfp=0556b0bc bln=22 avl=02 flg=05
value=1
EXEC #2:c=30043,e=30000,p=0,cr=0,cu=0,mis=0,r=0,dep=1,og=4,tim=1774233376
FETCH #2:c=0,e=0,p=0,cr=1,cu=2,mis=0,r=0,dep=1,og=4,tim=1774233376
BINDS #2:
bind 0: dty=2 mxl=22(21) mal=00 scl=00 pre=00 oacflg=13 oacfl2=1 size=24 offset=0
bfp=0555ded8 bln=22 avl=02 flg=05
value=2
EXEC #2:c=30043,e=30000,p=0,cr=0,cu=0,mis=0,r=0,dep=1,og=4,tim=1774603376
FETCH #2:c=0,e=0,p=0,cr=1,cu=2,mis=0,r=0,dep=1,og=4,tim=1774613376
=====================
XCTEND rlbk=0, rd_only=1
STAT #2 id=1 cnt=0 pid=0 pos=0 obj=5025 op='TABLE ACCESS FULL FRED '
26
35
27
36
EXEC #2:c=30043,e=30000,p=0,cr=0,cu=0,mis=0,r=0,dep=1,og=4,tim=1774233376
FETCH #2:c=0,e=0,p=0,cr=1,cu=2,mis=0,r=0,dep=1,og=4,tim=1774233376
PARSE #2:c=0,e=0,p=0,cr=0,cu=0,mis=1,r=0,dep=1,og=0,tim=1774173376
c= 30043 CPU time in microseconds
e= 30000 Elapsed time
p=0
Physical reads
cr=0
consistent reads
cu=0
current mode gets
mis=1
Library Cache misses. This case, 1, means we just had a hard parse.
r=0
rows processed
dep=1
recursive depth
og=4
Optimizer mode: 1= All_Rows; 2= First_Rows, 3=Rule, 4= Choose.
tim=1773812376 The ubiquitous timestamp, in microseconds. Not wall clock time.
37
28
offset=0
bfp=0555ded8 UGA buffer pointer
bln=22
Buffer length
avl=02
Value length
flg=05
Bitmask, see kxs.h
value=2
Actual value of bind variable
38
29
Wait Events
WAIT #1: nam='SQL*Net message to client' ela= 22 p1=1111838976 p2=1 p3=0
nam='SQL*Net
ela= 22
p1=1111838976
p2=1
p3=0
id=1
cnt=0
pid=0
pos=0
obj=5025
op='TABLE ACCESS FULL FRED
Operation ID
Count of output rows
Parent Operation ID
Position
Object #
Operation
Extremely valuable for SQL tuning because we see exactly how many
rows were involved in each plan step vs. the EXPLAIN PLAN where we
only see an estimate of the rows
40
31
TKPROF Utility
Usage: tkprof tracefile outputfile [explain= ] [table= ]
[print= ] [insert= ] [sys= ] [sort= ]
table=sch.tname
explain=un/pw
print=<n>
aggregate=yes|no
insert=filename
sys=no
record=filename
waits=yes|no
sort=option
41
32
Explain
Runs EXPLAIN under the specified username, and prints the EXPLAIN output together with the
SQL statements. The users need not currently have a PLAN_TABLE but must have the privilege
to create it. Note that the execution plans are the ones that would be chosen when TKPROF
was run.
Waits
This option is new in Oracle9i; it produces a summary of all waits found in the trace file. Note,
however, that there is no documented or supported way for customers to produce wait
information in their trace files. You can only achieve that with event 1046 level 8, to be
discussed later in this lesson.
42
33
Example:
sort = exeela orders by elapsed time during execution;
sort = fchcpu execpu orders by fetch cpu time and execution
is the largest.
43
34
Sample TKProf
update
call
count
------- -----Parse
1
Execute
17
Fetch
0
------- -----total
18
cpu
elapsed
disk
query
current
-------- ---------- ---------- ---------- ---------0.01
0.00
0
0
0
0.07
162.56
0
268
123
0.00
0.00
0
0
0
-------- ---------- ---------- ---------- ---------0.08
162.57
0
268
123
rows
---------0
1071
0
---------1071
44
35
Max. Wait
---------2.92
0.00
0.97
0.00
Total Waited
-----------162.45
0.00
9.71
0.00
TKPROF: Example
Summary
OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS
call
count
cpu
elapsed
disk
query
current
------- ------ -------- ---------- ---------- ---------- ---------Parse
0
0.00
0.00
0
0
0
Execute
0
0.00
0.00
0
0
0
Fetch
0
0.00
0.00
0
0
0
------- ------ -------- ---------- ---------- ---------- ---------total
0
0.00
0.00
0
0
0
Misses in library cache during parse: 0
2 user SQL statements in session.
0 internal SQL statements in session.
2 SQL statements in session.
rows
---------0
0
0
---------0
********************************************************************************
Trace file: /u01/app/oracle/admin/DB10gR1/udump/db10gr1_ora_1986.trc
Trace file compatibility: 10.01.00
Sort options: default
3
2
0
2
2
663
178
45
36
sessions in tracefile.
user SQL statements in trace file.
internal SQL statements in trace file.
SQL statements in trace file.
unique SQL statements in trace file.
lines in trace file.
elapsed seconds in trace file.
EVENT: ERRORSTACK
WHAT IS IT AND HOW TO TAKE THIS
Levels:
0
Print the date and time / Dump the Oracle error stack
Dump the current sql statement and pl/sql call stack ,Dump the call stack
46
17
SPIN : Errorstack
HANG : Systemstate(3)/HangAnalyze(2)
SLOW : statspack/awr
DBLocking : Errorstack(Before this we will take
Systemstate/hanganalyze)
18
47
Explain Plan
ORACLE_HOME/rdbms/admin/utlxpls - Displays the explain plan for last Explain command.
ORACLE_HOME/rdbms/admin/utlxplp Displays the parallel query info.
48
SQLTRPT
ORACLE_HOME/rdbms/admin/sqlrtpt.sql
Script that gets a single statement as input from the user (via SQLID),
Rem
tunes that statement, and then displays the text report.
SQL> @C:\oracle\product\11.2.0\dbhome_1\RDBMS\ADMIN\sqltrpt.sql
15 Most expensive SQL in the cursor cache
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SQL_ID
ELAPSED SQL_TEXT_FRAGMENT
------------- ---------- -----------------------------------------------------gtvg6a7quptab
23.42 DECLARE cnt
NUMBER; bid
NUMBER; eid
fskyn4u39manv
11.75 DECLARE job BINARY_INTEGER := :job; next_date TIMESTA
cvn54b7yz0s8u
10.40 select /*+ index(idl_ub1$ i_idl_ub11) +*/ piece#,lengt
:
15 Most expensive SQL in the workload repository
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SQL_ID
ELAPSED SQL_TEXT_FRAGMENT
------------- ---------- -----------------------------------------------------b6usrg82hwsa3 348.42 call dbms_stats.gather_database_stats_job_proc ( )
59v4zh1ac3v2a 145.78 DECLARE job BINARY_INTEGER := :job; next_date TIMESTA
7mgr3uwydqq8j 114.81
select decode(open_mode, 'MOUNTED', 0,
424h0nf7bhqzd 105.02 SELECT sqlset_row(sql_id, force_matching_signature,
c0j6cx9kzjf7g
85.33 SELECT EXTRACTVALUE(VALUE(T), '/select_list_item/pos')
:
49
1- Original
----------Plan hash value: 1147449465
-------------------------------------------------------------------------| Id | Operation
| Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------| 0 | SELECT STATEMENT |
| 29 | 870 | 715 (1)| 00:00:09 |
|* 1 | TABLE ACCESS FULL| TT1 | 29 | 870 | 715 (1)| 00:00:09 |
--------------------------------------------------------------------------
50
References
Note: 376442.1 : Recommended Method for Obtaining 10046 trace for
Tuning
51
39
Questions
?
52