Вы находитесь на странице: 1из 32

_________________________________

_________________________________
_________________________________
_________________________________

Advanced Internal
Oracle Tuning
Techniques for
SAP Systems

_________________________________
_________________________________
_________________________________
_________________________________
_________________________________

Michael Kennedy
SMS Consulting

_________________________________

2008 Wellesley Information Services. All rights reserved.

What Well Cover

_________________________________

Understanding index design


Proactive review of poorly performing SQL
10053 CBO trace
Oracle Wait Events
10046 tracing
SAP transactions for tuning
Oracle best practices
Wrap-up

_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
1

B*Tree Design

_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
2

B*Tree Indexes

B*Tree indexes are always balanced

_________________________________
_________________________________

All leaf blocks, which hold the row ID, are on the same level

_________________________________

Index entries are always ordered


Index scans use a db file sequential read

_________________________________
_________________________________

Single block fetch (not a multi-block fetch), except for Index


Fast Full Scan
Can be slow for large index RANGE scans

_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
3

Optimal Oracle Block Access

_________________________________

What is the optimal number of blocks read for


an index?

_________________________________
_________________________________

The optimal number of blocks being accessed in Oracle is


between 3 and 5.
During a unique scan down the index, the root block, branch
block, leaf block, then the table data is read into the database
cache. Depending on the height of the index, a unique scan will
only read 3 to 5 blocks.
Use the 3 to 5 blocks as the optimal value to compare with
other inefficient SQL statements.

_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
4

What Well Cover

_________________________________

Understanding index design


Proactive review of poorly performing SQL
10053 CBO trace
Oracle Wait Events
10046 tracing
SAP transactions for tuning
Oracle best practices
Wrap-up

_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
5

Proactive Review of Poor SQL

What is poor SQL?

_________________________________
_________________________________

Inefficient SAP programs, usually custom programs, can cause


excessive CPU and I/O loads on the database server
Millions of SQL statements can be called in an SAP system,
requiring frequently executed statements to be tuned to reduce
the impact on server resources

_________________________________
_________________________________
_________________________________
_________________________________

What is the return on investment?

_________________________________

Improved I/O and CPU times


Frequently used data (e.g., SD users) stays cached in Oracles
buffer cache longer, resulting in faster user response times
Improved SAP average dialog response times
Improved overall performance of the system

_________________________________
_________________________________
_________________________________
6

Proactive Review of Poor SQL (cont.)

_________________________________

ST04 Detailed Analysis SQL Requests

_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
7

Proactive Review of Poor SQL (cont.)

_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
8

Inefficient SQL

_________________________________

Example of an inefficient SQL statement

_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
9

Efficient SQL

_________________________________

Example of an efficient SQL statement

_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
10

SQL Statement General Rules

In general, RANGE scans may be slower and require additional


resources (CPU, memory, I/O)
Try to access the least amount of data down an index
Oracle joins may not be the fastest option depending on the
driving table of the inner join

_________________________________
_________________________________
_________________________________
_________________________________

If a join is slow, determine the inner-most index of the explain plan


If the index is not efficient, a custom index may be created
If the CBO is not picking the correct driving index, a HINT should be used
(SAP Note 130480)

_________________________________
_________________________________
_________________________________

Check SAP Notes for performance enhancements for suspected


transaction some standard SAP ABAP code may pass the
LITERALS instead of BIND variables

_________________________________
_________________________________

Example: MB51 transaction is slow due to large number of rows in


MSEG/MKPF
Applying SAP Note 921164 may change that with LITERALS instead of
BIND variables

_________________________________
11

What Well Cover

_________________________________

Understanding index design


Proactive review of poorly performing SQL
10053 CBO trace
Oracle Wait Events
10046 tracing
SAP transactions for tuning
Oracle best practices
Wrap-up

_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
12

CBO 10053 Trace

_________________________________

Tracing the CBO (event 10053) can help prove why the
CBO is not picking the correct index
Parameters that affect the CBO:

_________________________________
_________________________________

db_file_multiblock_read_count = 8
f The higher the value, the lower the cost of a full tablescan
optimizer_index_cost_adj = 10
f The lower the value, the lower the cost of an index access
Event 10183
f Used in conjunction with optimizer_index_cost_adj when two
indexes have a cost calculation less than one

