Thursday, March 15, 2012

Oracle hidden utilities undocumented parameters

Each new release of Oracle brings new hidden utilities. They are sometimes used by internal Oracle development staff and left in Oracle for emergency support. Many of these undocumented utilities are very powerful but can be complex.
A hidden utility is not a utility that is physically hidden in the Oracle software. Rather, a hidden utility is an executable or PL/SQL package that is either undocumented or where the documentation is difficult to find. For example, some PL/SQL packages are never loaded by the Oracle installer, yet their definitions remain in the operating system files.
The main directories of interest regarding Oracle utilities are the following:
  • $ORACLE_HOME/bin -- This contains the binary executables used by the Oracle server. Most of the tools discussed in this book reside here.
  • $ORACLE_HOME/plsql/demo -- This contains a useful collection of SQL scripts related to many utilities, including dbms_profiler.
  • $ORACLE_HOME/rdbms/admin -- This contains many SQL scripts used for creating PL/SQL packages and their required environments.
  • $ORACLE_HOME/sqlplus/admin -- This contains scripts used with autotrace and other utilities.
  • $ORACLE_HOME/otrace/admin -- This is the administration directory for the Oracle Trace diagnostic tool.
  • $ORACLE_HOME/otrace/sysman -- This is used by utilities such as oemctl and the Oracle Management Server (OMS).
  • $ORACLE_HOME/otrace/lib -- This contains facility files used with the oerr utility.
Many of these undocumented utilities such as TKPROF have surfaced from the obscure and entered mainstream Oracle toolkits while others remain hidden inside the O/S.

Finding hidden utilities

The easiest way to find hidden utilities is to look for new packages within Oracle. The following query compares the packages in Oracle8i with new packages in Oracle9i, using a database link:
select 
   object_name 
from 
   dba_objects@oracle9i 
where 
   owner      = 'SYS' 
and 
   object_type = 'PACKAGE BODY' 
minus
select 
   object_name 
from  
   dba_objects@oracle8i
where 
   owner     = 'SYS'
and 
   object_type = 'PACKAGE BODY';
This query will quickly display all package bodies owned by SYS that exist in Oracle9i but not in Oracle8i.

Finding hidden executables

Discovering new binaries entails comparing two directories in the operating system and ignoring the duplicates entries. The dircmp UNIX command can be used to find only new entries within two directories:

dircmp -- s 
/u01/aoracle/product/8.1.7/bin 
/u01/oracle/product/9.0.3/bin
Here we compare the bin directory of 8.1.7 with Oracle 9.0.2. Note that the -- s option of the dircmp command tells UNIX to eliminate the matches from the output.

Hidden initialization parameters

Hidden initialization parameters are very dangerous because their use is undocumented, but they can be very valuable if you are careful. We can use a SQL*Plus query to quickly find any new initialization parameters in a new version of Oracle:
select 
   name
from 
    v$parameter@oracle9i 
minus 
select 
   name
from 
   v$parameter@oracle8i
; 
Every version of Oracle has special undocumented initialization parameters. These undocumented initialization parameters are usually only used in emergencies and only under the direction of a senior DBA or Oracle support. Because the undocumented parameters begin with an underscore "_", we can write a query against the X$ foxed tables to easily extract them:
COLUMN parameter           FORMAT a37
COLUMN description         FORMAT a30 WORD_WRAPPED
COLUMN "Session Value"     FORMAT a10
COLUMN "Instance Value"    FORMAT a10
SET LINES 100
SET PAGES 0
SPOOL undoc.lis

SELECT  
   a.ksppinm  "Parameter",  
   a.ksppdesc "Description", 
   b.ksppstvl "Session Value",
   c.ksppstvl "Instance Value"
FROM 
   x$ksppi a, 
   x$ksppcv b, 
   x$ksppsv c
WHERE 
   a.indx = b.indx 
   AND 
   a.indx = c.indx
   AND 
   a.ksppinm LIKE '/_%' escape '/'
