15
Sampling Kyle Hailey Embarcadero Technologies http://oraclemonitor.com

Oracle 10g Performance: chapter 00 sampling

Embed Size (px)

Citation preview

Page 1: Oracle 10g Performance: chapter 00 sampling

Sampling

Kyle Hailey

Embarcadero Technologies

http://oraclemonitor.com

Page 2: Oracle 10g Performance: chapter 00 sampling

Example on 9i

Slowdown on Database Look at Statspack:

Copyright 2006 Kyle Hailey

Top 5 Timed EventsTop 5 Timed Events

~~~~~~~~~~~~~~~~~~ % Total~~~~~~~~~~~~~~~~~~ % TotalEvent Waits Time (s) Call TimeEvent Waits Time (s) Call Time--------------------------- ----------- ------------------------------------ ----------- ---------buffer busy waits 2,748 250 78.72buffer busy waits 2,748 250 78.72CPU time 32 10.16CPU time 32 10.16free buffer waits 1,588 15 4.63free buffer waits 1,588 15 4.63write complete waits 10 8 2.51write complete waits 10 8 2.51log buffer space 306 5 1.51log buffer space 306 5 1.51--------------------------------------------------------------

Page 3: Oracle 10g Performance: chapter 00 sampling

What do we do?

How do we solve “buffer busy wait” Need:

SQL Sessions Objects Wait details

Type of buffer busy wait File and block numbers

How do we get that information?Not from StatspackBut from v$session_wait

And v$session starting in 10g

Copyright 2006 Kyle Hailey

Page 4: Oracle 10g Performance: chapter 00 sampling

V$session_wait

Shows who is waiting For example lists who is waiting on “buffer busy waits”Data only exists while waits are happeningData includes

Type of buffer busy wait File and block involved in buffer busy wait

Problem: Once waits are over, data is gone Solution: Sample data all the time

Copyright 2006 Kyle Hailey

Page 5: Oracle 10g Performance: chapter 00 sampling

Sample Query

Copyright 2006 Kyle Hailey

select nvl(s.username,s.program) username, s.sid sid, s.serial# serial, s.sql_hash_value sql_hash_value, substr(decode(w.wait_time, 0, w.event, 'ON CPU'),1,15) event , w.p1 p1, w.p2 p2, w.p3 p3from v$session s, v$session_wait wwhere w.sid=s.sidand s.status='ACTIVE'and s.type='USER';

This query works since v7This query works since v7

SQL identifierSQL identifier

Waiting or on CPU?Waiting or on CPU?

Page 6: Oracle 10g Performance: chapter 00 sampling

Sampling Output

Copyright 2006 Kyle Hailey

USERNAME SID SERIAL SQL_HASH_V EVENT P1 P2 P3USERNAME SID SERIAL SQL_HASH_V EVENT P1 P2 P3---------- ----- -------- ---------- -------------------- -------- -------- -------------- ----- -------- ---------- -------------------- -------- -------- ----SYS 64 8717 4116021597 PL/SQL lock timer 300 0 0SYS 64 8717 4116021597 PL/SQL lock timer 300 0 0SYS 58 19467 961168820 ON CPU 16508152 1 0SYS 58 19467 961168820 ON CPU 16508152 1 0STARGUS 71 6251 1311875676 direct path write 201 2155902 127STARGUS 71 6251 1311875676 direct path write 201 2155902 127(CJQ0) 9 1 0 rdbms ipc message 500 0 0(CJQ0) 9 1 0 rdbms ipc message 500 0 0

Run sample query every second and

save into a table “v$ash”

Page 7: Oracle 10g Performance: chapter 00 sampling

Buffer busy wait type

Copyright 2006 Kyle Hailey

SQL> Select count(*), p3from v$ashwhere event = 'buffer busy waits'group by p3;

COUNT(*) P3---------- ----3423 220

On 9i

P3 < 200 read problem

P3 >= 200 write problem

On 10g P3 is the block class which is better for diagnostics

Page 8: Oracle 10g Performance: chapter 00 sampling

File and Block #s

Copyright 2006 Kyle Hailey

select count(*), p1 filen, p2 blockn from v$ashwhere event='buffer busy waits'group by p1, p2, hash_value;

COUNT(*) FILEN BLOCKN---------- -------- -------- 1 11 90644 2 11 90651 3 11 98233 1 11 104767 3 11 113291 1 11 119842 1 11 119856 3 11 121632 1 11 126334

Pick a File and Block to find object

Page 9: Oracle 10g Performance: chapter 00 sampling

Sampling Output

Copyright 2006 Kyle Hailey

column segment_name format a30column segment_name format a30

