SlideShare una empresa de Scribd logo
1 de 102
Oaktable
   Jonathan Lewis and ORACLE_TRACE
   Oracle_Trace crashes my Database
   I start the SGA attach by searching every offset
   Anjo Kolk says James Morle wrote a program using
    x$ksmmem
   I show James my first draft using x$ksmmem
   James is baffled by why I'm hard coding offsets
   James says the offsets are in some X$ table
   I search, turn up a mail by Jonathan Lewis on x$kqfco
   Goldmine – all the offsets
   Thanks Mogens Nogard!
   Thanks to TomKyte's Decimal to Hex
http://oraperf.sourceforge.net
Direct Oracle SGA Memory
         Access

   Reading data directly from
Oracle’s shared memory segment
          using C code

  Wednesday, February 20, 2013
SGA on UNIX

        SMON             S nnn
                                          D nnn              P nnn


 PMON
                               SGA                                   CKPT
                                                  Redo Log
         Shared Pool    Database Buffer Cache      Buffer

 DBWR
                                                                     ARCH

 LGWR


               oracle                   sqlplus        Machine
                                                       Memory
SGA on NT

          S nnn       D nnn     P nnn    CKPT
 SMON                                                      Machine
        Shared Pool     Database Buffer Cache
                                                Redo Log
                                                 Buffer    Memory
 PMON


   DBWR
                      LGWR       ARCH           oracle




            Process Space                                    sqlplus
What is the SGA
 Memory Cache
 Often Used Data
 Rapid Access
 Shareable
 Concurrently Access
SGA 4 main regions
 Fixed information
   –   Users info
   –   Database statistics
   –   X$dual
   –   etc
 Data block cache
 SQL cache ( library cache/shared pool)
 Redo log buffer
How is the SGA info Used?
 Automatically
   –   data blocks cached
   –   Log buffer
   –   Sql cache
   –   Updates of system and user statistics

 User Queries
   –   User info v$session
   –   System info v$parameter
   –   Performance statistics v$sysstat, v$latch, v$system_event
   –   Buffer cache headers, x$bh
Why Direct Access with C?
 Reading Hidden Information
   –   Sort info on version 7
   –   OPS locking info version 8
   –   Contents of data blocks (only the headers or visible in X$)

 Access while Database is Hung
 High Speed Access
   –   Sampling User Waits, catch ephemeral data
   –   Scan LRU chain in X$bh
   –   Statistically approximate statistics
         SQL statistics per user

 Low overhead
Database Slow or Hung
Often happens at the largest sites when cutting
  edge support is expected.

   Shared Pool errors ORA 4031
   Archiver or Log file Switch Hangs
   Hang Bugs
   Library Cache Latch contention
   ORA-00379: no free buffers available in buffer
    pool DEFAULT
Statistical Sampling


  By Rapidly Sampling SQL statistics
  and the users who have the statistics
  open, one can see how much work a
  particular user does with a particular
  SQL statement
Low Overhead
 Marketing Appeal
 Clients are sensitive about their production
  databases
 Heisenberg uncertainty affect – less overhead
  less affect monitoring has on performance
  which we are monitoring
SGA made visible through x$tables

   Most of the SGA is not visible
   X$KSMMEM Exception, Raw Dump of SGA
   Information Externalized through X$ tables
   Useful or Necessary information is Externalized
   Externalized publicly through V$ Tables
Machine Memory


  0x80000000




         SGA     SGA
Buffer Cache
 Graphic SGA
SGA
0x80000000

             Fixed Area
              Buffer Cache



               Shared Pool


               Log Buffer
Fixed Area
    SGA          X$KSUSECST- user waits
    0x80000000




0x85251EF4
X$KSUSECST
   170 Records
                 2328 bytes


0x85251EF4          Row 1               Row 2
                              Row 3 …
X$KSUSECST Record

One Record in X$KSUSECST



                 1276



                 2328 bytes
X$KSUSECST Fields


1276     1278       1280   1284   1288

 Seq #    Event #    p1      p2    p3
Externalization of C structs: X$
tables

If Structure foo was externalized in a X$
SQL> describe x$foo
Column Name                       Type
------------------------------   --------
ADDR                             RAW(8)
INDX                             NUMBER
ID                               NUMBER
B                                NUMBER
SGA is One Large C Struct

   struct foo
   {
      int id;
      int A;
      int B;
      int C;
   };
   struct foo foo[N];
Struct C code
#include <stdio.h>
#include <fcntl.h>
#define N 20
/* structure definition: */

struct foo
{
     int id;
     int a;
     int b;
     int c;
};
/* end structure definition */
Struct Record
main(){
struct foo foo[20];
int fptr;
   /* zero out memory of struct */
   memset(foo,0,sizeof(foo));

    foo[0].id=1;                     /* row 0 */
    foo[0].a=12;
    foo[0].b=13;
    foo[0].c=13;
Struct Write to File
       foo[1].id=2;       /* row 1 */
       foo[1].a=22;
       foo[1].b=23;
       foo[1].c=24;
/* write to file, simulate SGA */
  if ((fptr = open("foo.out",O_WRONLY | O_CREAT,0777)) < 0 )
   return -1;

    write(fptr,foo,sizeof(foo));
    return 0;
}
Simulate SGA with a File



  write(fp,foo,sizeof(foo));
Simulate SGA with a File

         Row 0                     Row 1

    ID       A   B    C    ID          A     …
0        1     3      4   6       8    bits
0        4
         6     8
               2      1
                      8   1
                          4       2
                                  0    bytes
0        4     8      C
                      2   1
                          6       1
                                  0    hex bytes
0        4     1      1   2
                          0       2
                                  4         oct
               0
     Memory address   4   0       4
                          Increasing       bytes
Struct File Contents

$ ./foo
$ ls -l foo.out
-rw-r--r-- joe dba 320 Feb 10 19:41 foo.out

int = 32 bits
Int = 4 bytes
20 entries * 4 int * 4 bytes/int = 320 bytes
od – octal dump
$ od -l foo.out
0000000         1   12   13   13
0000020         2   22   23   24
0000040         0    0    0    0
*
0000500
Struct File Contents




 Address is in Hex
 Column 2 is the ID
 Column 3 is field A
 Column 4 is field B
 Column 5 is field C
X$ tables ?
 Ok, x$foo =~ foo[20]
 How do I get a list of x$ tables?
 Where is each X$ located?
 V$Fixed_Tables
V$Fixed_Table – list of X$ tables


SQL> desc v$fixed_table;
Name                                    Null? Type
----------------------------------------- -------- -----------------
NAME                                            VARCHAR2(30)
OBJECT_ID                                           NUMBER
TYPE                                           VARCHAR2(5)
TABLE_NUM                                            NUMBER
Graphic: X$ Addresses
    SGA
     0x80000000




0x8????????
  X$????
V$Fixed_Table
spool addr.sql
select
   'select 'addr, ||''''||name||''''||' from ' || name ||' where
   rownum < 2;'
from
      v$fixed_table
where
     name like 'X%'
/
spool off
@addr.sql
Example: finding the address
select
      a.addr ,
      'X$KSUSE'
from
      X$KSUSE
where
      rownum < 2 ;
X$ layout
6802B244 X$KSLEMAP
6802B7EC X$KSLEI
6820B758 X$KSURU
6820B758 X$KSUSE    - v$session
6820B758 X$KSUSECST – v$session_wait
6820B758 X$KSUSESTA – v$session_stat
6820B758 X$KSUSIO
6826FBD0 X$KSMDD
6831EA0C X$KSRCHDL
What's in these X$ views
 V$ views are documented
 V$ views are based often on X$ tables
 The map from v$ to X$ is described in :


          V$Fixed_View_Definition
V$Fixed_View_Definition
SQL> desc V$Fixed_View_Definition
Name                                    Type
----------------------------------- --------------
VIEW_NAME                             VARCHAR2(30)
VIEW_DEFINITION                       VARCHAR2(4000)
Definition of V$Session_Wait
SQL> select
            VIEW_DEFINITION
        from
            V$FIXED_VIEW_DEFINITION
        where
            view_name='GV$SESSION_WAIT';
VIEW_DEFINITION
-----------------------------------------------------------------------
select s.inst_id,s.indx,s.ksussseq,e.kslednam, e.ksledp1,s.ksussp1,s.ksussp1r,e.
ksledp2, s.ksussp2,s.ksussp2r,e.ksledp3,s.ksussp3,s.ksussp3r, decode(s.ksusstim,
0,0,-1,-1,-2,-2, decode(round(s.ksusstim/10000),0,-1,round(s.ksusstim/10000)))
, s.ksusewtm, decode(s.ksusstim, 0, 'WAITING', -2, 'WAITED UNKNOWN TIME', -1, '
WAITED SHORT TIME', 'WAITED KNOWN TIME') from x$ksusecst s, x$ksled e where bit
and(s.ksspaflg,1)!=0 and bitand(s.ksuseflg,1)!=0 and s.ksussseq!=0 and s.ksussop
c=e.indx
The Fields in X$ tables
 OK, I've picked an X$
 I've got the starting address
 Now, how do I get the fields?
X$KQFTA
 Kernel Query Fixed_view Table
 INDX          use to find column information
 KQFTANAM X$ table names
X$KQFCO
   Kernel Query Fixed_view Column
   KQFCOTAB Join with X$KQFTA.INDX
   KQFCONAM Column name
   KQFCOOFF Offset from beginning of the row
   KQFCOSIZ      Columns size in bytes
X$KSUSECST Fields


1276     1278       1280   1284   1288   Address

 Seq #    Event #    p1      p2    p3



2         2          4      4      4     BYTES
SGA Contents in Resume
  In resume:
  Oracle takes the C structure defining the
  SGA and maps it onto a shared memory
  segment
               Memory address   Increasing
0x800000
    0
Fixed SGA      Buffer       Redo        Library
               Cache       Buffer       Cache
 Oracle provides access to some of the SGA
 contents via X$ tables
**** Procedure *****

1.   Choose a V$ view
2.   Find base X$ Tables for v$ view
3.   Map X$ fields to V$ fields
4.   Get address of X$ table in SGA
5.   Get the size of each record in X$ table
6.   Get the number of records in X$ table
7.   Get offsets for each desired field in X$ table
8.   Get the base address of SGA
1) V$SESSION_WAIT Example
 List of all users waiting
 Detailed information on the waits
 Data is ephemeral
 Useful in Bottleneck diagnostics
 High sampling rate candidate
 Event 10046 captures this info


  Good table for SGA sampling
