• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
B13 Investigating oracle by Julian Dyke
 

B13 Investigating oracle by Julian Dyke

on

  • 738 views

 

Statistics

Views

Total Views
738
Views on SlideShare
738
Embed Views
0

Actions

Likes
0
Downloads
35
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    B13 Investigating oracle by Julian Dyke B13 Investigating oracle by Julian Dyke Presentation Transcript

    • 1 Investigating Oracle Julian Dyke Independent Consultant DB Tech Showcase - Osaka May 2013 juliandyke.com© 2013 Julian Dyke
    • juliandyke.com© 2013 Julian Dyke About Me  Worked with Oracle databases since 1989  Independent Consultant for 8 years  Regular presenter at Conferences, Seminars and Special Interest Groups  Co-Author of Pro Oracle Database 10g RAC on Linux  Member of Oak Table Network since 2003  Member of UKOUG Council  Former UKOUG director  Former chair of UKOUG RAC & HA SIG  Oracle ACE Expert  Oracle Certified DBA – 7.3, 8, 8i, 9i and 10i 2
    • juliandyke.com© 2013 Julian Dyke3 Investigating Oracle Introduction  This presentation describes various techniques for investigating Oracle features  Investigative techniques differ depending on feature under investigation  Why investigate?  Feature evaluation  Performance  Compatibility  Licensing costs
    • juliandyke.com© 2013 Julian Dyke Investigating Oracle Agenda  Initial Research  Advanced Research  Oracle Tools  Execution Plans  Trace  Dumps  Internals  Operating System Tools  Custom Tools 4
    • juliandyke.com© 2013 Julian Dyke5 Initial Research
    • juliandyke.com© 2013 Julian Dyke6 Initial Research Read the Oracle Documentation  Read ALL of the Oracle documentation for the feature  Useful sources include:  New Features Guide 11g Release 1 (11.2)  Part Number E10881-01  Other Oracle documents  What's New in... sections  White Papers  Oracle Technology Network  http://www.oracle.com/technetwork  My Oracle Support  http://support.oracle.com  Review the SQL syntax that supports the feature in:  SQL Language Reference  PL/SQL Packages and Types Reference
    • juliandyke.com© 2013 Julian Dyke Initial Research Read Third Party Documentation  Read any available third party documentation for the feature  Blogs  Websites  Books  Presentations  White Papers  Make information is accurate and credible 7
    • juliandyke.com© 2013 Julian Dyke Initial Research Learn how the new feature works  Build a test environment  Build VMs  Configure storage  Install Oracle software  Install required patch sets / one-offs  Create database(s)  Configure feature  Set parameters  Test feature  DDL  DML  etc 8
    • juliandyke.com© 2013 Julian Dyke Initial Research Licensing  Check the licensing requirements for the feature being investigated  Almost all recent new features have been licensed options  Investigation may not be cost-effective  Check the Oracle Licensing document  Check the global pricing document  Check your existing license agreement  Gotchas include:  VMWare environments  Primary and standby configurations  RAC/Exadata environments 9
    • juliandyke.com© 2013 Julian Dyke10 Advanced Research
    • juliandyke.com© 2013 Julian Dyke11 Advanced Research Supported Parameters  Supported parameter values are reported in  V$PARAMETER  V$SYSTEM_PARAMETER  V$SPPARAMETER  Normalized lists of values are reported in  V$PARAMETER2  V$SYSTEM_PARAMETER2  In Oracle 10.1 and above, valid values for supported parameters are reported in  V$PARAMETER_VALID_VALUES
    • juliandyke.com© 2013 Julian Dyke12 Advanced Research Unsupported Parameters  Unsupported parameter values are reported in  X$KSPPI  X$KSPPSV  X$KSPPCV  To print parameter name, description and values use:  In Oracle 10.1 and above, valid values for unsupported parameters are reported in  X$KSPVLD_VALUES SELECT i.ksppinm, i.ksppdesc, sv.ksppstvl FROM x$ksppi i, x$ksppsv sv WHERE i.indx = sv.indx ORDER BY i.ksppinm;
    • juliandyke.com© 2013 Julian Dyke13 Advanced Research Optimizer Parameters  In Oracle 10.1 and above, optimizer parameter values are reported at  Instance-level  Session-level  Statement-level  Dynamic performance views only report supported parameters  Fixed (X$) tables include unsupported parameters: Level Supported Parameters Unsupported Parameters Instance V$SYS_OPTIMIZER_ENV X$QKSCESYS Session V$SES_OPTIMIZER_ENV X$QKSCESES Statement V$SQL_OPTIMIZER_ENV X$KQLFSQCE
    • juliandyke.com© 2013 Julian Dyke14 Advanced Research Data Dictionary View Definitions  Data dictionary views are based on data dictionary objects DBA_% Accessible by all users ALL_% Accessible by current user USER_% Accessible by users with DBA privilege only  View definitions can be found in DBA_VIEWS SET LONG 50000 SELECT text FROM dba_views WHERE view_name = 'DBA_INDEXES';  Many views are defined in terms of other views e.g. DBA_SEGMENTS is now based on SYS_DBA_SEGS
    • juliandyke.com© 2013 Julian Dyke15 Advanced Research Data Dictionary Objects  The data dictionary is created in the SYSTEM tablespace  Objects are owned by SYS  Data dictionary tables include: Table Name Description OBJ$ Objects TAB$ Tables IND$ Indexes COL$ Columns USER$ Users SEG$ Segments FET$ Free Extents UET$ Used Extents TS$ Tablespaces FILE$ Files
    • juliandyke.com© 2013 Julian Dyke16 Advanced Research Data Dictionary Index Clusters  Many data dictionary objects are stored in index clusters  For example C_OBJ# is a cluster containing the following tables: ASSEMBLY$ ICOLDEP$ REFCON$ ATTRCOL$ IND$ SUBCOLTYPE$ CLU$ LIBRARY$ TAB$ COL$ LOB$ TYPE_MISC$ COLTYPE$ NTAB$ VIEWTRCOL$ ICOL$ OPQTYPE$ ICOLDEP$  Other clusters include:  C_USER#  C_FILE#_BLOCK#  C_TS#  Index clusters increase complexity of:  Trace files  Redo/undo changes
    • juliandyke.com© 2013 Julian Dyke17 Advanced Research SQL.BSQ  During database creation, data dictionary objects are defined in $ORACLE_HOME/rdbms/admin/sql.bsq  In Oracle 11.1 and above, sql.bsq has been divided into the following files: dcore.bsq drac.bsq daw.bsq dsqlddl.bsq dsec.bsq dsummgt.bsq dmanage.bsq doptim.bsq dtools.bsq dplsql.bsq dobj.bsq dexttab.bsq dtxnspc.bsq djava.bsq ddm.bsq dfmap.bsq dpart.bsq dlmnr.bsq denv.bsq drep.bsq  The core data dictionary tables (obj$, tab$, ind$, col$ etc) are specified in dcore.bsq
    • juliandyke.com© 2013 Julian Dyke18 Advanced Research Dynamic Performance View Definitions  Definitions reported by  V$FIXED_VIEW_DEFINITION  Global (GV$) view selects from underlying fixed (X$) tables SELECT view_definition FROM v$fixed_view_definition WHERE view_name = 'GV$RESULT_CACHE_MEMORY'; VIEW_DEFINITION SELECT inst_id, qesrcmem_lad, qesrcmem_cnk, qesrcmem_blk, DECODE (qesrcmem_sta, 0, 'NO', 1, 'YES'), qesrcmem_oid, qesrcmem_pos FROM x$qesrcmem; SELECT view_definition FROM v$fixed_view_definition WHERE view_name = 'V$RESULT_CACHE_MEMORY'; VIEW_DEFINITION SELECT id, chunk, offset, free, object_id, position FROM gv$result_cache_memory WHERE inst_id = USERENV ('Instance')  Instance (V$) view selects from global (GV$) view
    • juliandyke.com© 2013 Julian Dyke Advanced Research PL/SQL Package Definitions  PL/SQL package headers are distributed in $ORACLE_HOME/rdbms/admin  For example:  dbmsmntr.sql contains package header for DBMS_MONITOR  dbmsxplan.sql contains package header for DBMS_XPLAN  Names are not intuitive  Use grep to find specific packages  Package headers contain comments that can be useful when documentation is inadequate e.g.:  new parameters  ambiguity  Most package bodies are wrapped:  Unwrap tools can be found on the internet  Probably break terms of licence agreements 19
    • juliandyke.com© 2013 Julian Dyke20 Advanced Research Error Messages  Error messages describe what a feature does not support  Can be useful to understand how feature is implemented  See $ORACLE_HOME/rdbms/mesg/oraus.msg  Contains all message and event definitions  Individual messages reported by oerr on Unix platforms  Binary file - on Unix use strings utility to inspect contents $ strings $ORACLE_HOME/rdbms/mesg/oraus.msg > /tmp/oraus.txt  A range of error numbers is initially allocated for each feature  Some features have more than one range
    • juliandyke.com© 2013 Julian Dyke21 Advanced Research Fixed Tables and Views  V$FIXED_TABLES reports all fixed objects including  Fixed (X$) tables  Derived fixed (X$) tables (fixed views)  Global (GV$) dynamic performance views  Instance (V$) dynamic performance views  V$INDEXED_FIXED_COLUMN reports all indexed columns for  Fixed (X$) tables
    • juliandyke.com© 2013 Julian Dyke22 Advanced Research Fixed Tables and Views  Fixed (X$) tables are described in X$KQFTA  Fixed (X$) derived tables are described in X$KQFDT  Fixed (X$) table columns arev described in X$KQFCO  Internal data type reported in KQFCODTY  Indexes reported in KQFCOIDX and KQFCOIPO SELECT co.kqfconam, CASE co.kqfcodty WHEN 2 THEN 'NUMBER' WHEN 23 THEN 'RAW ('||kqfcosiz||')' END FROM x$kqfco co, x$kqfta ta WHERE co.kqfcotab = ta.indx AND ta.kqftanam = 'X$QESRCMEM' ORDER BY co.kqfcocno;
    • juliandyke.com© 2013 Julian Dyke23 Advanced Research Fixed Tables  X$KQFCO.KQFCODTY reports internal column data type  Current values in Oracle 11.1 Value Description 1 VARCHAR2 2 NUMBER 12 DATE 23 RAW 112 CLOB 180 TIMESTAMP 181 TIMESTAMP WITH TIME ZONE  See http://www.juliandyke.com for more comprehensive list of internal data types (Internals/Internal Data Types)
    • juliandyke.com© 2013 Julian Dyke24 Advanced Research Shared Memory  V$SGA  reports SGA memory sizes  V$SGAINFO  reports SGA memory pool sizes  introduced in Oracle 10.1  V$SGASTAT  reports SGA memory area sizes  enhanced in Oracle 10.1
    • juliandyke.com© 2013 Julian Dyke25 Advanced Research Shared Memory  X$KSMFSV  Contents of fixed SGA  X$KSMGE  Reports granule allocation  X$KSMMEM  Contents of SGA presented as an array  Usually fails in Windows  Usually fails with Automatic Memory Management  X$KSMSP  Reports shared pool memory usage  X$KSMHP  Reports heap allocation
    • juliandyke.com© 2013 Julian Dyke Advanced Research AWR Tables  Some AWR tables contain useful information including:  DBA_HIST_PLAN_OPERATION_NAME  Execution plan operations  DBA_HIST_PLAN_OPTION_NAME  Execution plan operation options  DBA_HIST_SQLCOMMAND_NAME  Command types and names – similar to AUDIT_ACTIONS  DBA_HIST_TOPLEVELCALL_NAME  Top level calls 26
    • juliandyke.com© 2013 Julian Dyke27 Advanced Research Dynamic Performance Views  V$BGPROCESS (X$KSBDD)  List of background processes  V$LATCHNAME (X$KSLLD)  List of parent latches  V$EVENT_NAME (X$KSLED)  List of wait events  V$LOCK_TYPE (X$KSIRESTYP)  List of lock/enqueue types (Oracle 10.1 and above)  V$SQL_HINT  List of supported hints  V$SQL_FEATURE  List of supported features
    • juliandyke.com© 2013 Julian Dyke28 Advanced Research Dynamic Performance Views  V$TYPE_SIZE (X$KQFSZ)  Size in bytes of various data types  V$RESERVED_WORDS (X$KWDDEF)  List of keywords / reserved words  X$MESSAGES  List of messages exchanged between processes
    • juliandyke.com© 2013 Julian Dyke29 Advanced Research Standard Package  $ORACLE_HOME/rdbms/admin/standard.sql  Contains definitions of standard PL/SQL types, built-in functions and exceptions  For example:  DECODE  SUBSTR  INSTR  UPPER  LOWER  In Oracle 11.2 standard.sql calls  stdspec.sql  stdbody.sql
    • juliandyke.com© 2013 Julian Dyke30 Oracle Tools Execution Plans
    • juliandyke.com© 2013 Julian Dyke31 Execution Plans AUTOTRACE  SQL*Plus feature  Prints execution plans and execution statistics $ORACLE_HOME/rdbms/admin/utlxplan.sql  Requires PLUS_TRACE role $ORACLE_HOME/sqlplus/admin/plustrce.sql GRANT plustrce TO user1;  In Oracle 10.1 and above execution plan output uses DBMS_XPLAN format:  Automatically includes:  Partition information  Parallel execution information  Requires access to a PLAN_TABLE
    • juliandyke.com© 2013 Julian Dyke32 Execution Plans AUTOTRACE  Options are: SET AUTOTRACE OFF No report generated - default SET AUTOTRACE ON EXPLAIN Shows execution plan SET AUTOTRACE ON STATISTICS Shows execution statistics SET AUTOTRACE ON Shows output, execution plan and statistics SET AUTOTRACE ON TRACEONLY Suppresses query output if executed  The EXPLAIN option generates a new execution plan  Optimizer environment may differ from user sessions  SET AUTOTRACE TRACEONLY EXPLAIN  Shows execution plan for SELECT statements  Shows execution plan AND executes DML statements Note that SET AUTOT TRACE EXP executes DML statements Any changes must be rolled back manually Alternatively explain the SELECT subquery only
    • juliandyke.com© 2013 Julian Dyke33 Execution Plans DBMS_XPLAN  Introduced in Oracle 9.2  Enhanced in subsequent releases  Useful subroutines include  DISPLAY - display a plan from a PLAN_TABLE  DISPLAY_AWR - display a plan from the AWR  DISPLAY_CURSOR - display a plan from the library cache  DISPLAY_PLAN – returns plan as a CLOB  DISPLAY_SQLSET – displays a plan from a SQL tuning set  DISPLAY_SQLPLAN_BASELIN E – displays a plan from SQL baseline  For example to display execution plan for statement most recently executed by the current session: SELECT * FROM TABLE (DBMS_XPLAN.DISPLAY_CURSOR);
    • juliandyke.com© 2013 Julian Dyke Execution Plans DBMS_XPLAN  The FORMAT parameter specifies the output format for the execution plan  There are four options:  BASIC – minimum information - operation ID, operation name and option only  TYPICAL – default – most relevant information in plan – operation id, operation name, option, #rows, # bytes, optimizer cost. Also pruning, parallel and predicate information where applicable  SERIAL – same as TYPICAL except parallel information is not displayed even if plan executes in parallel  ALL – same as TYPICAL. Also includes PROJECTION, ALIAS and REMOTE SQL if applicable 34
    • juliandyke.com© 2013 Julian Dyke Execution Plans DBMS_XPLAN  The following keywords can be added to the FORMAT options for more fine- grained control of output  ROWS – number of rows estimated by optimizer  BYTES – number of bytes estimated by optimizer  COST – optimizer cost information  PARTITION – partition pruning information  PARALLEL – parallel execution information  PREDICATE – predicate section  PROJECTION – projection section  ALIAS – Query Block Name / Object Alias section  REMOTE – distributed query information  NOTE - note section of plan  Sections are only displayed if relevant  To exclude a section prefix with minus e.g. -PROJECTION 35
    • juliandyke.com© 2013 Julian Dyke Execution Plans DBMS_XPLAN  For DISPLAY_CURSOR and DISPLAY_SQLSET, additional data can be output using the following keywords:  IOSTATS – shows IO statistics for all executions of the cursor  MEMSTATS – displays memory management statistics including  execution mode of operator  how much memory was used  number of bytes spilled to disk  ALLSTATS – both IOSTATS and MEMSTATS  LAST – only report statistics for last execution of cursor  IOSTATS, ALLSTATS and LAST require basic plan statistics which are collected by  setting STATISTICS_LEVEL parameter to ALL  specifying GATHER_PLAN_STATISTICS hint  MEMSTATS requires PGA memory management to be enabled by:  setting PGA_AGGREGATE_TARGET to non-zero value 36
    • juliandyke.com© 2013 Julian Dyke37 Oracle Tools Trace
    • juliandyke.com© 2013 Julian Dyke38 SQL Trace Diagnostics Area  In Oracle 11.1 and above trace files and alert logs are written to the diagnostics area:  Default location is $ORACLE_HOME/diag  Trace files and alter log are written to  $ORACLE_BASE/diag/rdbms/<database>/<instance>/trace  For example for database TEST  $ORACLE_BASE/diag/rdbms/test/TEST/trace  BACKGROUND_DUMP_DEST and USER_DUMP_DEST parameters still available in Oracle 11.2  New dynamic performance view V$DIAG_INFO reports trace locations  Trace file for current process can be identified using: SELECT value FROM v$diag_info WHERE name = 'Default Trace File';
    • juliandyke.com© 2013 Julian Dyke39 SQL Trace Trace File Identifier  In Oracle 8.1.5 and above a suffix can be added to the trace file name using TRACEFILE_IDENTIFIER parameter For example given the following current trace filename: ALTER SESSION SET tracefile_identifier = 'TEST1'; TEST_ora_24672.trc  The following statement:  will add the suffix "_TEST1" to the file name e.g. TEST_ora_24672_TEST1.trc
    • juliandyke.com© 2013 Julian Dyke40 DBMS_MONITOR Overview  Introduced in Oracle 10.1  Contains the following subroutines:  SESSION_TRACE_ENABLE  SESSION_TRACE_DISABLE  DATABASE_TRACE_ENABLE  DATABASE_TRACE_DISABLE  CLIENT_ID_TRACE_ENABLE  CLIENT_ID_TRACE_DISABLE  CLIENT_ID_STAT_ENABLE  CLIENT_ID_STAT_DISABLE  SERV_MOD_ACT_TRACE_ENABLE  SERV_MOD_ACT_TRACE_DISABLE  SERV_MOD_ACT_STAT_ENABLE  SERV_MOD_ACT_STAT_DISABLE  DBMS_MONITOR trace configuration is reported in DBA_ENABLED_TRACES
    • juliandyke.com© 2013 Julian Dyke41 DBMS_MONITOR Enabling and Disabling Trace  To enable and disable trace in the current session use: EXECUTE DBMS_MONITOR.SESSION_TRACE_ENABLE; EXECUTE DBMS_MONITOR.SESSION_TRACE_DISABLE;  To enable and disable trace in another session e.g. 42 use: EXECUTE DBMS_MONITOR.SESSION_TRACE_ENABLE (SESSION_ID => 42); EXECUTE DBMS_MONITOR.SESSION_TRACE_DISABLE (SESSION_ID => 42);  To enable and disable trace for instance RAC1 use: EXECUTE DBMS_MONITOR.DATABASE_TRACE_ENABLE (INSTANCE_NAME => 'RAC1'); EXECUTE DBMS_MONITOR.DATABASE_TRACE_DISABLE (INSTANCE_NAME => 'RAC1');  To enable and disable trace for the entire database use: EXECUTE DBMS_MONITOR.DATABASE_TRACE_ENABLE; EXECUTE DBMS_MONITOR.DATABASE_TRACE_DISABLE;
    • juliandyke.com© 2013 Julian Dyke42 DBMS_MONITOR Client Identifiers  Trace can be enabled for using client identifiers  Useful when many sessions connect using the same Oracle user  Useful with connection caches  To set a client identifier use DBMS_SESSION.SET_IDENTIFIER e.g.:  The client identifier is reported in V$SESSION.CLIENT_IDENTIFIER DBMS_SESSION.SET_IDENTIFIER ('CLIENT42');  To enable and disable trace for CLIENT42 use: DBMS_MONITOR.CLIENT_ID_TRACE_ENABLE (CLIENT_ID => 'CLIENT42'); DBMS_MONITOR.CLIENT_ID_TRACE_DISABLE (CLIENT_ID => 'CLIENT42');  To enable and disable statistics collection for CLIENT42 use: DBMS_MONITOR.CLIENT_ID_STAT_ENABLE (CLIENT_ID => 'CLIENT42'); DBMS_MONITOR.CLIENT_ID_STAT_DISABLE (CLIENT_ID => 'CLIENT42');  Client statistics are reported in V$CLIENT_STATS
    • juliandyke.com© 2013 Julian Dyke43 DBMS_MONITOR Services, Modules & Actions  Trace can be enabled for a specific  service  service and module  service, module and action  Current module and action reported by  V$SESSION.MODULE  V$SESSION.ACTION  To specify a new action within the current module use: DBMS_APPLICATION_INFO.SET_ACTION (ACTION_NAME=> 'ACTION2'); DBMS_APPLICATION_INFO.SET_MODULE (MODULE_NAME => 'MODULE1', ACTION_NAME=> 'ACTION1');  To specify a module and action with a session use:
    • juliandyke.com© 2013 Julian Dyke44 DBMS_MONITOR Services, Modules & Actions  To enable trace for use:  To enable statistics collection use: DBMS_MONITOR.SERV_MOD_ACT_TRACE_ENABLE (SERVICE_NAME => 'SERVICE1',MODULE_NAME => 'MODULE1',ACTION_NAME => 'ACTION1‘); DBMS_MONITOR.SERV_MOD_ACT_TRACE_ENABLE (SERVICE_NAME => 'SERVICE1',MODULE_NAME => 'MODULE1‘); DBMS_MONITOR.SERV_MOD_ACT_STAT_ENABLE (SERVICE_NAME => 'SERVICE1',MODULE_NAME => 'MODULE1',ACTION_NAME => 'ACTION1‘); DBMS_MONITOR.SERV_MOD_ACT_STAT_ENABLE (SERVICE_NAME => 'SERVICE1',MODULE_NAME => 'MODULE1‘); DBMS_MONITOR.SERV_MOD_ACT_STAT_ENABLE (SERVICE_NAME => 'SERVICE1'); DBMS_MONITOR.SERV_MOD_ACT_TRACE_ENABLE (SERVICE_NAME => 'SERVICE1');  Statistics are reported in V$SERV_MOD_ACT_STATS
    • juliandyke.com© 2013 Julian Dyke45 DBMS_MONITOR Row Source Statistics  In Oracle 11.2 and above PLAN_STAT parameter is supported in:  CLIENT_ID_TRACE_ENABLE  DATABASE_TRACE_ENABLE  SERV_MOD_ACT_TRACE_ENABLE  SESSION_TRACE_ENABLE  PLAN_STAT specifies frequency of row source statistic dumps. Can be:  NEVER  FIRST_EXECUTION (default)  ALL_EXECUTIONS  In Oracle 11.2 and above event 10046 level 16 also dumps row source statistics for all executions  To dump binds + waits + statistics use event 10046 level 28 ALTER SESSION SET EVENTS ‘10046 trace name context forever, level 28’’;
    • juliandyke.com© 2013 Julian Dyke46 DBMS_MONITOR Interpreting Trace  Use TKPROF to sort and filter the trace file  Avoid re-explaining execution plans  Use TRCSESS to merge trace files  Useful with shared server (MTS)  See Metalink Note: 39817.1 Interpreting Raw SQL_TRACE and DBMS_SUPPORT.START_TRACE output  Describes contents of trace file  See Optimizing Oracle Performance Cary Millsap & Jeff Holt (O'Reilly)
    • juliandyke.com© 2013 Julian Dyke47 Oracle Tools Dumps
    • juliandyke.com© 2013 Julian Dyke48 ORADEBUG Overview  Undocumented SQL*Plus feature  Requires SQLDBA privilege  Allows session to connect to other processes and execute commands  A process must be specified for many ORADEBUG commands using one of:  ORADEBUG SETMYPID – connect to local process  ORADEBUG SETORAPID – connect using Oracle process ID  ORADEBUG SETOSPID – connect using OS pid  All commands are prefixed with ORADEBUG  To obtain a list of commands use ORADEBUG HELP  New functionality is frequently added  Review in each new release
    • juliandyke.com© 2013 Julian Dyke49 ORADEBUG Dumps  To list of available dumps can be obtained using ORADEBUG DUMPLIST  Most dumps can be performed by  ORADEBUG  ALTER SYSTEM  ALTER SESSION  Some dumps can be very useful for specific investigations  Dumps are mostly undocumented  187 dumps listed in Oracle 11.2.0.3  Some dumps modify database  Only use on  non-production databases  when requested by Oracle Support
    • juliandyke.com© 2013 Julian Dyke50 Memory Dumps Trace Dumps  Memory dumps can be taken using  ORADEBUG  ALTER SYSTEM  ALTER SESSION  For example to dump fixed SGA including contents ALTER SESSION SET EVENTS 'immediate trace name global_area level 2‘;  To dump summary of SGA heap use: ALTER SESSION SET EVENTS 'immediate trace name heapdump level 2‘;  To dump contents of a specific SGA subheap use: ALTER SESSION SET EVENTS 'immediate trace name heapdump_addr level 2, addr <address>';
    • juliandyke.com© 2013 Julian Dyke51 File Dumps Redo Log Dumps  To identify the current redo log use: SELECT member FROM v$logfile WHERE group# = ( SELECT group# FROM v$log WHERE status = 'CURRENT' );  To dump the contents of a redo log use: ALTER SYSTEM DUMP LOGFILE '<logfilename>';  Also works for archived log files
    • juliandyke.com© 2013 Julian Dyke52 File Dumps Redo Log Dumps  Full syntax is: ALTER SYSTEM DUMP LOGFILE 'FileName' SCN MIN MinimumSCN SCN MAX MaximumSCN TIME MIN MinimumTime TIME MAX MaximumTime LAYER Layer OPCODE Opcode DBA MIN FileNumber . BlockNumber DBA MAX FileNumber . BlockNumber RBA MIN LogFileSequenceNumber . BlockNumber RBA MAX LogFileSequenceNumber . BlockNumber;  See MOS Note 1031381.6 for further details
    • juliandyke.com© 2013 Julian Dyke53 File Dumps Block Dumps  To dump a database block in Oracle 8.0 or above: ALTER SYSTEM DUMP DATAFILE <absolute_file_number> BLOCK <block_number>; ALTER SYSTEM DUMP DATAFILE <absolute_file_number> BLOCK MIN <minimum_block_number> BLOCK MAX <maximum_block_number>;  To dump a range of database blocks:  To dump a block from a datafile in a closed database: ALTER SYSTEM DUMP DATAFILE '<file_name>' BLOCK <block_number>;
    • juliandyke.com© 2013 Julian Dyke54 Internals
    • juliandyke.com© 2013 Julian Dyke Internals Overview  Oracle dumps often include data. Common data types include  VARCHAR2  CHAR  NUMBER  DATE  ROWID  Oracle dumps also include some common metadata structures including:  SCN  DBA  UBA  RBA  SQLID  Command Types  Unix Time 55
    • juliandyke.com© 2013 Julian Dyke Internals Internal Data Type  Each data type has an internal number  Internal data type numbers appear in many structures and dumps  e.g. bind variables  Examples include: 56 Internal Type Description 1 VARCHAR2, NVARCHAR2 2 NUMBER 8 LONG 12 DATE 23 RAW 24 LONG RAW 58 ANYDATA 69 ROWID 96 CHAR, NCHAR 100 BINARY FLOAT 101 BINARY DOUBLE 111 XMLTYPE Internal Type Description 112 CLOB, NCLOB 113 BLOB 114 BFILE 121 TYPE (User-defined) 122 TYPE (TABLE OF RECORD) 123 TYPE (VARRAY) 180 TIMESTAMP 181 TIMESTAMP WITH TZ 182 INTERVAL YEAR TO MONTH 183 INTERVAL DAY TO SECOND 208 UROWID 231 TIMESTAMP WITH LOCAL TZ
    • juliandyke.com© 2013 Julian Dyke57 Internals Hexadecimal Conversions  To convert from hexadecimal to decimal use TO_NUMBER with the 'XXXX' format mask e.g. SELECT TO_NUMBER (100,'XXX') FROM dual; TO_NUMBER(100,'XXX') -------------------- 256  To convert from decimal to hexadecimal use TO_CHAR with the 'XXXX' format mask e.g. SELECT TO_CHAR (256,'XXX') FROM dual; TO_NUMBER(256,'XXX') -------------------- 100
    • juliandyke.com© 2013 Julian Dyke Internals DUMP Function  Column values can be dumped using the SQL DUMP function  Syntax is: 58 FUNCTION DUMP (expr[,return_format[,start_position[,length]]])  where RETURN_FORMAT is: Format Description 8 Octal Notation 10 Decimal Notation 16 Hexadecimal Notation 17 Single Characters  For example: SELECT DUMP (10000,16) FROM dual; DUMP(10000,16) ----------------- Typ=2 Len=2: c3,2
    • juliandyke.com© 2013 Julian Dyke Internals String Data Types  VARCHAR2 (Internal Type 1)  Stores characters plus length byte(s)  e.g. “Ferrari” in a VARCHAR2(20) 59 Len F e r r a r i 07 46 65 72 72 61 72 69  CHAR (InternalType 96)  Pads data with space characters  e.g. “Ferrari” in a CHAR(20) Len F e r r a r i 07 46 65 72 72 61 72 69 20 20 20 20 20 20 20 20 20 20 20 20 20
    • juliandyke.com© 2013 Julian Dyke Internals NUMBER Data Type  NUMBER (Internal Type 2)  Oracle proprietary number format  Platform independent representation  Designed to ensure numbers collate  Up to 38 bytes can be stored  Numbers are stored as base-100 digits  Each digit is increased by 1 to ensure non-zero  Numbers prefixed by  Sign bit  Exponent 60 Number Value Positive Infinity FF 65 Zero 80 Negative Infinity 01 01 66
    • juliandyke.com© 2013 Julian Dyke Internals NUMBER Data Type  Some examples: 61 Value Internal Representation 0 80 1 C1,02 2 C1,03 3 C1,04 8 C1,09 9 C1,0A 99 C1,64 100 C2,02 101 C2,02,02 102 C2,02,03 999 C2,02,64 1000 C2,0B 1001 C2,0B,2 Value Internal Representation 9999 C2,64,64 10000 C3,02 90000 C3,0A 100000 C3,0B -1 3E,64,66 -2 3E,63,66 -3 3E,62,66 -4 3E,61,66 -99 3E,2,66 -100 3D,64,66 -101 3D,64,64,66 -102 3D,64,63,66 -103 3D,64,62,66
    • juliandyke.com© 2013 Julian Dyke Internals DATE Data Type  DATE (Internal Type 12)  Oracle can store dates ranging from Jan 1, 4712BC to Dec 31 4712AD  Dates are always stored in 7 byte values  Always prefixed by (redundant) length byte  Format is: 62 Byte Value 0 Year / 100 1 Year % 100 2 Month 3 Day 4 Hour 5 Minute 6 Second  For example 26May2013 05:06:38 is Len 0 1 2 3 4 5 6 07 DD 07 05 1A 05 06 26
    • juliandyke.com© 2013 Julian Dyke63 Internals ROWID Data Type  ROWID (Internal Type 69)  Extended ROWIDs were introduced in Oracle 8.0  Use relative file number / block number / slot number  Absolute file number derived from relative file number and tablespace number  Can be accessed using DBMS_ROWID package  Useful functions include:  ROWID_RELATIVE_FNO  ROWID_BLOCK_NUMBER  ROWID_ROW_NUMBER  ROWID_TO_ABSOLUTE_FNO
    • juliandyke.com© 2013 Julian Dyke64 Internals ROWID Data Type  For example: SELECT ROWID, dbms_rowid.rowid_relative_fno (ROWID) AS "File Number", dbms_rowid.rowid_block_number (ROWID) AS "Block Number", dbms_rowid.rowid_row_number (ROWID) AS "Row Number" FROM gp.team; ROWID File Number Block Number Row Number ------------------ ----------- ------------ ---------- AAAR1GAAGAAAAR4AAA 6 1144 0 AAAR1GAAGAAAAR4AAB 6 1144 1 AAAR1GAAGAAAAR4AAC 6 1144 2 AAAR1GAAGAAAAR4AAD 6 1144 3 ......
    • juliandyke.com© 2013 Julian Dyke Internals Database Block Address  Database Block Address (DBA)  Address of block in database  Always 32-bit value  Even on 64 bit platform  SMALLFILE tablespaces (default)  Upper 10 bits represent relative file number  Lower 22 bits represent block number  For example if DBA is 0x01000227 65  BIGFILE tablespaces  All 32 bits represent block number  Some dumps / tools may not report DBA correctly File number = dba >> 22 = 4 Block number = dba & 0x3FFFFF = 551
    • juliandyke.com© 2013 Julian Dyke Internals SQLID  13 character representation of a 64-bit unsigned integer  Uses a mapping of 32 characters to 0..31  Uses the characters 0-9 and a-z with the exception of e, i, l and o  Used in Oracle 10.1 and above to identify SQL parent cursors  Also used to generate database replay file names  5-bit characters in SQL ID map to 8 bit characters in unsigned integer  Right to left  Top bit of left hand word is not used
    • juliandyke.com© 2013 Julian Dyke Internals SQLID Conversion 0 1 2 3 4 5 6 7 00000 00001 00010 00011 00100 00101 00110 00111 8 9 a b c d f g 01000 01001 01010 01011 01100 01101 01110 01111 h j k m n p q r 10000 10001 10010 10011 10100 10101 10110 10111 s t u v w x y z 11000 11001 11010 11011 11100 11101 11110 11111  The following table shows the mapping between characters and byte values:
    • juliandyke.com© 2013 Julian Dyke Internals SQLID Conversion  Example  “6j02q68mxgzt4“ = 0xcdc4598000000001 6 j 0 2 q 6 8 m x g z t 4 00110 10001 00000 00010 10110 00110 01000 10011 11101 01111 11111 11001 00100 01101000 10000000 01010110 00110010 00100111 11010111 11111111 00100100 68 80 56 32 27 d7 ff 24
    • juliandyke.com© 2013 Julian Dyke Internals SQLID Conversion  The following C function converts a 64-bit unsigned integer into a 13- character SQL ID void ConvertLongToSQLID (unsigned long l,char *s) { char *map = "0123456789abcdfghjkmnpqrstuvwxyz"; int i; for (i = 0;i < 13;i++) { unsigned long k = (l >> (60 - i * 5)) & 0x1F; s[i] = map[k]; } s[13] = 0; }
    • juliandyke.com© 2013 Julian Dyke Internals SQLID Conversion  The following C function converts a 13-character SQL ID into a 64-bit unsigned integer void ConvertSQLIDToLong (char *s,unsigned long *l) { char *map = "0123456789abcdfghjkmnpqrstuvwxyz"; unsigned long res = 0; int i,j; for (i = 0;i < 13;i++) { for (j = 0;j < 32;j++) { if (s[i] == map[j]) break; } res = (res << 5) | j; } *l = res; }
    • juliandyke.com© 2013 Julian Dyke Internals Command Types  Command types are listed the SYS.AUDIT_ACTIONS table Name Type ACTION NUMBER NAME VARCHAR2(28)  Common actions include: Action Name 1 CREATE TABLE 2 INSERT 3 SELECT 6 UPDATE 7 DELETE 9 CREATE INDEX 10 DROP INDEX 12 DROP TABLE 17 GRANT OBJECT 19 CREATE SYNONYM
    • juliandyke.com© 2013 Julian Dyke Internals Unix Time  Unix (POSIX) time – time in seconds since the Epoch  Not counting leap seconds  Epoch was midnight on 1st January 1970  To determine current Unix time on Linux: #include <stdio.h> #include <sys/time.h> main () { struct timeval tv; struct timezone tz; gettimeofday (&tv,&tz); printf ("Seconds = %ld (0x%lx)¥n",tv.tv_sec, tv.tv_sec); printf ("MicroSeconds = %ld (0x%lx)¥n",tv.tv_usec,tv.tv_usec); }
    • juliandyke.com© 2013 Julian Dyke73 Operating System Tools
    • juliandyke.com© 2013 Julian Dyke Operating System Tools strings and od  On Unix and Linux useful operating system tools for investigations include:  strings – print ASCII strings in a binary file  default string length is 4 – may miss short strings  use –n parameter to specify shorter minimum length e.g. –n 3  od – dumps blocks from a file in specified format  Formats include:  -c – ASCII characters or backslash escapes  -d – Unsigned decimal 2-byte units  -o – Octal 2 byte units  -x – Hexadecimal 2 byte units 74
    • juliandyke.com© 2013 Julian Dyke75 Operating System Tools tcpdump  Allows packets to be captured and displayed  On busy systems packets can be stored in a file and examined subsequently  Filters can be applied to  Reduce number of packets captured  Increase level of data captured  Promiscuous - network packets between other network interfaces can be captured  Based on libpcap  Similar to snoop on Solaris  Useful for investigating  RAC interconnect traffic  Oracle Streams packets
    • juliandyke.com© 2013 Julian Dyke76 Custom Tools
    • juliandyke.com© 2013 Julian Dyke Custom Tools  If no suitable tools exist you can always develop your own….  C is the best language for most tools  Oracle is developed in C  Structures align better in C  Avoids unnecessary indirection  GNU compilers are usually available  Ensure development platform is:  Same architecture as target e.g. x86-64, SPARC, Itanium  Same word size e.g. 32 or 64 bit  Ensure correct compiler switches are specified  Word size  Word alignment 77
    • juliandyke.com© 2013 Julian Dyke Custom Tools  RedoAnalyzer  Analyses online redo log / archive redo log  Summarizes redo generation by:  undo / redo  object  operation  Version specific  Usually requires porting for different platforms  LogMiner provides similar functionality  LogMiner has high memory requirements  RedoAnalyzer is less-intrusive  RedoAnalyzer is faster 78
    • juliandyke.com© 2013 Julian Dyke Custom Tools  Block Dumper  Dumps database blocks  Similar output format to ALTER SYSTEM DUMP command  Can be adapted  For example non-intrusive analysis of chaining and migration  SGA Attach  Attaches to shared memory  Follows memory pointers from fixed SGA  Dumps blocks of memory  Dumps sessions, processes, parent and child cursors etc  Dumps RAC structures  Useful for research and for identifying bugs 79
    • juliandyke.com© 2013 Julian Dyke Custom Tools  TCP Dump  Based on libpmap  Intercepts and dumps messages  Useful for  Clusterware / RAC research  Oracle Streams research  IO Performance  Reads random blocks from large files  Measures I/O rates  Fine grained  Allows I/O rate to be calculated for  buffered I/O  SAN cache  SAN disk 80
    • juliandyke.com© 2013 Julian Dyke Custom Tools  ReplayAnalyzer  Extracts contents of database replay files (record and workload metadata)  Writes output in pseudo-XML format  Useful for understanding  database capture – what is captured and what is omitted  database replay – what can be replayed  TrailAnalyzer  Dumps contents of Oracle GoldenGate trail  Very similar to Oracle GoldenGate logdump utility 81
    • juliandyke.com© 2013 Julian Dyke82 Thank you for listening info@juliandyke.com
    • juliandyke.com© 2013 Julian Dyke83 Backup
    • juliandyke.com© 2013 Julian Dyke84 Execution Plans AUTOTRACE  Statistics reported are: Statistic Name recursive calls db block gets consistent gets physical reads redo size bytes sent via SQL*Net to client bytes received via SQL*Net from client SQL*Net roundtrips to/from client sorts(memory) sorts(disk) rows processed
    • juliandyke.com© 2013 Julian Dyke85 Execution Plans AUTOTRACE  In Oracle 9.2 and below execution plan consists of four columns: Column Name Description ID_PLUS_EXP ID of execution step PARENT_ID_PLUS_EXP Parent ID of execution step PLAN_PLUS_EXP Execution step OBJECT_NODE_PLUS_EXP Database links or parallel query servers  Output can optionally be suppressed e.g.: COLUMN PARENT_ID_PLUS_EXP NOPRINT  For parallel and remote operations additional information is displayed in another section: Column Name Description OTHER_PLUS_EXP Shows the SQL query OTHER_TAG_PLUS_EXP Shows reason for OTHER_PLUS_EXP
    • juliandyke.com© 2013 Julian Dyke86 Parameters Parameter Types  Parameter types are reported numerically in  V$PARAMETER.TYPE  X$KSPPI.KSPPITY  Values are: Value Description 1 Boolean 2 String 3 Integer 4 File 6 Big Integer
    • juliandyke.com© 2013 Julian Dyke87 Parameters Optimizer Parameters  Optimizer parameters are grouped in FID_QKSCESYROW  For example in Oracle 11.1 FID_QKSCESYROW COUNT(*) QKSFM_ALL 101 QKSFM_CBO 71 QKSFM_CVM 1 QKSFM_EXECUTION 1 QKSFM_FBA 1 QKSFM_INDEX 1 QKSFM_JPPD 3 QKSFM_OR_EXPAND 1 QKSFM_PQ 6 QKSFM_STAR_TRANS 3 QKSFM_TRANSFORMATION 70