_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________

13

CBO Optimizer Trace

_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
14

CBO Optimizer Trace Error

_________________________________

The error below is shown for some versions of SAP


However, the trace file is generated in:
/oracle/<SID>/saptrace/usertrace

_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
15

CBO Optimizer Trace Example

_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
16

When Should Oracle Indexes Be Rebuilt?

_________________________________

After large data deletes


When indexes are very large and you would like to
reclaim space
If an index has too many extents (greater than 1,000)
When there are SQL statements that do large RANGE
SCANS (<,>, like, between) on the index. Keeping the
indexes small will improve performance.

_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
17

Rebuilding Indexes

_________________________________

SAP Note 771929


DB02

_________________________________
_________________________________

Detailed Analysis Enter Index Detailed Analysis


Menu: Analyze Index Storage Quality
Uses Oracles DBMS_SPACE package to calculate space usage

_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
18

Rebuilding Indexes (cont.)

_________________________________

SAP Note 771929


SE38

_________________________________
_________________________________

Program RSORATAD
Ran for one hour on 20 GB index MSEG~0 with 304 million rows

_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________

19

Rebuilding Indexes (cont.)

_________________________________

SAP Note 771929


Analyze Index VALIDATE Structure

_________________________________
_________________________________

Analyze index &index validate structure


Select * from index_stats
Analyze will lock all DML on the table so run on a copy of
production

_________________________________
_________________________________
_________________________________

SQL> select name, height, lf_rows, del_lf_rows, pct_used from index_stats;

_________________________________
_________________________________

NAME
HEIGHT
LF_ROWS DEL_LF_ROWS
PCT_USED
-------------------- ---------- ---------- ----------- ---------TST03~0
3
159608
115497
54

_________________________________
_________________________________
20

How Do You Monitor Index Creation or Rebuild Status?

_________________________________
_________________________________

The index in this example is created with a parallel


degree of 5 and is being sorted in PSAPTEMP

_________________________________
_________________________________

create index "EKBE~Z1" on EKBE(MANDT,VGABE, BUDAT, WERKS)


tablespace psaprtl
online
parallel (degree 5)

_________________________________
_________________________________

select a.username, a.tablespace, b.sid, a.contents,a.segtype, a.extents, a.blocks*8192


"Bytes"
from v$sort_usage a, v$session b
where a.session_addr = b.saddr

_________________________________
_________________________________

USERNAME TABLESPACE
SID CONTENTS SEGTYPE
EXTENTS
Bytes
---------------------- ---------- --------- --------- ---------- ---------------SAPRTL
PSAPTEMP
393 TEMPORARY SORT
64
67,108,864
SAPRTL
PSAPTEMP
384 TEMPORARY SORT
40
41,943,040
SAPRTL
PSAPTEMP
367 TEMPORARY SORT
80
83,886,080
SAPRTL
PSAPTEMP
395 TEMPORARY SORT
61
63,963,136
SAPRTL
PSAPTEMP
382 TEMPORARY SORT
67
70,254,592
---------- ---------------sum
312
327,155,712

_________________________________
_________________________________
21

How Do You Monitor Index Creation or Rebuild Status? (cont.)

_________________________________

With this script, you can monitor the index being created
in the target tablespace

_________________________________

select segment_name, tablespace_name, bytes,


extents from dba_segments
where segment_type = 'TEMPORARY'
ORDER BY 2

_________________________________

SEGMENT_NAME
--------------31.680100
63.290980
97.325500
208.153460
237.178036
sum

_________________________________
_________________________________
_________________________________

TABLESPACE_NAME
BYTES
EXTENTS
--------------- ---------------- ---------PSAPRTL
98,631,680
84
PSAPRTL
79,626,240
81
PSAPRTL
85,262,336
82
PSAPRTL
81,002,496
81
PSAPRTL
95,420,416
86
---------------- ---------439,943,168
414

_________________________________
_________________________________
_________________________________
_________________________________
22

Tips for Index Creations and Rebuild

The pga_aggreagate_target only uses 100 MB for sorts. Using


_pga_max_size may help, which is a setting in BW.
Use the parallel query for faster creation times