V$SESSION_WAIT Description
 SQL> desc v$session_wait
 Name                                        Type
 -----------------------------------------   --------------------------
 SID                                         ,NUMBER
 SEQ#                                         ,NUMBER
 EVENT                                       ,VARCHAR2(64)
 P1TEXT                                      ,VARCHAR2(64)
 P1                                          ,NUMBER
 P1RAW                                       ,RAW(4)
 P2TEXT                                      ,VARCHAR2(64)
 P2                                          ,NUMBER
 P2RAW                                       ,RAW(4)
 P3TEXT                                      ,VARCHAR2(64)
 P3                                          ,NUMBER
 P3RAW                                       ,RAW(4)
 WAIT_TIME                                   ,NUMBER
 SECONDS_IN_WAIT                             ,NUMBER
 STATE                                       ,VARCHAR2(19)
 )
V$SESSION_WAIT Short

SQL> desc v$session_wait
Name                         Type
---------------------------- -------------
SID                          NUMBER
SEQ#                         NUMBER
EVENT                        VARCHAR2(64)
P1                                    NUMBER
P2                                    NUMBER
P3                                    NUMBER)
V$FIXED_VIEW_DEFINITION

Gives mappings of V$ views to X$ tables

SQL> select
          VIEW_DEFINITION
    from
          V$FIXED_VIEW_DEFINITION
    where
          view_name='V$SESSION_WAIT‘;
V$SESSION_WAIT View Definition
VIEW_DEFINITION
---------------------------------------------------------------------
select
s.inst_id,
         s.indx,
         s.ksussseq,
         e.kslednam,
e.ksledp1,
s.ksussp1,
s.ksussp1r,
e.ksledp2,
s.ksussp2,
s.ksussp2r,
e.ksledp3,
s.ksussp3,
s.ksussp3r,
round(s.ksusstim / 10000),
s.ksusewtm,
decode(s.ksusstim, 0, 'WAITING', -2, 'WAITED UNKNOWN TIME',
                                                       -1, 'WAITED SHORT TIME', 'WAITED KNOWN TIME')
from
x$ksusecst s,
x$ksled e
where
bitand(s.ksspaflg,1)!=0 and
bitand(s.ksuseflg,1)!=0 and
s.ksussseq!=0 and
s.ksussopc=e.indx
View Definition Short
VIEW_DEFINITION
---------------------------------------------------------------------
select
         s.indx,
         s.ksussseq,
         e.kslednam,
         s.ksussp1,
         s.ksussp2,
         s.ksussp3
from
         x$ksusecst s,
         x$ksled e
where
         s.ksussopc=e.indx
2) V$SESSION_WAIT Based on
X$KSUSECT
 VIEW_DEFINITION
 ---------------------------------------------------
 -
 select
          indx,
          ksussseq,
          ksussopc,
          ksussp1,
          ksussp2,
          ksussp3
 from
          x$ksusecst
Equivalent SQL Statements
select                       select
         indx,                        sid
         ksussseq,                    seq#
         ksussopc,                    event
         ksussp1,                     p1
         ksussp2,                     p2
         ksussp3                      p3
from                        from
         x$ksusecst                   v$session_wait )
  Note: x$ksusecst. Ksussopc is the event #
  x$ksled.kslednam is a list of the event names where
  x$ksled.indx = x$ksusecst. ksussopc
3) V$ to X$ Field Mapping
4) Get base SGA address for X$ table


  Find the location of X$KSUSECST in the SGA


  SQL> select addr from x$ksusecst where rownum < 2
  ADDR
  --------
  85251EF4
5) Find the Size of Each Record
SQL> select
     ((to_dec(e.addr)-to_dec(s.addr))) row_size
from
     (select addr from x$ksusecst where rownum < 2) s,
     (select max(addr) addr from x$ksusecst where rownum < 3) e ;


ROW_SIZE
----------------
         2328
6) Find the Number of Records in the
 structure
SQL> select count(*) from x$ksusecst ;
COUNT(*)
--------------
         170
Get Offsets for Each Desired Field in X$ table
  SQL> select c.kqfconam field_name,
      c.kqfcooff offset,
      c.kqfcosiz sz
  from
      x$kqfco c,
      x$kqfta t
  where
      t.indx = c.kqfcotab and
      t.kqftanam='X$KSUSECST'
  order by
      offset
  ;
X$KQFTA - X$ Tables Names
List of X$ tables

 INDX     use to find column information
 KQFTANAM X$ table names


To get Column information join with X$KQFCO

   X$KQFTA.INDX = X$KQFCO.KQFCOTAB
X$KQFCO – X$ Table Columns
    List of all the columns in X$ Tables

   KQFCOTAB       Join with X$KQFTA.INDX
   KQFCONAM       Column name
   KQFCOOFF       Offset from beginning of the row
   KQFCOSIZ       Columns size in bytes
Field Offsets
FIELD_NAME                       OFFSET       SZ
------------------------------   ----------   ----------
ADDR                             0            4
INDX                             0            4
KSUSEWTM                         0            4
INST_ID                          0            4
KSSPAFLG                         1            1
KSUSSSEQ                         1276         2
KSUSSOPC                         1278         2
KSUSSP1                          1280         4
KSUSSP1R                         1280         4
KSUSSP2                          1284         4
KSUSSP2R                         1284         4
KSUSSP3                          1288         4
KSUSSP3R                         1288         4
KSUSSTIM                         1292         4
KSUSENUM                         1300         2
KSUSEFLG                         1308         4
What are all the fields at OFFSET 0?
These are all calculated values and not stored
  explicitly in the SGA.

  ADDR           memory address
  INDX           record number, like rownum
  INST_ID        database instance ID
  KSUSEWTM       calculated field
Unexposed Fields
What happens between OFFSET 1 and 1276?

• Unexposed Fields
• Sometimes exposed elsewhere, in our case
   •   V$SESSION
   •   V$SESSTAT
Fields at Same Address
Why do some fields start at the same address?
  KSUSSP1
  KSUSSP1R
Are at the same address
Equivalent of
  V$SESSION_WAIT.P1
  V$SESSION_WAIT.P1RAW
These are the same data, just exposed as
  Hex
  Decimal
7) Offsets of Fields
8) Get Base SGA Address


SQL> select addr from x$ksmmem where
 rownum < 2

      ADDR
--------------
 80000000
Results X$KSUSECST
Machine Memory


  0x80000000




         SGA     SGA
Fixed Area
    SGA          X$KSUSECST- user waits
    0x80000000




0x85251EF4
X$KSUSECST
   170 Records
                 2328 bytes


0x85251EF4          Row 1               Row 2
                              Row 3 …
X$KSUSECST Record

One Record in X$KSUSECST



                 1276



                 2328 bytes
X$KSUSECST Fields


1276     1278       1280   1284   1288

 Seq #    Event #    p1      p2    p3
Attaching to the SGA

 UNIX System Call “shmat”


To attach to shared memory Unix as a system
  call

 void *shmat(   int shmid,
                const void *shmaddr,
                int shmflg             );
ID and Address arguments to “shmat”
    The arguments are:

      shmid – shared memory identifier specified
      shmaddr – starting address of the shared memory
      shmflg - flags

The argument shmflg can be set to SHM_RDONLY . To
  avoid any possible data corruption the SGA should only
  be attached read only.
The arguments shmid and shmaddr need to be set to
  Oracle’s SGA id and address.
Finding Oracle SGA’s ID and
Address
Use ORADEBUG to find the SGA id

SQL> oradebug setmypid
Statement processed.
SQL> oradebug ipc

Information written to trace file.

 
Finding Trace File


SQL> show parameters user_dump
NAME                    VALUE
----------------------- --------------------------------
user_dump_dest /u02/app/oracle/admin/V901/udump
SQL> exit
$ cd /u02/app/oracle/admin/V901/udump
$ ls -ltr | tail -1
-rw-r----- usupport dba Aug 24 18:01 v901_ora_23179.trc
Finding SHMID in Trace File
$ vi v901_ora_23179.trc
…
 Total size 004456c Minimum Subarea size 00000000
  Area Subarea Shmid       Stable Addr    Actual Addr
    0     0         34401 0080000000 0080000000
…
Attaching to the SGA

Shmid        34401
Shmaddr      0x80000000
Shmflg       SHM_RDONLY

The SGA attach call in C would be:

Shmat(34401, 0x80000000, SHM_RDONLY);

This call needs to be executed as a UNIX user who has
  read permission to the Oracle SGA
C Code Headers
 #include <stdio.h>
 #include <sys/ipc.h>
 #include <sys/shm.h>
 #include <errno.h>
 #include "event.h"

event.h is for translating the event #s into event
  names
Events.h


Spool events.h
select 'char event[][100]={' from dual;
select '"'||name||'",' from v$event_name;
select ' "" };' from dual;
spool off
Define Base Addresses and Sizes
/* SGA BASE ADDRESS */
#define SGA_BASE            0x80000000

/* START ADDR of KSUSECST(V$SESSION_WAIT) */
#define KSUSECST_ADDR     0x85251EF4

/* NUMBER of ROWS/RECORDS in KSUSECST */
#define SESSIONS        150

/* SIZE in BYTES of a ROW in KSUSECST */
#define RECORD_SZ             2328
Define Offsets to Fields


 #define KSUSSSEQ 1276      /* sequence # */
 #define KSUSSOPC 1278      /* event # */
 #define KSUSSP1R 1280     /* p1 */
 #define KSUSSP2R 1284     /* p2 */
 #define KSUSSP3R 1288     /* p3 */