/
Remember, not everyone knows about the undocumented parameters, and few know how or when to use them. Oracle does not allow DBAs to use many of these parameters unless specifically directed by Oracle support. DBAs should be aware that use of certain undocumented parameters will result in an unsupported system.
In many cases, the undocumented parameters were either documented in previous releases or will be in future releases. Of course, it is difficult to use the undocumented parameters that have never been documented, and never will be, safely. When in doubt, get guidance from Oracle support. We will take a closer look at some of these parameters in our next installment.

Hidden v$ views

New V$ views indicate a new functionality within the database, and not all of the views make it into the Oracle documentation. Here is a quick query to locate new views:
select 
   view_name
from 
    v$fixed_view_description@oracle9i 
minus 
select 
   view_name
from 
   v$fixed_view_description@oracle8i
; 

Hidden system events

With each new release of Oracle, system events and system statistics are changed. For example, here is a query to show changed system statistics for the database writer process between Oracle8i and Oracle9i:
sql> select distinct name from v$sysstat where name like 'DBWR%'

NAME
----------------------------------------------------------------
DBWR Flush object call found no dirty buffers
DBWR Flush object cross instance calls
DBWR buffers scanned
DBWR checkpoint buffers written
DBWR checkpoint write requests
DBWR checkpoints
DBWR cross instance writes
DBWR free buffers found
DBWR incr. ckpt. write requests
DBWR lru scans
DBWR make free requests
DBWR revisited being-written buffer
DBWR skip hot writes
DBWR summed scan depth
DBWR timeouts
DBWR transaction table writes
DBWR undo block writes
Here is the listing from Oracle9i.  Note the changed statistics.
SQL> select distinct name from v$sysstat where name like 'DBWR%';

NAME
----------------------------------------------------------------
DBWR buffers scanned
DBWR checkpoint buffers written
DBWR checkpoints
DBWR cross instance writes
DBWR free buffers found
DBWR fusion writes
DBWR lru scans
DBWR make free requests
DBWR revisited being-written buffer
DBWR summed scan depth
DBWR transaction table writes
DBWR undo block writes
By the same token, we van use the v $event_name view to quickly locate all new system events in Oracle19i.  Here is a quick query to locate new views:
select 
   name
from 
    v$event_name@oracle9i 
minus 
select 
   name
from 
   v$event_name@oracle8i
; 

Undocumented SQL hints

Getting a list of Oracle hints for SQL tuning is often difficult. The Oracle hint list is inside the Oracle executable and you can extract the Oracle hint list easily with UNIX commands. In UNIX, you can use grep and strings to get them directly from the Oracle executable:
   strings $ORACLE_HOME/bin/oracle > hints.lst