_________________________________
_________________________________

Run the create or rebuild index during a low peak time, because high Data
Manipulation Language (DML) may cause a table lock (SAP Note 682926)

_________________________________
_________________________________

Use ONLINE keyword so the table is not locked


Use NOLOGGING to minimize redo generation

_________________________________

_________________________________

The index will need to be dropped and recreated if using Oracle dataguard
The index will need to be dropped and recreated if a recovery is needed if a
backup was not taken after the create or rebuild command

_________________________________
_________________________________

PSAPTEMP needs to be at least 1.5 times the size of the largest


index being created in order to hold the ordered data

_________________________________
_________________________________
23

Tips for Index Creations and Rebuild (cont.)

Schedule Index Rebuilds


SE38

_________________________________

Program RSANAORA
List of Indexes in variant

_________________________________

_________________________________

_________________________________

Online Index Rebuilds


If locking occurs Kill the Oracle SQL*Net process, NOT the SAP session

_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
24

Reactive Troubleshooting: User Performance Complaint

_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
25

Example: BSAS SQL Statement

_________________________________

ST04 Detailed Analysis Oracle Session

_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
26

BSAS Buffer Gets

_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
27

BSAS Solution

_________________________________

There have been 13,905 executions while the database


has been up for 20 days
That means this query is executed 695 times per day or
28 times per hour
Each execution needs to allocate 459 blocks of memory
to find almost ZERO rows
The BSAS statement has fetched almost 7 million blocks
into memory with only 6 rows found out of the 13,905
executions
Resolution:

_________________________________

Add ZUONR to the custom index BSAS~Z1


Create a new custom index as ZUONR, BUKRS, HKONT, BUDAT

_________________________________

_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________

28

What Well Cover

_________________________________

Understanding index design


Proactive review of poorly performing SQL
10053 CBO trace
Oracle Wait Events
10046 tracing
SAP transactions for tuning
Oracle best practices
Wrap-up

_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
29

Oracle Wait Events

_________________________________

Users who are waiting are not happy users!


Every session that waits must wait for a specific event,
and knowing where to look can answer why the
session is waiting
Areas to look for waits:

_________________________________
_________________________________
_________________________________
_________________________________
_________________________________

V$SESSION_WAIT
V$SYSTEM_EVENT
V$SESSION
V$LOCK
SAP Transaction ST04 Detailed Analysis Oracle Sessions

_________________________________
_________________________________
_________________________________
_________________________________
30

Common Oracle Wait Events

DB FILE SEQUENTIAL READ

_________________________________

Session is waiting for I/O when doing a FULL TABLESCAN or FAST FULL
INDEX scan. Multi-block operations are done.

_________________________________
_________________________________

The DBWR is writing data to the datafiles.

_________________________________

LOG FILE SYNC

_________________________________

DB FILE PARALLEL WRITE

_________________________________

Session is waiting for I/O from an explain plan using an index. A single
block I/O is done.

DB FILE SCATTERED READ

_________________________________

The session is waiting for the LGWR to write the data from the log buffer to
the online redo logs because of the commit.

_________________________________
_________________________________

LATCH FREE

The session is waiting for an Oracle Latch. Use P2 value to determine latch
name to resolve the issue in 9i. Oracle 10G will show the full latch name.

_________________________________
31

Common Oracle Wait Events (cont.)

ENQUEUE

_________________________________
_________________________________
_________________________________
_________________________________

The session is waiting for the DBWR to clean up dirty blocks in the Oracle
buffer cache

_________________________________

LIBRARY CACHE PIN or LIBRARY CACHE LOCK

_________________________________

_________________________________

The session is waiting for the DBWR to write the dirty block to disk

FREE BUFFER WAIT

The session is waiting for an Oracle Enqueue, which is most likely either a(n):
f ST Enqueue Space Transaction Enqueue for extent management
f TX Enqueue Multiple sessions modifying the exact same row
concurrently (usually a SELECT FOR UPDATE)

WRITE COMPLETE WAIT

_________________________________

_________________________________

Waiting for exclusive lock to the library cache and may indicate a Shared
Pool issue

_________________________________
32

Oracle Wait Events Example

_________________________________

In this example on Oracle 9i, there are many users