select select owner,owner, segment_name, segment_name, segment_type, segment_type, block_id, blocks+block_id block_id, blocks+block_idfrom dba_extentsfrom dba_extentswhere file_id = 11where file_id = 11and 126334 between block_id AND block_id + blocks-1;and 126334 between block_id AND block_id + blocks-1;

OWNER SEGMENT_NAME SEGMENT_TY BLOCK_ID BLOCKS+BLOCK_IDOWNER SEGMENT_NAME SEGMENT_TY BLOCK_ID BLOCKS+BLOCK_ID---------- ------------------ ---------- ---------- ------------------------- ------------------ ---------- ---------- ---------------SYSTEM TOTO1 TABLE 125201 127249SYSTEM TOTO1 TABLE 125201 127249

Data block ( not header block )

COUNT(*) FILEN BLOCKN---------- -------- -------- 1 11 126334

Page 10: Oracle 10g Performance: chapter 00 sampling

What SQL ?

Copyright 2006 Kyle Hailey

SQL> select count(*), p1 filen, p2 blockn , sql_hash_valueSQL> select count(*), p1 filen, p2 blockn , sql_hash_value2 from v$ash2 from v$ash3 where event='buffer busy waits'3 where event='buffer busy waits'4 group by p1, p2, hash_value;4 group by p1, p2, hash_value;

COUNT(*) FILEN BLOCKN SQL_HASH_VALUECOUNT(*) FILEN BLOCKN SQL_HASH_VALUE---------- -------- -------- -------------------- -------- -------- ---------- 3 1 94609 5586668633 1 94609 558666863 2 11 81163 5586668632 11 81163 558666863 2 11 87123 5586668632 11 87123 558666863 1 11 90644 5586668631 11 90644 558666863 2 11 90651 5586668632 11 90651 558666863 3 11 98233 5586668633 11 98233 558666863 1 11 104767 5586668631 11 104767 558666863 3 11 113291 5586668633 11 113291 558666863 1 11 119842 5586668631 11 119842 558666863 1 11 119856 5586668631 11 119856 558666863 3 11 121632 5586668633 11 121632 558666863 1 11 126334 5586668631 11 126334 558666863

All the same SQL , SQL_HASH_VALUE=All the same SQL , SQL_HASH_VALUE= 558666863 558666863

Page 11: Oracle 10g Performance: chapter 00 sampling

SQL Statement ?

Copyright 2006 Kyle Hailey

select sql_textfrom v$sqltextwhere hash_value=558666863;

SQL_TEXT-----------------------------------------------------INSERT into toto1 values (:b1,lpad('a',1000,'a'))

Insert statement getting write type buffer busy waits: problem with users inserting data into same block. Solution : configure inserts to uses different blocks with Freelists or ASSM

Page 12: Oracle 10g Performance: chapter 00 sampling

ASSM ?

Copyright 2006 Kyle Hailey

select FREELISTS, TABLESPACE_NAMEselect FREELISTS, TABLESPACE_NAMEfrom dba_tablesfrom dba_tableswhere table_name='TOTO1' and owner='SCOTT';where table_name='TOTO1' and owner='SCOTT';

FREELISTS TABLESPACE_NAMEFREELISTS TABLESPACE_NAME---------- ---------------------------------------- ------------------------------1 USERS1 USERS

Table only has 1 freelist

The table is in tablespace Users

Is it an ASSM tablespace ?

Page 13: Oracle 10g Performance: chapter 00 sampling

Sampling Output

Copyright 2006 Kyle Hailey

select tablespace_name, SEGMENT_SPACE_MANAGEMENTfrom dba_tablespaces;

TABLESPACE_NAME SEGMEN------------------------------ ------SYSTEM MANUALUNDOTBS1 MANUALTEMP MANUALUSERS MANUALTOOLS AUTO

USERS tablespace is not in ASSM mode

Page 14: Oracle 10g Performance: chapter 00 sampling

Let’s add Freelists

Copyright 2006 Kyle Hailey

select count(*), sid, serial select count(*), sid, serial from v$ash from v$ash where event='buffer busy waits‘where event='buffer busy waits‘group by sid, serial;group by sid, serial;

COUNT(*) SID SERIAL COUNT(*) SID SERIAL---------- ----- ------------------ ----- -------- 7 12 79 7 12 79 4 14 99 4 14 99 4 19 770 4 19 770 8 20 176 8 20 176

Max Concurrency is 4

Freelists >= 4

How many freelists?

Page 15: Oracle 10g Performance: chapter 00 sampling

DB Optimizer shows it all

Copyright 2006 Kyle Hailey