Here are all of the 124 Oracle9i hints on release 9.0.2:
ALL_ROWSAND_EQUALANTIJOIN
APPENDBITMAPBUFFER
BYPASS_RECURSIVE_CHECKBYPASS_UJVCCACHE
CACHE_CBCACHE_TEMP_TABLECARDINALITY
CHOOSECIV_GBCOLLECTIONS_GET_REFS
CPU_COSTINGCUBE_GBCURSOR_SHARING_EXACT
DEREF_NO_REWRITEDML_UPDATEDOMAIN_INDEX_NO_SORT
DOMAIN_INDEX_SORTDRIVING_SITEDYNAMIC_SAMPLING
DYNAMIC_SAMPLING_EST_CDNEXPAND_GSET_TO_UNIONFACT
FIRST_ROWSFORCE_SAMPLE_BLOCKFULL
GBY_CONC_ROLLUPGLOBAL_TABLE_HINTSHASH
HASH_AJHASH_SJHWM_BROKERED
IGNORE_ON_CLAUSEIGNORE_WHERE_CLAUSEINDEX_ASC
INDEX_COMBINEINDEX_DESCINDEX_FFS
INDEX_JOININDEX_RRSINDEX_SS
INDEX_SS_ASCINDEX_SS_DESCINLINE
LEADINGLIKE_EXPANDLOCAL_INDEXES
MATERIALIZEMERGEMERGE_AJ
MERGE_SJMV_MERGENESTED_TABLE_GET_REFS
NESTED_TABLE_SET_REFSNESTED_TABLE_SET_SETIDNL_AJ
NL_SJNO_ACCESSNO_BUFFER
NO_EXPANDNO_EXPAND_GSET_TO_UNIONNO_FACT
NO_FILTERINGNO_INDEXNO_MERGE
NO_MONITORINGNO_ORDER_ROLLUPSNO_PRUNE_GSETS
NO_PUSH_PREDNO_PUSH_SUBQNO_QKN_BUFF
NO_SEMIJOINNO_STATS_GSETSNO_UNNEST
NOAPPENDNOCACHENOCPU_COSTING
NOPARALLELNOPARALLEL_INDEXNOREWRITE
OR_EXPANDORDEREDORDERED_PREDICATES
OVERFLOW_NOMOVEPARALLELPARALLEL_INDEX
PIV_GBPIV_SSFPQ_DISTRIBUTE
PQ_MAPPQ_NOMAPPUSH_PRED
PUSH_SUBQREMOTE_MAPPEDRESTORE_AS_INTERVALS
REWRITERULESAVE_AS_INTERVALS
SCN_ASCENDINGSELECTIVITYSEMIJOIN
SEMIJOIN_DRIVERSKIP_EXT_OPTIMIZERSQLLDR
STARSTAR_TRANSFORMATIONSWAP_JOIN_INPUTS
SYS_DL_CURSORSYS_PARALLEL_TXNSYS_RID_ORDER
TIV_GBTIV_SSFUNNEST
USE_ANTIUSE_CONCATUSE_HASH
USE_MERGEUSE_NLUSE_SEMI
USE_TTT_FOR_GSETS
In this output we see 57 undocumented SQL hints:
BYPASS_RECURSIVE_CHECKBYPASS_UJVCCACHE_CB
CACHE_TEMP_TABLECIV_GBCOLLECTIONS_GET_REFS
CUBE_GBCURSOR_SHARING_EXACTDEREF_NO_REWRITE
DML_UPDATEDOMAIN_INDEX_NO_SORTDOMAIN_INDEX_SORT
DYNAMIC_SAMPLINGDYNAMIC_SAMPLING_EST_CDNEXPAND_GSET_TO_UNION
FORCE_SAMPLE_BLOCKGBY_CONC_ROLLUPGLOBAL_TABLE_HINTS
HWM_BROKEREDIGNORE_ON_CLAUSEIGNORE_WHERE_CLAUSE
INDEX_RRSINDEX_SSINDEX_SS_ASC
INDEX_SS_DESCLIKE_EXPANDLOCAL_INDEXES
MV_MERGENESTED_TABLE_GET_REFSNESTED_TABLE_SET_REFS
NESTED_TABLE_SET_SETIDNO_EXPAND_GSET_TO_UNIONNO_FACT
NO_FILTERINGNO_ORDER_ROLLUPSNO_PRUNE_GSETS
NO_STATS_GSETSNO_UNNESTNOCPU_COSTING
OVERFLOW_NOMOVEPIV_GBPIV_SSF
PQ_MAPPQ_NOMAPREMOTE_MAPPED
RESTORE_AS_INTERVALSSAVE_AS_INTERVALSSCN_ASCENDING
SKIP_EXT_OPTIMIZERSQLLDRSYS_DL_CURSOR
SYS_PARALLEL_TXNSYS_RID_ORDERTIV_GB
TIV_SSFUNNESTUSE_TTT_FOR_GSETS
These Oracle SQL hints can be extremely useful for solving complex SQL execution problems, and that is why Oracle created them. They generally remain undocumented because Oracle does not want someone with inadequate knowledge of optimizer internals using them because they could lead to confusing results. However, for the experienced SQL tuning professional these undocumented hints are a godsend.

Conclusion

In this first installment we have shown you how to extract powerful (but potentially dangerous) undocumented utilities, parameters, hints, packages and executables. Remember, many of these undocumented features have unknown effects and should be treated with great care.

No comments:

Post a Comment

Oracle Escape Characters

Oracle allows the assignment of special escape characters to tell Oracle that the character is interpreted literally.  Certain characters ...