waiting for a LATCH FREE for KNB1

_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
33

Oracle Wait Events Example (cont.)

_________________________________

In this example on Oracle 10G, there are many users


waiting for a LATCH on cache buffers chains

_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
34

Oracle Wait Events Example (cont.)

_________________________________

In this example from v$session_wait, the event and the time


waiting can be seen
Shown below, a FULL TABLESCAN (db file scattered read) can be
seen. Why? FULL TABLESCANS should not be common!
Similar information in ST04 Detailed Analysis Oracle
Session

_________________________________
_________________________________
_________________________________
_________________________________

Select sid, seq#, event, p1,p2,p3, seconds_in_wait


from v$session_wait
where event not like SQL% and event not like %ipc%
and event not like %timer;

_________________________________
_________________________________
_________________________________

SID
SEQ# EVENT
P1
P2
P3 SECONDS_IN_WAIT
---------- ---------- ------------------------------ ---------- ---------- ---------- --------------624
18902 buffer busy waits
354
44041
130
0
2002
41785 db file scattered read
286
73460
8
0
157
30307 db file sequential read
53
320723
1
0
2245
1775 db file sequential read
354
44209
1
0
11
48565 log file parallel write
2
20
2
0

_________________________________
_________________________________
35

Oracle Enqueue Waits

_________________________________

Usually, there are two types of Oracle Enqueues (not the


same as SAP Enqueues)

_________________________________
_________________________________

TX Enqueue is a row level lock (i.e., DATA) and common in


parallel jobs
f NRIV Locking
f Locking on similar tables due to SELECT FOR UPDATE
Non-TX Enqueue (i.e., TM, ST, CI) is usually locking in Oracle
kernel and is not DATA related
f ST Enqueue due to Dictionary Managed Tablespaces and
extent management
f Oracle bug

_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
36

Oracle Enqueue Waits (cont.)

_________________________________

Steps to diagnose Oracle Enqueues

_________________________________

SM66 can show concurrent access to a table


(e.g., CE3LBOC below)

_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
37

Oracle Enqueue Waits (cont.)

_________________________________

Use ST04 Detailed Analysis Oracle Session

_________________________________

Shows the SQL statement causing the enqueue

_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
38

Oracle Enqueue Waits (cont.)

_________________________________

Use transaction DB01 to see the TX enqueues and the


waiter/holder
Use the Oracle SID (System ID) shown below in DB01 to
map to the session in ST04

_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
39

Oracle Enqueue Waits (cont.)

_________________________________

For Oracle 9i, run the following scripts in SQL*Plus to


determine TYPE of enqueue. The TYPE determines in what
area the problem resides.
The example below shows two sessions with TX enqueue
locking.

_________________________________
_________________________________
_________________________________
_________________________________

Prompt This will show the TYPE of enqueue


SELECT sid, chr(bitand(p1,-16777216)/16777215)||
chr(bitand(p1, 16711680)/65535) "Lock",
to_char( bitand(p1, 65535) ) "Mode"
FROM v$session_wait
WHERE event = 'enqueue;

_________________________________
_________________________________
_________________________________
_________________________________

SID Lock
Mode
----- ------ ---------------------------------------383 TX
4
385 TX
4

_________________________________
40

Oracle Enqueue Waits (cont.)

_________________________________

For 9i, use the following script to see the object and row of the
enqueue prompt. This will show the object and row of enqueue.
In this example, the Object 122961 is where the TX enqueue occurs.

_________________________________
_________________________________
_________________________________

col event format a25


select a.sid, b.event, a.row_wait_obj#, a.row_wait_file#,
a.row_wait_block#, a.row_wait_row#, b.seconds_in_wait
from v$session a, v$session_wait b
where a.sid = b.sid
and b.event = 'enqueue'
order by 2, 3, 4, 5;

_________________________________
_________________________________
_________________________________

SID EVENT
ROW_WAIT_OBJ# ROW_WAIT_FILE# ROW_WAIT_BLOCK# ROW_WAIT_ROW# SECONDS_IN_WAIT
---------- --------- ------------- -------------- --------------- ------------- --------------381 enqueue
122961
25
25020
0
46
383 enqueue
122961
25
25020
0
43
385 enqueue
122961
25
25020
0
80