Set Up Variables
 main(argc, argv)
 int argc;
 char **argv;
 {
  void *addr;
  int shmid;
  int shmaddr;
  void *current_addr;
  long p1r, p2r, p3r;
  unsigned int i, seq, tim, flg, evn;
Attach to SGA
/* ATTACH TO SGA */
   shmid=atoi(argv[1]);
   shmaddr=SGA_BASE;
   if (
         (void *)shmat(
                        shmid,
                        (void *)shmaddr,
                        SHM_RDONLY)
                  == (void *)-1 ) {
        printf("shmat: error attatching to SGAn");
        exit();
   }
Set Up Sampling Loop

 /* LOOP OVER ALL SESSIONS until CANCEL */
    while (1) {
     /* set current address to beginning of Table */
      current_addr=(void *)KSUSECST_ADDR;
      sleep(1);
      printf("^[[H ^[[J"); /* clear screen */
     /* print page heading */
      printf("%4s %8s %-20.20s %10s %10s %10s n",
           "sid", "seq", "wait","p1","p2","p3");
Loop over all Sessions
for ( i=0; i < SESSIONS ; i++ ) {
         seq=*(unsigned short *)((int)current_addr+KSUSSSEQ);
         evn=*(short *)          ((int)current_addr+KSUSSOPC);
         p1r=*(long *)         ((int)current_addr+KSUSSP1R);
         p2r=*(long *)         ((int)current_addr+KSUSSP2R);
         p3r=*(long *)         ((int)current_addr+KSUSSP3R);
         if ( evn != 0 ) {
              printf("%4d %8u %-20.20s %10X %10X %10X n",
                i, seq, event[evn] ,p1r, p2r,p3r
              );
          }
          current_addr=(void *)((int)current_addr+RECORD_SZ);
       }
   }
 }
Output
$ sga_read_session_wait 34401
sid   seq     wait                 p1            p2
    p3
  0    40582 pmon timer            12C       0   0
  1    40452 rdbms ipc message     12C       0   0
  2    43248 rdbms ipc message     12C       0   0
  3    24706 rdbms ipc message     12C       0   0
  4    736    smon timer           12C       0   0
  5    88     rdbms ipc message    2BF20     0   0
  8    178    SQL*Net message from 6265710   1   0
Pitfalls
   Byte Swapping
   32 bit vs 64 bit
   Multiple Shared Memory Segments
   Segmented Memory
   Addresses are "unsigned int"
   Misaligned Access
Little Endian vs Big Endian
 Is low byte values first or high byte values first ?
 a byte is 8 bits
     –   00000000-11111111 bits,0 – 31 dec, 0x0 - 0xFF hex
 Big Endian is "normal" , highest bit first
 In ascii, the word "byte" is stored as
     –   b = 62, y = 79, t = 74, e = 65
 echo 'byte' | od -x
     –   b y t e
     –   62 79 74 65
 Little Endian, ie byte swapped (Linux, OSF, Sequent, ? )
     –    y b e t
     –   79 62 65 74
Byte Swap Example
Short = 2 bytes ie 16 bits
Goal, get the flag in the "second" byte

#ifdef __linux
       uflg=*(short *)((int)sga_address)>>8;
#else
       uflg=*(short *)((int)sga_address);
#endif
Byte Swap
Big Endian:
00 00 00 00 00 00 00 01
Little Endian
00 00 00 01 00 00 00 00
Solution, push the value over 8 places, to the
   right,
ie >>8
64 bit vs 32 bit
 SQL> desc x$ksmmem
 Name                                        Type
 -------------------------------------   ---------
 ADDR                                        RAW(4)
 INDX                                       NUMBER
 INST_ID                                     NUMBER
 KSMMMVAL                                   RAW(4)
-> 32 bit
Raw(8) -> 64 bit
Segmented Memory
x$ksuse – can be dis-contiguous

Work around:
select 'int users[]={' from dual;
select '0x'||addr||',' from x$ksuse;
select '0x0};' from dual;
Misaligned Access
 Some platforms seg fault when addressing
  misaligned bytes, need to read in even bytes or
  units of 4 bytes depending on platform




             1   2   3   4   5   6   7   8
x$ksusecst Record: What's Missing?

One Record in X$KSUSECST

    ???                 ???
                 1276



                 2328 bytes
Select Addr from X$? where Rownum<
2;
6802B244 X$KSLEMAP
6802B7EC X$KSLEI
6820B758 X$KSURU
6820B758 X$KSUSE – v$session
6820B758 X$KSUSECST – v$session_wait
6820B758 X$KSUSESTA – v$sesstat
6820B758 X$KSUSIO
6826FBD0 X$KSMDD
6831EA0C X$KSRCHDL
x$ksuse Record Contains
x$ksusecst

One Record in X$Ksusecst

   v$session    v$sesstat   v$session_wait v$session
               236          1276


                      2328 bytes



               x$ksusesta    x$ksusecst


                      x$ksuse