_________________________________
_________________________________
_________________________________
41

Oracle Enqueue Waits (cont.)

_________________________________

Oracle 10G will show the TYPE of enqueue in the event

_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
42

General Rules for Oracle Waits

Determine the WAIT event for the sessions, then a


course of action

_________________________________
_________________________________
_________________________________

Full tablescans are not common and probably should be fixed


Large index RANGE scans may be slow due to single block
fetch from db file sequential read

_________________________________
_________________________________

Transactional enqueues (TX) cause row-level ENQUEUE


waits that are usually waiting for the commit due to high
concurrency. Try to commit more frequently.

Determine the TYPE of enqueue


f If it is TX, then it is most likely application concurrency
f If it is NOT TX, then it may be in the Oracle kernel and more
research is needed
Concurrent Select for UPDATE statements are a common
cause of TX enqueues

_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
43

What Well Cover

_________________________________

Understanding index design


Proactive review of poorly performing SQL
10053 CBO trace
Oracle Wait Events
10046 tracing
SAP transactions for tuning
Oracle best practices
Wrap-up

_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
44

Oracle Tracing Overview

_________________________________

Use Oracle tracing methods to:

_________________________________

Determine if the Database Writer (DBWR) is writing inefficiently


Determine if the Log Writer (LGWR) is slowing down on the
write times
Determine actual fetch times for Oracle blocks from the disk
to the buffer cache. Use the results to ascertain if the disk
subsystem is slow.
Correlate Oracles trace with SAPs ST05 trace to find similar
poor performance
Trace other Oracle background processes, if needed, to
determine what is causing them to hang or spin

_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
45

Event 10046 Levels

_________________________________

Oracle provides event 10046 to trace user and


background processes to determine what they are
WAITING for
Event 10046 has different tracing levels:

_________________________________
_________________________________
_________________________________
_________________________________

Level 1 (default) Standard SQL_TRACE functionality


Level 4 SQL_TRACE plus tracing BIND VARIABLES
Level 8 SQL_TRACE plus WAIT EVENTS
Level 12 SQL_TRACE plus BIND VARIABLES plus WAIT
EVENTS

_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
46

Tracing User Sessions

_________________________________

SQL> alter session set events '10046 trace name context forever,
level 12';

_________________________________

Session altered.

_________________________________

SQL> select count(*) from dirty_blocks;

_________________________________
_________________________________

COUNT(*)
---------386544

_________________________________

SQL> alter session set events '10046 trace name context off';

_________________________________

Session altered.

_________________________________
_________________________________
_________________________________
47

User Trace File

_________________________________

The user trace file is located in:


/oracle/<SID>/saptrace/usertrace

_________________________________
_________________________________

select count(*) from dirty_blocks


END OF STMT
PARSE
#1:c=0,e=1496,p=0,cr=0,cu=0,mis=1,r=0,dep=0,og=4,tim=4001773990916
BINDS #1:
EXEC #1:c=0,e=189,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=4,tim=4001773991256
WAIT #1: nam='SQL*Net message to client' ela= 2 p1=1650815232 p2=1 p3=0
WAIT #1: nam='db file scattered read' ela= 199 p1=66 p2=24963 p3=8
WAIT #1: nam='db file scattered read' ela= 86 p1=66 p2=24971 p3=8
WAIT #1: nam='db file scattered read' ela= 82 p1=66 p2=24979 p3=8
WAIT #1: nam='db file scattered read' ela= 78 p1=66 p2=24987 p3=8
WAIT #1: nam='db file scattered read' ela= 78 p1=66 p2=24995 p3=8
WAIT #1: nam='db file scattered read' ela= 78 p1=66 p2=25003 p3=8
WAIT #1: nam='db file scattered read' ela= 78 p1=66 p2=25011 p3=8

_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
48

Event 10046 Tracing Information

_________________________________

Wait information:

_________________________________

nam is what event is being waited on


ela is the elapsed time for the operation
f In Oracle 7/8, this is in units of hundredths of a second
f In Oracle 9i onwards, this is in microseconds
p1 is the additional information for that wait event (e.g., for I/O
waits the p1 value is the file number)
p2 is the additional information for that wait event (e.g., for I/O
waits the p2 value is the block number)
p3 is the additional information for that wait event (e.g., for I/O
waits the p3 value is the number of blocks read by the
operation)

_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
49

10046 Trace for an SAP User

_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
50

10046 Trace for an SAP User (cont.)

_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
51

10046 Trace for an SAP User (cont.)

_________________________________

In this example, because we are tracing a session other


than our own, we need to attach to the process and
trace it
To do this, the Oracle Process ID (PID) needs to be
determined from the Oracle Session ID (SID) that is
provided in the ST04 screen

_________________________________
_________________________________
_________________________________
_________________________________
_________________________________

select pid from v$process where addr =


(select paddr from v$session where sid =
17);

_________________________________
_________________________________
_________________________________

PID
---------22

_________________________________
52

10046 Trace for an SAP User (cont.)

_________________________________

Now that we have the Oracle PID, we can use another Oracle
tracing method, ORADEBUG, to attach and trace what is
happening with the process.

_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________

* See SAP Note 613872 for additional information on ORADEBUG

53

10046 Trace for an SAP User (cont.)

_________________________________

SQL> oradebug setorapid 22


Unix process pid: 23808, image: oracle@d1ua0002 (TNS V1-V3)
SQL> oradebug unlimit
Statement processed.
SQL> oradebug event 10046 trace name context forever, level 12
Statement processed.

_________________________________
_________________________________
_________________________________
_________________________________

Waited 30 seconds......

_________________________________
_________________________________

SQL> oradebug event 10046 trace name context off


Statement processed.

_________________________________
_________________________________
_________________________________
54

10046 Trace for an SAP User (cont.)

_________________________________

Below is the output from the 10046 trace of the SAP work process
23732, which was running a SELECT on table ECMCA.
Notice the elapse (ela) times to fetch the block from disk into the
buffer cache are very fast!

WAIT
WAIT
WAIT
WAIT
WAIT
WAIT
WAIT
WAIT
WAIT
WAIT
WAIT
WAIT

#332:
#332:
#332:
#332:
#332:
#332:
#332:
#332:
#332:
#332:
#332:
#332:

nam='db
nam='db
nam='db
nam='db
nam='db
nam='db
nam='db
nam='db
nam='db
nam='db
nam='db
nam='db

file
file
file
file
file
file
file
file
file
file
file
file

sequential
sequential
sequential
sequential
sequential
sequential
sequential
sequential
sequential
sequential
sequential
sequential

read'
read'
read'
read'
read'
read'
read'
read'
read'
read'
read'
read'

ela=
ela=
ela=
ela=
ela=
ela=
ela=
ela=
ela=
ela=
ela=
ela=

_________________________________
_________________________________
_________________________________

36 p1=39 p2=2209765 p3=1


32 p1=39 p2=2209766 p3=1
32 p1=39 p2=2209767 p3=1
31 p1=39 p2=2209768 p3=1
31 p1=39 p2=2209769 p3=1
31 p1=39 p2=2209770 p3=1
30 p1=39 p2=2209771 p3=1
9311 p1=39 p2=2209772 p3=1
34 p1=39 p2=2209773 p3=1
274 p1=39 p2=2209774 p3=1
33 p1=39 p2=2209775 p3=1
17972 p1=39 p2=2209808 p3=1

_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
55

Tracing Background Processes

_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
56

Background ORADEBUG

_________________________________

SQL> select count(*) from v$bh where dirty='Y';

_________________________________

COUNT(*)
---------11015

_________________________________
_________________________________

SQL> oradebug setospid 6072


Oracle pid: 3, Unix process pid: 6072, image: oracle@d1ua0002 (DBW0)
SQL> oradebug unlimit
Statement processed.
SQL> oradebug event 10046 trace name context forever, level 12
Statement processed.
SQL> alter system checkpoint;

_________________________________
_________________________________
_________________________________

System altered.
SQL>

_________________________________

select count(*) from v$bh where dirty='Y';

_________________________________

COUNT(*)
---------23
SQL> oradebug event 10046 trace name context off
Statement processed.

_________________________________
57

Background 10046 Trace File

_________________________________

Background trace file is located in:

_________________________________