Getting v$sesstat addresses
select '#define '||
    upper(translate(s.name,' :-()/*''','________'))||' '||
    to_char(c.kqfcooff + STATISTIC# * 4 )
from
    x$kqfco c,
    x$kqfta t,
    v$statname s
where
    t.indx = c.kqfcotab
  and ( t.kqftanam='X$KSUSESTA' ) and c.kqfconam='KSUSESTV'
  and kqfcooff > 0
order by
   c.kqfcooff
/
User Drilldown Query: 4 joins
select
          w.sid sid,
          w.seq# seq,
          w.event event,
          w.p1raw p1,
          w.p2raw p2,
          w.p3raw p3,
          w.SECONDS_IN_WAIT ctime,
          s.sql_hash_value sqlhash,
          s.prev_hash_value psqlhash,
          st.value cpu
   from
         v$session s,
         v$sesstat st,
         v$statname sn,
         v$session_wait w
   where
         w.sid = s.sid and
         st.sid = s.sid and
         st.statistic# = sn.statistic# and
          sn.name = 'CPU used when call started' and
          w.event != 'SQL*Net message from client'
   order by w.sid;
Other Fun Stuff
The next example is output from an SGA
  program that follows the LRU of the Buffer
  Cache

The program demonstrates the
•    insertion point of LRU
•    cold end of LRU
•    hot end of the LRU
•    Full Table Scan Insertion Point
LRU HOT
LRU COLD

Más contenido relacionado

La actualidad más candente

Oracle Latch and Mutex Contention Troubleshooting
Oracle Latch and Mutex Contention TroubleshootingOracle Latch and Mutex Contention Troubleshooting
Oracle Latch and Mutex Contention TroubleshootingTanel Poder
 
Oracle Database Performance Tuning Concept
Oracle Database Performance Tuning ConceptOracle Database Performance Tuning Concept
Oracle Database Performance Tuning ConceptChien Chung Shen
 
Performance Tuning With Oracle ASH and AWR. Part 1 How And What
Performance Tuning With Oracle ASH and AWR. Part 1 How And WhatPerformance Tuning With Oracle ASH and AWR. Part 1 How And What
Performance Tuning With Oracle ASH and AWR. Part 1 How And Whatudaymoogala
 
A deep dive about VIP,HAIP, and SCAN
A deep dive about VIP,HAIP, and SCAN A deep dive about VIP,HAIP, and SCAN
A deep dive about VIP,HAIP, and SCAN Riyaj Shamsudeen
 
Oracle Database SQL Tuning Concept
Oracle Database SQL Tuning ConceptOracle Database SQL Tuning Concept
Oracle Database SQL Tuning ConceptChien Chung Shen
 
Understanding Oracle RAC 12c Internals OOW13 [CON8806]
Understanding Oracle RAC 12c Internals OOW13 [CON8806]Understanding Oracle RAC 12c Internals OOW13 [CON8806]
Understanding Oracle RAC 12c Internals OOW13 [CON8806]Markus Michalewicz
 
Chasing the optimizer
Chasing the optimizerChasing the optimizer
Chasing the optimizerMauro Pagano
 
Understanding oracle rac internals part 2 - slides
Understanding oracle rac internals   part 2 - slidesUnderstanding oracle rac internals   part 2 - slides
Understanding oracle rac internals part 2 - slidesMohamed Farouk
 
SQL Plan Directives explained
SQL Plan Directives explainedSQL Plan Directives explained
SQL Plan Directives explainedMauro Pagano
 
Oracle RAC 12c Practical Performance Management and Tuning OOW13 [CON8825]
Oracle RAC 12c Practical Performance Management and Tuning OOW13 [CON8825]Oracle RAC 12c Practical Performance Management and Tuning OOW13 [CON8825]
Oracle RAC 12c Practical Performance Management and Tuning OOW13 [CON8825]Markus Michalewicz
 
pstack, truss etc to understand deeper issues in Oracle database
pstack, truss etc to understand deeper issues in Oracle databasepstack, truss etc to understand deeper issues in Oracle database
pstack, truss etc to understand deeper issues in Oracle databaseRiyaj Shamsudeen
 
Understanding oracle rac internals part 1 - slides
Understanding oracle rac internals   part 1 - slidesUnderstanding oracle rac internals   part 1 - slides
Understanding oracle rac internals part 1 - slidesMohamed Farouk
 
UKOUG, Oracle Transaction Locks
UKOUG, Oracle Transaction LocksUKOUG, Oracle Transaction Locks
UKOUG, Oracle Transaction LocksKyle Hailey
 
Christo kutrovsky oracle, memory & linux
Christo kutrovsky   oracle, memory & linuxChristo kutrovsky   oracle, memory & linux
Christo kutrovsky oracle, memory & linuxKyle Hailey
 
My First 100 days with an Exadata (PPT)
My First 100 days with an Exadata (PPT)My First 100 days with an Exadata (PPT)
My First 100 days with an Exadata (PPT)Gustavo Rene Antunez
 
Undo internalspresentation
Undo internalspresentationUndo internalspresentation
Undo internalspresentationoracle documents
 
Oracle RAC Internals - The Cache Fusion Edition
Oracle RAC Internals - The Cache Fusion EditionOracle RAC Internals - The Cache Fusion Edition
Oracle RAC Internals - The Cache Fusion EditionMarkus Michalewicz
 
Deep review of LMS process
Deep review of LMS processDeep review of LMS process
Deep review of LMS processRiyaj Shamsudeen
 

La actualidad más candente (20)

Oracle Latch and Mutex Contention Troubleshooting
Oracle Latch and Mutex Contention TroubleshootingOracle Latch and Mutex Contention Troubleshooting
Oracle Latch and Mutex Contention Troubleshooting
 
Oracle Database Performance Tuning Concept
Oracle Database Performance Tuning ConceptOracle Database Performance Tuning Concept
Oracle Database Performance Tuning Concept
 
Performance Tuning With Oracle ASH and AWR. Part 1 How And What
Performance Tuning With Oracle ASH and AWR. Part 1 How And WhatPerformance Tuning With Oracle ASH and AWR. Part 1 How And What
Performance Tuning With Oracle ASH and AWR. Part 1 How And What
 
A deep dive about VIP,HAIP, and SCAN
A deep dive about VIP,HAIP, and SCAN A deep dive about VIP,HAIP, and SCAN
A deep dive about VIP,HAIP, and SCAN
 
Oracle Database SQL Tuning Concept
Oracle Database SQL Tuning ConceptOracle Database SQL Tuning Concept
Oracle Database SQL Tuning Concept
 
Redo internals ppt
Redo internals pptRedo internals ppt
Redo internals ppt
 
Understanding Oracle RAC 12c Internals OOW13 [CON8806]
Understanding Oracle RAC 12c Internals OOW13 [CON8806]Understanding Oracle RAC 12c Internals OOW13 [CON8806]
Understanding Oracle RAC 12c Internals OOW13 [CON8806]
 
Chasing the optimizer
Chasing the optimizerChasing the optimizer
Chasing the optimizer
 
Understanding oracle rac internals part 2 - slides
Understanding oracle rac internals   part 2 - slidesUnderstanding oracle rac internals   part 2 - slides
Understanding oracle rac internals part 2 - slides
 
SQL Plan Directives explained
SQL Plan Directives explainedSQL Plan Directives explained
SQL Plan Directives explained
 
Oracle RAC 12c Practical Performance Management and Tuning OOW13 [CON8825]
Oracle RAC 12c Practical Performance Management and Tuning OOW13 [CON8825]Oracle RAC 12c Practical Performance Management and Tuning OOW13 [CON8825]
Oracle RAC 12c Practical Performance Management and Tuning OOW13 [CON8825]
 
pstack, truss etc to understand deeper issues in Oracle database
pstack, truss etc to understand deeper issues in Oracle databasepstack, truss etc to understand deeper issues in Oracle database
pstack, truss etc to understand deeper issues in Oracle database
 
Understanding oracle rac internals part 1 - slides
Understanding oracle rac internals   part 1 - slidesUnderstanding oracle rac internals   part 1 - slides
Understanding oracle rac internals part 1 - slides
 
UKOUG, Oracle Transaction Locks
UKOUG, Oracle Transaction LocksUKOUG, Oracle Transaction Locks
UKOUG, Oracle Transaction Locks
 
Christo kutrovsky oracle, memory & linux
Christo kutrovsky   oracle, memory & linuxChristo kutrovsky   oracle, memory & linux
Christo kutrovsky oracle, memory & linux
 
My First 100 days with an Exadata (PPT)
My First 100 days with an Exadata (PPT)My First 100 days with an Exadata (PPT)
My First 100 days with an Exadata (PPT)
 
Undo internalspresentation
Undo internalspresentationUndo internalspresentation
Undo internalspresentation
 
Oracle RAC Internals - The Cache Fusion Edition
Oracle RAC Internals - The Cache Fusion EditionOracle RAC Internals - The Cache Fusion Edition
Oracle RAC Internals - The Cache Fusion Edition
 
Oracle ASM Training
Oracle ASM TrainingOracle ASM Training
Oracle ASM Training
 
Deep review of LMS process
Deep review of LMS processDeep review of LMS process
Deep review of LMS process
 

Destacado

Todos los consejos en el blog para padres
Todos los consejos en el blog para padresTodos los consejos en el blog para padres
Todos los consejos en el blog para padresdemamas
 
La química y el deporte
La química y el deporteLa química y el deporte
La química y el deporteJTKirk61
 
parangaricutirimicuaro32
parangaricutirimicuaro32parangaricutirimicuaro32
parangaricutirimicuaro32Luis-R3y
 
Socializacion santa elena balsas
Socializacion santa elena balsasSocializacion santa elena balsas
Socializacion santa elena balsasyom94
 
Ranking radio - 1º ac. Movil 2.011 y 2º ac. Movil 2.011
Ranking radio - 1º ac. Movil 2.011  y 2º ac. Movil 2.011Ranking radio - 1º ac. Movil 2.011  y 2º ac. Movil 2.011
Ranking radio - 1º ac. Movil 2.011 y 2º ac. Movil 2.011Las Iniciativas
 
Cinematography of psychological horror’s over the years bdfh
Cinematography of psychological horror’s over the years bdfhCinematography of psychological horror’s over the years bdfh
Cinematography of psychological horror’s over the years bdfhamieelittle
 
Música y Mercado - edición #67
Música y Mercado - edición #67Música y Mercado - edición #67
Música y Mercado - edición #67Música & Mercado
 
Registro de datos como herramientas de calidad en PAI Dolor Torácico
Registro de datos como herramientas de calidad en PAI Dolor TorácicoRegistro de datos como herramientas de calidad en PAI Dolor Torácico
Registro de datos como herramientas de calidad en PAI Dolor TorácicoPlan de Calidad para el SNS
 
Revista agosto 2016(2)
Revista agosto 2016(2)Revista agosto 2016(2)
Revista agosto 2016(2)Utrera AL Dia
 
DevOps from Control to Enablement
DevOps from Control to EnablementDevOps from Control to Enablement
DevOps from Control to EnablementJoAnna Cheshire
 
La Primera Guerra Mundial
La Primera Guerra MundialLa Primera Guerra Mundial
La Primera Guerra Mundialneusgr
 
Infecciones postquirurgicas
Infecciones postquirurgicasInfecciones postquirurgicas
Infecciones postquirurgicasRamiro Emilio
 
Gamileku Plataforma Gamificación E-Innobar
Gamileku Plataforma Gamificación E-InnobarGamileku Plataforma Gamificación E-Innobar
Gamileku Plataforma Gamificación E-InnobarGamileku
 
Eurodata tv worldwide atf singapore kids 10122014 final
Eurodata tv worldwide   atf singapore kids 10122014 finalEurodata tv worldwide   atf singapore kids 10122014 final
Eurodata tv worldwide atf singapore kids 10122014 finalEurodataTVWorldwide
 
PODEMOS: Campaña electoral en redes sociales de Internet (Elecciones Europeas...
PODEMOS: Campaña electoral en redes sociales de Internet (Elecciones Europeas...PODEMOS: Campaña electoral en redes sociales de Internet (Elecciones Europeas...
PODEMOS: Campaña electoral en redes sociales de Internet (Elecciones Europeas...Sònia Broch Camarelles
 
Ejercicio De La Camisa Ok 1
Ejercicio De La Camisa Ok 1Ejercicio De La Camisa Ok 1
Ejercicio De La Camisa Ok 1guest4cf96b85
 
Contacts Mining And Construction Brazil
Contacts Mining And Construction BrazilContacts Mining And Construction Brazil
Contacts Mining And Construction Brazilborisburgos1
 

Destacado (20)

Todos los consejos en el blog para padres
Todos los consejos en el blog para padresTodos los consejos en el blog para padres
Todos los consejos en el blog para padres
 
La química y el deporte
La química y el deporteLa química y el deporte
La química y el deporte
 
parangaricutirimicuaro32
parangaricutirimicuaro32parangaricutirimicuaro32
parangaricutirimicuaro32
 
Socializacion santa elena balsas
Socializacion santa elena balsasSocializacion santa elena balsas
Socializacion santa elena balsas
 
Ranking radio - 1º ac. Movil 2.011 y 2º ac. Movil 2.011
Ranking radio - 1º ac. Movil 2.011  y 2º ac. Movil 2.011Ranking radio - 1º ac. Movil 2.011  y 2º ac. Movil 2.011
Ranking radio - 1º ac. Movil 2.011 y 2º ac. Movil 2.011
 
Cinematography of psychological horror’s over the years bdfh
Cinematography of psychological horror’s over the years bdfhCinematography of psychological horror’s over the years bdfh
Cinematography of psychological horror’s over the years bdfh
 
Música y Mercado - edición #67
Música y Mercado - edición #67Música y Mercado - edición #67
Música y Mercado - edición #67
 
Hotel Cápsula (Japão)
Hotel Cápsula (Japão)Hotel Cápsula (Japão)
Hotel Cápsula (Japão)
 
Registro de datos como herramientas de calidad en PAI Dolor Torácico
Registro de datos como herramientas de calidad en PAI Dolor TorácicoRegistro de datos como herramientas de calidad en PAI Dolor Torácico
Registro de datos como herramientas de calidad en PAI Dolor Torácico
 
Revista agosto 2016(2)
Revista agosto 2016(2)Revista agosto 2016(2)
Revista agosto 2016(2)
 
DevOps from Control to Enablement
DevOps from Control to EnablementDevOps from Control to Enablement
DevOps from Control to Enablement
 
La Primera Guerra Mundial
La Primera Guerra MundialLa Primera Guerra Mundial
La Primera Guerra Mundial
 
Infecciones postquirurgicas
Infecciones postquirurgicasInfecciones postquirurgicas
Infecciones postquirurgicas
 
Gamileku Plataforma Gamificación E-Innobar
Gamileku Plataforma Gamificación E-InnobarGamileku Plataforma Gamificación E-Innobar
Gamileku Plataforma Gamificación E-Innobar
 
Eurodata tv worldwide atf singapore kids 10122014 final
Eurodata tv worldwide   atf singapore kids 10122014 finalEurodata tv worldwide   atf singapore kids 10122014 final
Eurodata tv worldwide atf singapore kids 10122014 final
 
PMI Marketing Plan
PMI Marketing PlanPMI Marketing Plan
PMI Marketing Plan
 
Teoria de Polinomios (3º eso)
Teoria de Polinomios (3º eso)Teoria de Polinomios (3º eso)
Teoria de Polinomios (3º eso)
 
PODEMOS: Campaña electoral en redes sociales de Internet (Elecciones Europeas...
PODEMOS: Campaña electoral en redes sociales de Internet (Elecciones Europeas...PODEMOS: Campaña electoral en redes sociales de Internet (Elecciones Europeas...
PODEMOS: Campaña electoral en redes sociales de Internet (Elecciones Europeas...
 
Ejercicio De La Camisa Ok 1
Ejercicio De La Camisa Ok 1Ejercicio De La Camisa Ok 1
Ejercicio De La Camisa Ok 1
 
Contacts Mining And Construction Brazil
Contacts Mining And Construction BrazilContacts Mining And Construction Brazil
Contacts Mining And Construction Brazil
 

Similar a Direct SGA access without SQL

Oracle Open World Thursday 230 ashmasters
Oracle Open World Thursday 230 ashmastersOracle Open World Thursday 230 ashmasters
Oracle Open World Thursday 230 ashmastersKyle Hailey
 
SequoiaDB Distributed Relational Database
SequoiaDB Distributed Relational DatabaseSequoiaDB Distributed Relational Database
SequoiaDB Distributed Relational Databasewangzhonnew
 
Oracle 10g Performance: chapter 00 sampling
Oracle 10g Performance: chapter 00 samplingOracle 10g Performance: chapter 00 sampling
Oracle 10g Performance: chapter 00 samplingKyle Hailey
 
AWR, ADDM, ASH, Metrics and Advisors.ppt
AWR, ADDM, ASH, Metrics and Advisors.pptAWR, ADDM, ASH, Metrics and Advisors.ppt
AWR, ADDM, ASH, Metrics and Advisors.pptbugzbinny
 
Oracle 10g Performance: chapter 06 buffer cache
Oracle 10g Performance: chapter 06  buffer cacheOracle 10g Performance: chapter 06  buffer cache
Oracle 10g Performance: chapter 06 buffer cacheKyle Hailey
 
Thomas+Niewel+ +Oracletuning
Thomas+Niewel+ +OracletuningThomas+Niewel+ +Oracletuning
Thomas+Niewel+ +Oracletuningafa reg
 
Kyle Hailey Oracle Performance IO Waits
Kyle Hailey  Oracle Performance IO WaitsKyle Hailey  Oracle Performance IO Waits
Kyle Hailey Oracle Performance IO Waitscookie1969
 
11 Things About11g
11 Things About11g11 Things About11g
11 Things About11gfcamachob
 
11thingsabout11g 12659705398222 Phpapp01
11thingsabout11g 12659705398222 Phpapp0111thingsabout11g 12659705398222 Phpapp01
11thingsabout11g 12659705398222 Phpapp01Karam Abuataya
 
Memory Optimization
Memory OptimizationMemory Optimization
Memory OptimizationWei Lin
 
Memory Optimization
Memory OptimizationMemory Optimization
Memory Optimizationguest3eed30
 
Ds8000 Practical Performance Analysis P04 20060718
Ds8000 Practical Performance Analysis P04 20060718Ds8000 Practical Performance Analysis P04 20060718
Ds8000 Practical Performance Analysis P04 20060718brettallison
 
Sedna XML Database: Executor Internals
Sedna XML Database: Executor InternalsSedna XML Database: Executor Internals
Sedna XML Database: Executor InternalsIvan Shcheklein
 

Similar a Direct SGA access without SQL (20)

Oracle Open World Thursday 230 ashmasters
Oracle Open World Thursday 230 ashmastersOracle Open World Thursday 230 ashmasters
Oracle Open World Thursday 230 ashmasters
 
Unix executable buffer overflow
Unix executable buffer overflowUnix executable buffer overflow
Unix executable buffer overflow
 
SequoiaDB Distributed Relational Database
SequoiaDB Distributed Relational DatabaseSequoiaDB Distributed Relational Database
SequoiaDB Distributed Relational Database
 
Oracle 10g Performance: chapter 00 sampling
Oracle 10g Performance: chapter 00 samplingOracle 10g Performance: chapter 00 sampling
Oracle 10g Performance: chapter 00 sampling
 
AWR, ADDM, ASH, Metrics and Advisors.ppt
AWR, ADDM, ASH, Metrics and Advisors.pptAWR, ADDM, ASH, Metrics and Advisors.ppt
AWR, ADDM, ASH, Metrics and Advisors.ppt
 
Oracle 10g Performance: chapter 06 buffer cache
Oracle 10g Performance: chapter 06  buffer cacheOracle 10g Performance: chapter 06  buffer cache
Oracle 10g Performance: chapter 06 buffer cache
 
Using AWR for IO Subsystem Analysis
Using AWR for IO Subsystem AnalysisUsing AWR for IO Subsystem Analysis
Using AWR for IO Subsystem Analysis
 
Thomas+Niewel+ +Oracletuning
Thomas+Niewel+ +OracletuningThomas+Niewel+ +Oracletuning
Thomas+Niewel+ +Oracletuning
 
Using Statspack and AWR for Memory Monitoring and Tuning
Using Statspack and AWR for Memory Monitoring and TuningUsing Statspack and AWR for Memory Monitoring and Tuning
Using Statspack and AWR for Memory Monitoring and Tuning
 
Scope Stack Allocation
Scope Stack AllocationScope Stack Allocation
Scope Stack Allocation
 
Kyle Hailey Oracle Performance IO Waits
Kyle Hailey  Oracle Performance IO WaitsKyle Hailey  Oracle Performance IO Waits
Kyle Hailey Oracle Performance IO Waits
 
11 Things About11g
11 Things About11g11 Things About11g
11 Things About11g
 
11thingsabout11g 12659705398222 Phpapp01
11thingsabout11g 12659705398222 Phpapp0111thingsabout11g 12659705398222 Phpapp01
11thingsabout11g 12659705398222 Phpapp01
 
Memory Optimization
Memory OptimizationMemory Optimization
Memory Optimization
 
Memory Optimization
Memory OptimizationMemory Optimization
Memory Optimization
 
Ds8000 Practical Performance Analysis P04 20060718
Ds8000 Practical Performance Analysis P04 20060718Ds8000 Practical Performance Analysis P04 20060718
Ds8000 Practical Performance Analysis P04 20060718
 
Bluestore
BluestoreBluestore
Bluestore
 
Bluestore
BluestoreBluestore
Bluestore
 
Rmoug ashmaster
Rmoug ashmasterRmoug ashmaster
Rmoug ashmaster
 
Sedna XML Database: Executor Internals
Sedna XML Database: Executor InternalsSedna XML Database: Executor Internals
Sedna XML Database: Executor Internals
 

Más de Kyle Hailey

Hooks in postgresql by Guillaume Lelarge
Hooks in postgresql by Guillaume LelargeHooks in postgresql by Guillaume Lelarge
Hooks in postgresql by Guillaume LelargeKyle Hailey
 
Performance insights twitch
Performance insights twitchPerformance insights twitch
Performance insights twitchKyle Hailey
 
History of database monitoring
History of database monitoringHistory of database monitoring
History of database monitoringKyle Hailey
 
Successfully convince people with data visualization
Successfully convince people with data visualizationSuccessfully convince people with data visualization
Successfully convince people with data visualizationKyle Hailey
 
Virtual Data : Eliminating the data constraint in Application Development
Virtual Data :  Eliminating the data constraint in Application DevelopmentVirtual Data :  Eliminating the data constraint in Application Development
Virtual Data : Eliminating the data constraint in Application DevelopmentKyle Hailey
 
DBTA Data Summit : Eliminating the data constraint in Application Development
DBTA Data Summit : Eliminating the data constraint in Application DevelopmentDBTA Data Summit : Eliminating the data constraint in Application Development
DBTA Data Summit : Eliminating the data constraint in Application DevelopmentKyle Hailey
 
Accelerate Develoment with VIrtual Data
Accelerate Develoment with VIrtual DataAccelerate Develoment with VIrtual Data
Accelerate Develoment with VIrtual DataKyle Hailey
 
Delphix and Pure Storage partner
Delphix and Pure Storage partnerDelphix and Pure Storage partner
Delphix and Pure Storage partnerKyle Hailey
 
Mark Farnam : Minimizing the Concurrency Footprint of Transactions
Mark Farnam  : Minimizing the Concurrency Footprint of TransactionsMark Farnam  : Minimizing the Concurrency Footprint of Transactions
Mark Farnam : Minimizing the Concurrency Footprint of TransactionsKyle Hailey
 
Dan Norris: Exadata security
Dan Norris: Exadata securityDan Norris: Exadata security
Dan Norris: Exadata securityKyle Hailey
 
Martin Klier : Volkswagen for Oracle Guys
Martin Klier : Volkswagen for Oracle GuysMartin Klier : Volkswagen for Oracle Guys
Martin Klier : Volkswagen for Oracle GuysKyle Hailey
 
Data as a Service
Data as a Service Data as a Service
Data as a Service Kyle Hailey
 
Data Virtualization: Revolutionizing data cloning
Data Virtualization: Revolutionizing data cloningData Virtualization: Revolutionizing data cloning
Data Virtualization: Revolutionizing data cloning Kyle Hailey
 
BGOUG "Agile Data: revolutionizing database cloning'
BGOUG  "Agile Data: revolutionizing database cloning'BGOUG  "Agile Data: revolutionizing database cloning'
BGOUG "Agile Data: revolutionizing database cloning'Kyle Hailey
 
Denver devops : enabling DevOps with data virtualization
Denver devops : enabling DevOps with data virtualizationDenver devops : enabling DevOps with data virtualization
Denver devops : enabling DevOps with data virtualizationKyle Hailey
 
Oracle Open World 2014: Lies, Damned Lies, and I/O Statistics [ CON3671]
Oracle Open World 2014: Lies, Damned Lies, and I/O Statistics [ CON3671]Oracle Open World 2014: Lies, Damned Lies, and I/O Statistics [ CON3671]
Oracle Open World 2014: Lies, Damned Lies, and I/O Statistics [ CON3671]Kyle Hailey
 
Jonathan Lewis explains Delphix
Jonathan Lewis explains Delphix Jonathan Lewis explains Delphix
Jonathan Lewis explains Delphix Kyle Hailey
 
Oaktable World 2014 Toon Koppelaars: database constraints polite excuse
Oaktable World 2014 Toon Koppelaars: database constraints polite excuseOaktable World 2014 Toon Koppelaars: database constraints polite excuse
Oaktable World 2014 Toon Koppelaars: database constraints polite excuseKyle Hailey
 
Profiling the logwriter and database writer
Profiling the logwriter and database writerProfiling the logwriter and database writer
Profiling the logwriter and database writerKyle Hailey
 

Más de Kyle Hailey (20)

Hooks in postgresql by Guillaume Lelarge
Hooks in postgresql by Guillaume LelargeHooks in postgresql by Guillaume Lelarge
Hooks in postgresql by Guillaume Lelarge
 
Performance insights twitch
Performance insights twitchPerformance insights twitch
Performance insights twitch
 
History of database monitoring
History of database monitoringHistory of database monitoring
History of database monitoring
 
Successfully convince people with data visualization
Successfully convince people with data visualizationSuccessfully convince people with data visualization
Successfully convince people with data visualization
 
Virtual Data : Eliminating the data constraint in Application Development
Virtual Data :  Eliminating the data constraint in Application DevelopmentVirtual Data :  Eliminating the data constraint in Application Development
Virtual Data : Eliminating the data constraint in Application Development
 
DBTA Data Summit : Eliminating the data constraint in Application Development
DBTA Data Summit : Eliminating the data constraint in Application DevelopmentDBTA Data Summit : Eliminating the data constraint in Application Development
DBTA Data Summit : Eliminating the data constraint in Application Development
 
Accelerate Develoment with VIrtual Data
Accelerate Develoment with VIrtual DataAccelerate Develoment with VIrtual Data
Accelerate Develoment with VIrtual Data
 
Delphix and Pure Storage partner
Delphix and Pure Storage partnerDelphix and Pure Storage partner
Delphix and Pure Storage partner
 
Mark Farnam : Minimizing the Concurrency Footprint of Transactions
Mark Farnam  : Minimizing the Concurrency Footprint of TransactionsMark Farnam  : Minimizing the Concurrency Footprint of Transactions
Mark Farnam : Minimizing the Concurrency Footprint of Transactions
 
Dan Norris: Exadata security
Dan Norris: Exadata securityDan Norris: Exadata security
Dan Norris: Exadata security
 
Martin Klier : Volkswagen for Oracle Guys
Martin Klier : Volkswagen for Oracle GuysMartin Klier : Volkswagen for Oracle Guys
Martin Klier : Volkswagen for Oracle Guys
 
What is DevOps
What is DevOpsWhat is DevOps
What is DevOps
 
Data as a Service
Data as a Service Data as a Service
Data as a Service
 
Data Virtualization: Revolutionizing data cloning
Data Virtualization: Revolutionizing data cloningData Virtualization: Revolutionizing data cloning
Data Virtualization: Revolutionizing data cloning
 
BGOUG "Agile Data: revolutionizing database cloning'
BGOUG  "Agile Data: revolutionizing database cloning'BGOUG  "Agile Data: revolutionizing database cloning'
BGOUG "Agile Data: revolutionizing database cloning'
 
Denver devops : enabling DevOps with data virtualization
Denver devops : enabling DevOps with data virtualizationDenver devops : enabling DevOps with data virtualization
Denver devops : enabling DevOps with data virtualization
 
Oracle Open World 2014: Lies, Damned Lies, and I/O Statistics [ CON3671]
Oracle Open World 2014: Lies, Damned Lies, and I/O Statistics [ CON3671]Oracle Open World 2014: Lies, Damned Lies, and I/O Statistics [ CON3671]
Oracle Open World 2014: Lies, Damned Lies, and I/O Statistics [ CON3671]
 
Jonathan Lewis explains Delphix
Jonathan Lewis explains Delphix Jonathan Lewis explains Delphix
Jonathan Lewis explains Delphix
 
Oaktable World 2014 Toon Koppelaars: database constraints polite excuse
Oaktable World 2014 Toon Koppelaars: database constraints polite excuseOaktable World 2014 Toon Koppelaars: database constraints polite excuse
Oaktable World 2014 Toon Koppelaars: database constraints polite excuse
 
Profiling the logwriter and database writer
Profiling the logwriter and database writerProfiling the logwriter and database writer
Profiling the logwriter and database writer
 

Direct SGA access without SQL

  • 1. Oaktable  Jonathan Lewis and ORACLE_TRACE  Oracle_Trace crashes my Database  I start the SGA attach by searching every offset  Anjo Kolk says James Morle wrote a program using x$ksmmem  I show James my first draft using x$ksmmem  James is baffled by why I'm hard coding offsets  James says the offsets are in some X$ table  I search, turn up a mail by Jonathan Lewis on x$kqfco  Goldmine – all the offsets  Thanks Mogens Nogard!  Thanks to TomKyte's Decimal to Hex
  • 2.
  • 4. Direct Oracle SGA Memory Access Reading data directly from Oracle’s shared memory segment using C code Wednesday, February 20, 2013
  • 5. SGA on UNIX SMON S nnn D nnn P nnn PMON SGA CKPT Redo Log Shared Pool Database Buffer Cache Buffer DBWR ARCH LGWR oracle sqlplus Machine Memory
  • 6. SGA on NT S nnn D nnn P nnn CKPT SMON Machine Shared Pool Database Buffer Cache Redo Log Buffer Memory PMON DBWR LGWR ARCH oracle Process Space sqlplus
  • 7. What is the SGA  Memory Cache  Often Used Data  Rapid Access  Shareable  Concurrently Access
  • 8. SGA 4 main regions  Fixed information – Users info – Database statistics – X$dual – etc  Data block cache  SQL cache ( library cache/shared pool)  Redo log buffer
  • 9. How is the SGA info Used?  Automatically – data blocks cached – Log buffer – Sql cache – Updates of system and user statistics  User Queries – User info v$session – System info v$parameter – Performance statistics v$sysstat, v$latch, v$system_event – Buffer cache headers, x$bh
  • 10. Why Direct Access with C?  Reading Hidden Information – Sort info on version 7 – OPS locking info version 8 – Contents of data blocks (only the headers or visible in X$)  Access while Database is Hung  High Speed Access – Sampling User Waits, catch ephemeral data – Scan LRU chain in X$bh – Statistically approximate statistics  SQL statistics per user  Low overhead
  • 11. Database Slow or Hung Often happens at the largest sites when cutting edge support is expected.  Shared Pool errors ORA 4031  Archiver or Log file Switch Hangs  Hang Bugs  Library Cache Latch contention  ORA-00379: no free buffers available in buffer pool DEFAULT
  • 12. Statistical Sampling By Rapidly Sampling SQL statistics and the users who have the statistics open, one can see how much work a particular user does with a particular SQL statement
  • 13. Low Overhead  Marketing Appeal  Clients are sensitive about their production databases  Heisenberg uncertainty affect – less overhead less affect monitoring has on performance which we are monitoring
  • 14. SGA made visible through x$tables  Most of the SGA is not visible  X$KSMMEM Exception, Raw Dump of SGA  Information Externalized through X$ tables  Useful or Necessary information is Externalized  Externalized publicly through V$ Tables
  • 15. Machine Memory 0x80000000 SGA SGA
  • 16. Buffer Cache Graphic SGA SGA 0x80000000 Fixed Area Buffer Cache Shared Pool Log Buffer
  • 17. Fixed Area SGA X$KSUSECST- user waits 0x80000000 0x85251EF4
  • 18. X$KSUSECST 170 Records 2328 bytes 0x85251EF4 Row 1 Row 2 Row 3 …
  • 19. X$KSUSECST Record One Record in X$KSUSECST 1276 2328 bytes
  • 20. X$KSUSECST Fields 1276 1278 1280 1284 1288 Seq # Event # p1 p2 p3
  • 21. Externalization of C structs: X$ tables If Structure foo was externalized in a X$ SQL> describe x$foo Column Name Type ------------------------------ -------- ADDR RAW(8) INDX NUMBER ID NUMBER B NUMBER
  • 22. SGA is One Large C Struct struct foo { int id; int A; int B; int C; }; struct foo foo[N];
  • 23. Struct C code #include <stdio.h> #include <fcntl.h> #define N 20 /* structure definition: */ struct foo { int id; int a; int b; int c; }; /* end structure definition */
  • 24. Struct Record main(){ struct foo foo[20]; int fptr; /* zero out memory of struct */ memset(foo,0,sizeof(foo)); foo[0].id=1; /* row 0 */ foo[0].a=12; foo[0].b=13; foo[0].c=13;
  • 25. Struct Write to File foo[1].id=2; /* row 1 */ foo[1].a=22; foo[1].b=23; foo[1].c=24; /* write to file, simulate SGA */ if ((fptr = open("foo.out",O_WRONLY | O_CREAT,0777)) < 0 ) return -1; write(fptr,foo,sizeof(foo)); return 0; }
  • 26. Simulate SGA with a File write(fp,foo,sizeof(foo));
  • 27. Simulate SGA with a File Row 0 Row 1 ID A B C ID A … 0 1 3 4 6 8 bits 0 4 6 8 2 1 8 1 4 2 0 bytes 0 4 8 C 2 1 6 1 0 hex bytes 0 4 1 1 2 0 2 4 oct 0 Memory address 4 0 4 Increasing bytes
  • 28. Struct File Contents $ ./foo $ ls -l foo.out -rw-r--r-- joe dba 320 Feb 10 19:41 foo.out int = 32 bits Int = 4 bytes 20 entries * 4 int * 4 bytes/int = 320 bytes
  • 29. od – octal dump $ od -l foo.out 0000000 1 12 13 13 0000020 2 22 23 24 0000040 0 0 0 0 * 0000500
  • 30. Struct File Contents Address is in Hex Column 2 is the ID Column 3 is field A Column 4 is field B Column 5 is field C
  • 31. X$ tables ?  Ok, x$foo =~ foo[20]  How do I get a list of x$ tables?  Where is each X$ located?  V$Fixed_Tables
  • 32. V$Fixed_Table – list of X$ tables SQL> desc v$fixed_table; Name Null? Type ----------------------------------------- -------- ----------------- NAME VARCHAR2(30) OBJECT_ID NUMBER TYPE VARCHAR2(5) TABLE_NUM NUMBER
  • 33. Graphic: X$ Addresses SGA 0x80000000 0x8???????? X$????
  • 34. V$Fixed_Table spool addr.sql select 'select 'addr, ||''''||name||''''||' from ' || name ||' where rownum < 2;' from v$fixed_table where name like 'X%' / spool off @addr.sql
  • 35. Example: finding the address select a.addr , 'X$KSUSE' from X$KSUSE where rownum < 2 ;
  • 36. X$ layout 6802B244 X$KSLEMAP 6802B7EC X$KSLEI 6820B758 X$KSURU 6820B758 X$KSUSE - v$session 6820B758 X$KSUSECST – v$session_wait 6820B758 X$KSUSESTA – v$session_stat 6820B758 X$KSUSIO 6826FBD0 X$KSMDD 6831EA0C X$KSRCHDL
  • 37. What's in these X$ views  V$ views are documented  V$ views are based often on X$ tables  The map from v$ to X$ is described in : V$Fixed_View_Definition
  • 38. V$Fixed_View_Definition SQL> desc V$Fixed_View_Definition Name Type ----------------------------------- -------------- VIEW_NAME VARCHAR2(30) VIEW_DEFINITION VARCHAR2(4000)
  • 39. Definition of V$Session_Wait SQL> select VIEW_DEFINITION from V$FIXED_VIEW_DEFINITION where view_name='GV$SESSION_WAIT'; VIEW_DEFINITION ----------------------------------------------------------------------- select s.inst_id,s.indx,s.ksussseq,e.kslednam, e.ksledp1,s.ksussp1,s.ksussp1r,e. ksledp2, s.ksussp2,s.ksussp2r,e.ksledp3,s.ksussp3,s.ksussp3r, decode(s.ksusstim, 0,0,-1,-1,-2,-2, decode(round(s.ksusstim/10000),0,-1,round(s.ksusstim/10000))) , s.ksusewtm, decode(s.ksusstim, 0, 'WAITING', -2, 'WAITED UNKNOWN TIME', -1, ' WAITED SHORT TIME', 'WAITED KNOWN TIME') from x$ksusecst s, x$ksled e where bit and(s.ksspaflg,1)!=0 and bitand(s.ksuseflg,1)!=0 and s.ksussseq!=0 and s.ksussop c=e.indx
  • 40. The Fields in X$ tables  OK, I've picked an X$  I've got the starting address  Now, how do I get the fields?
  • 41. X$KQFTA  Kernel Query Fixed_view Table  INDX use to find column information  KQFTANAM X$ table names
  • 42. X$KQFCO  Kernel Query Fixed_view Column  KQFCOTAB Join with X$KQFTA.INDX  KQFCONAM Column name  KQFCOOFF Offset from beginning of the row  KQFCOSIZ Columns size in bytes
  • 43. X$KSUSECST Fields 1276 1278 1280 1284 1288 Address Seq # Event # p1 p2 p3 2 2 4 4 4 BYTES
  • 44. SGA Contents in Resume In resume: Oracle takes the C structure defining the SGA and maps it onto a shared memory segment Memory address Increasing 0x800000 0 Fixed SGA Buffer Redo Library Cache Buffer Cache Oracle provides access to some of the SGA contents via X$ tables
  • 45. **** Procedure ***** 1. Choose a V$ view 2. Find base X$ Tables for v$ view 3. Map X$ fields to V$ fields 4. Get address of X$ table in SGA 5. Get the size of each record in X$ table 6. Get the number of records in X$ table 7. Get offsets for each desired field in X$ table 8. Get the base address of SGA
  • 46. 1) V$SESSION_WAIT Example  List of all users waiting  Detailed information on the waits  Data is ephemeral  Useful in Bottleneck diagnostics  High sampling rate candidate  Event 10046 captures this info Good table for SGA sampling
  • 47. V$SESSION_WAIT Description SQL> desc v$session_wait Name Type ----------------------------------------- -------------------------- SID ,NUMBER SEQ# ,NUMBER EVENT ,VARCHAR2(64) P1TEXT ,VARCHAR2(64) P1 ,NUMBER P1RAW ,RAW(4) P2TEXT ,VARCHAR2(64) P2 ,NUMBER P2RAW ,RAW(4) P3TEXT ,VARCHAR2(64) P3 ,NUMBER P3RAW ,RAW(4) WAIT_TIME ,NUMBER SECONDS_IN_WAIT ,NUMBER STATE ,VARCHAR2(19) )
  • 48. V$SESSION_WAIT Short SQL> desc v$session_wait Name Type ---------------------------- ------------- SID NUMBER SEQ# NUMBER EVENT VARCHAR2(64) P1 NUMBER P2 NUMBER P3 NUMBER)
  • 49. V$FIXED_VIEW_DEFINITION Gives mappings of V$ views to X$ tables SQL> select VIEW_DEFINITION from V$FIXED_VIEW_DEFINITION where view_name='V$SESSION_WAIT‘;
  • 50. V$SESSION_WAIT View Definition VIEW_DEFINITION --------------------------------------------------------------------- select s.inst_id, s.indx, s.ksussseq, e.kslednam, e.ksledp1, s.ksussp1, s.ksussp1r, e.ksledp2, s.ksussp2, s.ksussp2r, e.ksledp3, s.ksussp3, s.ksussp3r, round(s.ksusstim / 10000), s.ksusewtm, decode(s.ksusstim, 0, 'WAITING', -2, 'WAITED UNKNOWN TIME', -1, 'WAITED SHORT TIME', 'WAITED KNOWN TIME') from x$ksusecst s, x$ksled e where bitand(s.ksspaflg,1)!=0 and bitand(s.ksuseflg,1)!=0 and s.ksussseq!=0 and s.ksussopc=e.indx
  • 51. View Definition Short VIEW_DEFINITION --------------------------------------------------------------------- select s.indx, s.ksussseq, e.kslednam, s.ksussp1, s.ksussp2, s.ksussp3 from x$ksusecst s, x$ksled e where s.ksussopc=e.indx
  • 52. 2) V$SESSION_WAIT Based on X$KSUSECT VIEW_DEFINITION --------------------------------------------------- - select indx, ksussseq, ksussopc, ksussp1, ksussp2, ksussp3 from x$ksusecst
  • 53. Equivalent SQL Statements select select indx, sid ksussseq, seq# ksussopc, event ksussp1, p1 ksussp2, p2 ksussp3 p3 from from x$ksusecst v$session_wait ) Note: x$ksusecst. Ksussopc is the event # x$ksled.kslednam is a list of the event names where x$ksled.indx = x$ksusecst. ksussopc
  • 54. 3) V$ to X$ Field Mapping
  • 55. 4) Get base SGA address for X$ table Find the location of X$KSUSECST in the SGA SQL> select addr from x$ksusecst where rownum < 2 ADDR -------- 85251EF4
  • 56. 5) Find the Size of Each Record SQL> select ((to_dec(e.addr)-to_dec(s.addr))) row_size from (select addr from x$ksusecst where rownum < 2) s, (select max(addr) addr from x$ksusecst where rownum < 3) e ; ROW_SIZE ---------------- 2328
  • 57. 6) Find the Number of Records in the structure SQL> select count(*) from x$ksusecst ; COUNT(*) -------------- 170
  • 58. Get Offsets for Each Desired Field in X$ table SQL> select c.kqfconam field_name, c.kqfcooff offset, c.kqfcosiz sz from x$kqfco c, x$kqfta t where t.indx = c.kqfcotab and t.kqftanam='X$KSUSECST' order by offset ;
  • 59. X$KQFTA - X$ Tables Names List of X$ tables  INDX use to find column information  KQFTANAM X$ table names To get Column information join with X$KQFCO X$KQFTA.INDX = X$KQFCO.KQFCOTAB
  • 60. X$KQFCO – X$ Table Columns List of all the columns in X$ Tables  KQFCOTAB Join with X$KQFTA.INDX  KQFCONAM Column name  KQFCOOFF Offset from beginning of the row  KQFCOSIZ Columns size in bytes
  • 61. Field Offsets FIELD_NAME OFFSET SZ ------------------------------ ---------- ---------- ADDR 0 4 INDX 0 4 KSUSEWTM 0 4 INST_ID 0 4 KSSPAFLG 1 1 KSUSSSEQ 1276 2 KSUSSOPC 1278 2 KSUSSP1 1280 4 KSUSSP1R 1280 4 KSUSSP2 1284 4 KSUSSP2R 1284 4 KSUSSP3 1288 4 KSUSSP3R 1288 4 KSUSSTIM 1292 4 KSUSENUM 1300 2 KSUSEFLG 1308 4
  • 62. What are all the fields at OFFSET 0? These are all calculated values and not stored explicitly in the SGA. ADDR memory address INDX record number, like rownum INST_ID database instance ID KSUSEWTM calculated field
  • 63. Unexposed Fields What happens between OFFSET 1 and 1276? • Unexposed Fields • Sometimes exposed elsewhere, in our case • V$SESSION • V$SESSTAT
  • 64. Fields at Same Address Why do some fields start at the same address? KSUSSP1 KSUSSP1R Are at the same address Equivalent of V$SESSION_WAIT.P1 V$SESSION_WAIT.P1RAW These are the same data, just exposed as Hex Decimal
  • 65. 7) Offsets of Fields
  • 66. 8) Get Base SGA Address SQL> select addr from x$ksmmem where rownum < 2 ADDR -------------- 80000000
  • 68. Machine Memory 0x80000000 SGA SGA
  • 69. Fixed Area SGA X$KSUSECST- user waits 0x80000000 0x85251EF4
  • 70. X$KSUSECST 170 Records 2328 bytes 0x85251EF4 Row 1 Row 2 Row 3 …
  • 71. X$KSUSECST Record One Record in X$KSUSECST 1276 2328 bytes
  • 72. X$KSUSECST Fields 1276 1278 1280 1284 1288 Seq # Event # p1 p2 p3
  • 73. Attaching to the SGA  UNIX System Call “shmat” To attach to shared memory Unix as a system call void *shmat( int shmid, const void *shmaddr, int shmflg );
  • 74. ID and Address arguments to “shmat” The arguments are:  shmid – shared memory identifier specified  shmaddr – starting address of the shared memory  shmflg - flags The argument shmflg can be set to SHM_RDONLY . To avoid any possible data corruption the SGA should only be attached read only. The arguments shmid and shmaddr need to be set to Oracle’s SGA id and address.
  • 75. Finding Oracle SGA’s ID and Address Use ORADEBUG to find the SGA id SQL> oradebug setmypid Statement processed. SQL> oradebug ipc Information written to trace file.  
  • 76. Finding Trace File SQL> show parameters user_dump NAME VALUE ----------------------- -------------------------------- user_dump_dest /u02/app/oracle/admin/V901/udump SQL> exit $ cd /u02/app/oracle/admin/V901/udump $ ls -ltr | tail -1 -rw-r----- usupport dba Aug 24 18:01 v901_ora_23179.trc
  • 77. Finding SHMID in Trace File $ vi v901_ora_23179.trc … Total size 004456c Minimum Subarea size 00000000 Area Subarea Shmid Stable Addr Actual Addr 0 0 34401 0080000000 0080000000 …
  • 78. Attaching to the SGA Shmid 34401 Shmaddr 0x80000000 Shmflg SHM_RDONLY The SGA attach call in C would be: Shmat(34401, 0x80000000, SHM_RDONLY); This call needs to be executed as a UNIX user who has read permission to the Oracle SGA
  • 79. C Code Headers #include <stdio.h> #include <sys/ipc.h> #include <sys/shm.h> #include <errno.h> #include "event.h" event.h is for translating the event #s into event names
  • 80. Events.h Spool events.h select 'char event[][100]={' from dual; select '"'||name||'",' from v$event_name; select ' "" };' from dual; spool off
  • 81. Define Base Addresses and Sizes /* SGA BASE ADDRESS */ #define SGA_BASE 0x80000000 /* START ADDR of KSUSECST(V$SESSION_WAIT) */ #define KSUSECST_ADDR 0x85251EF4 /* NUMBER of ROWS/RECORDS in KSUSECST */ #define SESSIONS 150 /* SIZE in BYTES of a ROW in KSUSECST */ #define RECORD_SZ 2328
  • 82. Define Offsets to Fields #define KSUSSSEQ 1276 /* sequence # */ #define KSUSSOPC 1278 /* event # */ #define KSUSSP1R 1280 /* p1 */ #define KSUSSP2R 1284 /* p2 */ #define KSUSSP3R 1288 /* p3 */
  • 83. Set Up Variables main(argc, argv) int argc; char **argv; { void *addr; int shmid; int shmaddr; void *current_addr; long p1r, p2r, p3r; unsigned int i, seq, tim, flg, evn;
  • 84. Attach to SGA /* ATTACH TO SGA */ shmid=atoi(argv[1]); shmaddr=SGA_BASE; if ( (void *)shmat( shmid, (void *)shmaddr, SHM_RDONLY) == (void *)-1 ) { printf("shmat: error attatching to SGAn"); exit(); }
  • 85. Set Up Sampling Loop /* LOOP OVER ALL SESSIONS until CANCEL */ while (1) { /* set current address to beginning of Table */ current_addr=(void *)KSUSECST_ADDR; sleep(1); printf("^[[H ^[[J"); /* clear screen */ /* print page heading */ printf("%4s %8s %-20.20s %10s %10s %10s n", "sid", "seq", "wait","p1","p2","p3");
  • 86. Loop over all Sessions for ( i=0; i < SESSIONS ; i++ ) { seq=*(unsigned short *)((int)current_addr+KSUSSSEQ); evn=*(short *) ((int)current_addr+KSUSSOPC); p1r=*(long *) ((int)current_addr+KSUSSP1R); p2r=*(long *) ((int)current_addr+KSUSSP2R); p3r=*(long *) ((int)current_addr+KSUSSP3R); if ( evn != 0 ) { printf("%4d %8u %-20.20s %10X %10X %10X n", i, seq, event[evn] ,p1r, p2r,p3r ); } current_addr=(void *)((int)current_addr+RECORD_SZ); } } }
  • 87. Output $ sga_read_session_wait 34401 sid seq wait p1 p2 p3 0 40582 pmon timer 12C 0 0 1 40452 rdbms ipc message 12C 0 0 2 43248 rdbms ipc message 12C 0 0 3 24706 rdbms ipc message 12C 0 0 4 736 smon timer 12C 0 0 5 88 rdbms ipc message 2BF20 0 0 8 178 SQL*Net message from 6265710 1 0
  • 88. Pitfalls  Byte Swapping  32 bit vs 64 bit  Multiple Shared Memory Segments  Segmented Memory  Addresses are "unsigned int"  Misaligned Access
  • 89. Little Endian vs Big Endian  Is low byte values first or high byte values first ?  a byte is 8 bits – 00000000-11111111 bits,0 – 31 dec, 0x0 - 0xFF hex  Big Endian is "normal" , highest bit first  In ascii, the word "byte" is stored as – b = 62, y = 79, t = 74, e = 65  echo 'byte' | od -x – b y t e – 62 79 74 65  Little Endian, ie byte swapped (Linux, OSF, Sequent, ? ) – y b e t – 79 62 65 74
  • 90. Byte Swap Example Short = 2 bytes ie 16 bits Goal, get the flag in the "second" byte #ifdef __linux uflg=*(short *)((int)sga_address)>>8; #else uflg=*(short *)((int)sga_address); #endif
  • 91. Byte Swap Big Endian: 00 00 00 00 00 00 00 01 Little Endian 00 00 00 01 00 00 00 00 Solution, push the value over 8 places, to the right, ie >>8
  • 92. 64 bit vs 32 bit  SQL> desc x$ksmmem Name Type ------------------------------------- --------- ADDR RAW(4) INDX NUMBER INST_ID NUMBER KSMMMVAL RAW(4) -> 32 bit Raw(8) -> 64 bit
  • 93. Segmented Memory x$ksuse – can be dis-contiguous Work around: select 'int users[]={' from dual; select '0x'||addr||',' from x$ksuse; select '0x0};' from dual;
  • 94. Misaligned Access  Some platforms seg fault when addressing misaligned bytes, need to read in even bytes or units of 4 bytes depending on platform 1 2 3 4 5 6 7 8
  • 95. x$ksusecst Record: What's Missing? One Record in X$KSUSECST ??? ??? 1276 2328 bytes
  • 96. Select Addr from X$? where Rownum< 2; 6802B244 X$KSLEMAP 6802B7EC X$KSLEI 6820B758 X$KSURU 6820B758 X$KSUSE – v$session 6820B758 X$KSUSECST – v$session_wait 6820B758 X$KSUSESTA – v$sesstat 6820B758 X$KSUSIO 6826FBD0 X$KSMDD 6831EA0C X$KSRCHDL
  • 97. x$ksuse Record Contains x$ksusecst One Record in X$Ksusecst v$session v$sesstat v$session_wait v$session 236 1276 2328 bytes x$ksusesta x$ksusecst x$ksuse
  • 98. Getting v$sesstat addresses select '#define '|| upper(translate(s.name,' :-()/*''','________'))||' '|| to_char(c.kqfcooff + STATISTIC# * 4 ) from x$kqfco c, x$kqfta t, v$statname s where t.indx = c.kqfcotab and ( t.kqftanam='X$KSUSESTA' ) and c.kqfconam='KSUSESTV' and kqfcooff > 0 order by c.kqfcooff /
  • 99. User Drilldown Query: 4 joins select w.sid sid, w.seq# seq, w.event event, w.p1raw p1, w.p2raw p2, w.p3raw p3, w.SECONDS_IN_WAIT ctime, s.sql_hash_value sqlhash, s.prev_hash_value psqlhash, st.value cpu from v$session s, v$sesstat st, v$statname sn, v$session_wait w where w.sid = s.sid and st.sid = s.sid and st.statistic# = sn.statistic# and sn.name = 'CPU used when call started' and w.event != 'SQL*Net message from client' order by w.sid;
  • 100. Other Fun Stuff The next example is output from an SGA program that follows the LRU of the Buffer Cache The program demonstrates the • insertion point of LRU • cold end of LRU • hot end of the LRU • Full Table Scan Insertion Point

Notas del editor

  1. Notice that column A and C are missing from x$foo. Not all values in a structure used in the SGA are made visible via SQL
  2. If we mapped the structure on memory or dumped it in a file, we could find the different elements
  3. If we mapped the structure on memory or dumped it in a file, we could find the different elements
  4. Oracle doesn’t always expose all the fields in the structure thus if there are gaps in the offsets that are bigger than the field sizes then there is other information in the underlying structure that isn’t exposed in the X$ table. (in this case those address are exposed but in different X$ tables)