/oracle/<SID>/saptrace/background
WAIT
WAIT
WAIT
WAIT
WAIT
WAIT
WAIT
WAIT
WAIT
WAIT
WAIT
WAIT
WAIT
WAIT
WAIT
WAIT

#0:
#0:
#0:
#0:
#0:
#0:
#0:
#0:
#0:
#0:
#0:
#0:
#0:
#0:
#0:
#0:

nam='db file parallel write'


nam='db file parallel write'
nam='db file parallel write'
nam='db file parallel write'
nam='db file parallel write'
nam='db file parallel write'
nam='db file parallel write'
nam='db file parallel write'
nam='db file parallel write'
nam='db file parallel write'
nam='rdbms ipc message' ela=
nam='rdbms ipc message' ela=
nam='rdbms ipc message' ela=
nam='rdbms ipc message' ela=
nam='rdbms ipc message' ela=
nam='rdbms ipc message' ela=

_________________________________

ela= 74067 p1=204 p2=0 p3=2147483647


ela= 69087 p1=204 p2=0 p3=2147483647
ela= 75128 p1=204 p2=0 p3=2147483647
ela= 72345 p1=204 p2=0 p3=2147483647
ela= 67329 p1=204 p2=0 p3=2147483647
ela= 75704 p1=204 p2=0 p3=2147483647
ela= 72595 p1=204 p2=0 p3=2147483647
ela= 78253 p1=204 p2=0 p3=2147483647
ela= 70311 p1=204 p2=0 p3=2147483647
ela= 61051 p1=152 p2=0 p3=2147483647
2563836 p1=256 p2=0 p3=0
3007678 p1=300 p2=0 p3=0
3007685 p1=300 p2=0 p3=0
3007723 p1=300 p2=0 p3=0
3007736 p1=300 p2=0 p3=0
3007715 p1=300 p2=0 p3=0

_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
58

What Well Cover

_________________________________

Understanding index design


Proactive review of poorly performing SQL
10053 CBO trace
Oracle Wait Events
10046 tracing
SAP transactions for tuning
Oracle best practices
Wrap-up

_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
59

SAP Transactions for Tuning: SM66

_________________________________

Use SM66 as an indicator of normal SAP workload

_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
60

SAP Transactions for Tuning: ST04

_________________________________

Use Transaction ST04 Detailed Analysis Oracle


Session as an indicator of a normal workload

_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
61

SAP Transactions for Tuning: ST05

_________________________________

Use ST05 to trace any specific transactions that may be


causing issues

_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
62

SAP Transactions for Tuning: SE30

_________________________________

Use SE30 to quickly identify if the problem is in SAP or


the database layer

_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
63

SAP Transactions for Tuning: ST12

_________________________________

Combination ST05 and SE30 (see SAP Note 755977)


Holds the history of each trace

_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
64

SAP Transactions for Tuning: ST12 (cont.)

_________________________________

Here we can see SE30 trace information from the ABAP


Trace in ST12

_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
65

SAP Transactions for Tuning: ST12 (cont.)

_________________________________

Here we can see ST05 trace information from the


ST12 trace

_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
66

SAP Programs: RSORAVDV

_________________________________

Use to see DBA and V$ view information


Run in SE38

_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
67

SAP Programs: RSORADJV

_________________________________

Use to access DBA and V$ view information


Run in SE38

_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
68

SAP Programs: RSORADJV (cont.)

_________________________________

Output from RSORADJV

_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
69

SAP Programs: RSBDCOS0

_________________________________

Output from RSBDCOS0


Can be used to execute OS-level commands from SAP

_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
70

OS Debugging Methods

truss

_________________________________
_________________________________

Print streams information


strace is available for Windows

_________________________________
_________________________________

sar

_________________________________

Trace Unix system calls


Example:
f truss p <unix pid>

strace

_________________________________

Displays system activity (CPU, disk, network)


Example:
f sar 5 10

_________________________________
_________________________________

vmstat

_________________________________

Displays virtual memory statistics


Example:
f vmstat 5 10

_________________________________
71

OS Debugging Methods (cont.)

ping

_________________________________
_________________________________

Used to send network packets to host


Examples:
f ping <hostname>
f ping t <hostname>

_________________________________
_________________________________
_________________________________

Use these OS tracing methods in conjunction with the


10046 tracing to confirm elapse times

_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
72

What Well Cover

_________________________________

Understanding index design


Proactive review of poorly performing SQL
10053 CBO trace
Oracle Wait Events
10046 tracing
SAP transactions for tuning
Oracle best practices
Wrap-up

_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
73

Oracle Best Practices: Tablespaces

_________________________________

Locally Managed Tablespaces (LMTS)

_________________________________

Benefits:
f Does not use the single ST Enqueue, which can cause
performance issues
f Reduces DBAs workload by configuring auto allocate or
uniform extent sizes
Disadvantages:
f Still uses pct_used and pct_free, which are not efficient
f Concurrent inserts are still sent to the same free block on
the freelist

_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
74

Oracle Best Practices: Tablespaces (cont.)

_________________________________

ASSM tablespaces

_________________________________

Benefits:
f Same benefits as listed on previous slide for LMTS
f No longer uses the pct_used and pct_free; instead, manages
the block filling based on the percentages
f Concurrent inserts are automatically sent to different blocks

_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
75

Oracle Best Practices

AUM

_________________________________
_________________________________

Automatically configures the number of undo segments needed


Minimize ORA-1555 by keeping the changed data in the undo
segments based on a retention time

PGA tuning

_________________________________
_________________________________
_________________________________

Allows the PGA to allocate memory up to a certain value that is


greater than the parameters sort_area_size and hash_area_size
Minimizes sorts operations (I/O) to PSAPTEMP

_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
76

Oracle Best Practices (cont.)

Auto extend

_________________________________
_________________________________

Define only one datafile for each tablespace to auto extend in


the event that the DBA cannot add space in time. This will
reduce ORA-1653 and ORA-1654 space errors.

_________________________________
_________________________________

Using parallel query

_________________________________

Use parallel query servers to create indexes faster


Use parallel query servers to create tables faster when using
create table as select commands

_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
77

Oracle Best Practices (cont.)

SPFILE

_________________________________

Using the SPFILE aids in the managing of the database and the
parameters that are changed

_________________________________
_________________________________

Analyze table/index <name> validate structure online

_________________________________

_________________________________

Can be used to look for corruption without putting a lock on the


table, which happened in previous Oracle versions

_________________________________

Online table reorganization

_________________________________

Tables that do not have LONG or LONG RAW columns can now
be reorganized online using DBMS_REDEFINITION package.
This method is based on materialized views technology.

_________________________________
_________________________________
_________________________________
78

What Well Cover

_________________________________

Understanding index design


Proactive review of poorly performing SQL
10053 CBO trace
Oracle Wait Events
10046 tracing
SAP transactions for tuning
Oracle best practices
Wrap-up

_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
79

Resources

Oracle/SAP Newsletter

_________________________________
_________________________________

www.oracle.com/newsletters/sap/current.html

_________________________________

Wait Events

_________________________________

SAP Note 619188


service.sap.com/notes *

_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________

* Requires login credentials to the SAP Service Marketplace

80

7 Key Points to Take Home

_________________________________

The most efficient I/O done, besides blocks already


residing in cache, will be 3-4 blocks per row return
Proactively monitor the system for inefficient SQL
statements using ST04 and ST05 transactions
Use the CBO 10053 tracing to understand why the
optimizer is picking the index in the execution plan
Always determine what event is causing users to wait

_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
81

7 Key Points to Take Home (cont.)

_________________________________

Use wait event tracing 10046 to prove if any background


or foreground process is slowing down due to internal
latching or because of I/O issues
Use SAP transactions ST12, SE30, ST05, SM66, and
ST04 to quickly identify the area of waits
Set up the Oracle/SAP database per SAPs Best
Practices Standards (ASSM, AUM, SPFILE, etc.)

_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
82

Your Turn! Questions?

_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________
_________________________________

How to contact me:


Mike Kennedy
michael.kennedy@smsconsultinginc.com

_________________________________
_________________________________
83

Notes:
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________

Notes:
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________

Notes:
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________

Wellesley Information Services, 990 Washington Street, Suite 308, Dedham, MA 02026

Copyright 2008 Wellesley Information Services. All rights reserved.

Вам также может понравиться