<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-27939696</id><updated>2024-08-29T08:32:19.912+02:00</updated><title type='text'>Christoph Bohl&#39;s Oracle Blog</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://cbohl.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/27939696/posts/default?alt=atom'/><link rel='alternate' type='text/html' href='http://cbohl.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/27939696/posts/default?alt=atom&amp;start-index=26&amp;max-results=25'/><author><name>Christoph Bohl</name><uri>http://www.blogger.com/profile/13659990813733751317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>48</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-27939696.post-6612308435332938857</id><published>2013-03-11T13:42:00.000+01:00</published><updated>2013-03-11T13:42:29.453+01:00</updated><title type='text'>How To Set Database To Noarchivelog</title><content type='html'>Login to sqlplus
&lt;pre class=&quot;sql&quot; name=&quot;code&quot;&gt;
# sqlplus /nolog
SQL&amp;gt; connect / as sysdba
&lt;/pre&gt;
The db must be mounted EXCLUSIVE and not open for operation
&lt;pre class=&quot;sql&quot; name=&quot;code&quot;&gt;
SQL&gt; shutdown immediate;
SQL&amp;gt; startup mount;
&lt;/pre&gt;
Check the log mode of the database
&lt;pre class=&quot;sql&quot; name=&quot;code&quot;&gt;
SQL&gt; select log_mode from v$database;
&lt;/pre&gt;
Set it to noarchivelog mode
&lt;pre class=&quot;sql&quot; name=&quot;code&quot;&gt;
SQL&gt; alter database noarchivelog;
&lt;/pre&gt;
Set db open for user operation
&lt;pre class=&quot;sql&quot; name=&quot;code&quot;&gt;
SQL&gt; alter database open;
&lt;/pre&gt;
</content><link rel='replies' type='application/atom+xml' href='http://cbohl.blogspot.com/feeds/6612308435332938857/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/27939696/6612308435332938857' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/27939696/posts/default/6612308435332938857'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/27939696/posts/default/6612308435332938857'/><link rel='alternate' type='text/html' href='http://cbohl.blogspot.com/2013/03/how-to-set-database-to-noarchivelog.html' title='How To Set Database To Noarchivelog'/><author><name>Christoph Bohl</name><uri>http://www.blogger.com/profile/13659990813733751317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-27939696.post-5734032242312149896</id><published>2013-01-17T12:18:00.000+01:00</published><updated>2013-01-17T12:18:16.081+01:00</updated><title type='text'>Activate and De-Activate Granted Roles</title><content type='html'>Check the roles that are enabled in your session:

&lt;pre class=&quot;sql&quot; name=&quot;code&quot;&gt;
select * from session_roles;
&lt;/pre&gt;

Using the command SET ROLE you can set only specific roles to active.

Set all active:
&lt;pre class=&quot;sql&quot; name=&quot;code&quot;&gt;
set role all;
&lt;/pre&gt;

Disable specific roles:
&lt;pre class=&quot;sql&quot; name=&quot;code&quot;&gt;
set role all except role1, role2;
&lt;/pre&gt;

</content><link rel='replies' type='application/atom+xml' href='http://cbohl.blogspot.com/feeds/5734032242312149896/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/27939696/5734032242312149896' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/27939696/posts/default/5734032242312149896'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/27939696/posts/default/5734032242312149896'/><link rel='alternate' type='text/html' href='http://cbohl.blogspot.com/2013/01/activate-and-de-activate-granted-roles.html' title='Activate and De-Activate Granted Roles'/><author><name>Christoph Bohl</name><uri>http://www.blogger.com/profile/13659990813733751317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-27939696.post-5337319533153981170</id><published>2012-11-15T07:10:00.000+01:00</published><updated>2012-11-15T07:10:21.971+01:00</updated><title type='text'>Datapump: Re-Importing TYPEs</title><content type='html'>When duplicating a schema which contains TYPE objects using expdp/impdp, you will encounter the following error:
&lt;pre&gt;
Processing object type SCHEMA_EXPORT/TYPE/TYPE_SPEC
ORA-39083: Object type TYPE failed to create with error:
ORA-02304: invalid object identifier literal
&lt;/pre&gt;

This is because Oracle tries to create the type object in the target schema with the same object identifier (OID) as it has in the source schema. But an OID must be unique within a database.&lt;BR&gt;&lt;BR&gt;

Add the following parameter to your impdp command to make sure new OIDs are generated upon import:
&lt;pre&gt;
transform=oid:n
&lt;/pre&gt;

Since: Oracle 10gR2&lt;BR&gt;
Source: Oracle Support Doc ID 351519.1
</content><link rel='replies' type='application/atom+xml' href='http://cbohl.blogspot.com/feeds/5337319533153981170/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/27939696/5337319533153981170' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/27939696/posts/default/5337319533153981170'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/27939696/posts/default/5337319533153981170'/><link rel='alternate' type='text/html' href='http://cbohl.blogspot.com/2012/11/datapump-re-importing-types.html' title='Datapump: Re-Importing TYPEs'/><author><name>Christoph Bohl</name><uri>http://www.blogger.com/profile/13659990813733751317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-27939696.post-3044515818090710681</id><published>2012-11-14T13:21:00.001+01:00</published><updated>2012-11-14T13:21:39.665+01:00</updated><title type='text'>Stop Datapump Job Using PL/SQL API</title><content type='html'>Check the status of all current datapump jobs:
&lt;pre name=&quot;code&quot; class=&quot;sql&quot;&gt;
select *
from   dba_datapump_jobs
;
&lt;/pre&gt;

Using the PL/SQL API, attach to the job and stop it:
&lt;pre name=&quot;code&quot; class=&quot;sql&quot;&gt;
set serveroutput on
set lines 100
--/
declare
   handle number;
begin
  -- format: dbms_datapump.attach(&#39;&lt;job_name&gt;&#39;,&#39;&lt;owner_name&gt;&#39;);
   handle := dbms_datapump.attach(&#39;SYS_IMPORT_SCHEMA_01&#39;,&#39;SYS&#39;);
   dbms_datapump.stop_job (handle,1,0);
end;
/
&lt;/pre&gt;

In a previous post, I showed how to achieve this with the command line utility: &lt;a href=&quot;http://cbohl.blogspot.ch/2010/11/killing-datapump-job.html&quot;&gt;killing a datapump job&lt;/a&gt;.</content><link rel='replies' type='application/atom+xml' href='http://cbohl.blogspot.com/feeds/3044515818090710681/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/27939696/3044515818090710681' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/27939696/posts/default/3044515818090710681'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/27939696/posts/default/3044515818090710681'/><link rel='alternate' type='text/html' href='http://cbohl.blogspot.com/2012/11/stop-datapump-job-using-plsql-api.html' title='Stop Datapump Job Using PL/SQL API'/><author><name>Christoph Bohl</name><uri>http://www.blogger.com/profile/13659990813733751317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-27939696.post-668171018043702597</id><published>2012-11-13T12:50:00.000+01:00</published><updated>2012-11-13T12:50:04.667+01:00</updated><title type='text'>Column Dependencies</title><content type='html'>When looking for information about column dependencies, I stumbled over this article: &lt;a href=&quot;http://rwijk.blogspot.ch/2008/10/dbadependencycolumns.html&quot;&gt;DBA_DEPENDENCY_COLUMNS&lt;/a&gt;.

The script below is copied from this source and made available here for easier copying :-)

If you run it as sysdba, you&#39;ll have a new view DBA_DEPENDENCY_COLUMS. Requires Oracle 11g.

&lt;pre class=&quot;sql&quot; name=&quot;code&quot;&gt;
create view dba_dependency_columns as
select d.u_name                                        owner
   , d.o_name                                          name
   , decode  
     ( d.o_type#  
     , 0, &#39;NEXT OBJECT&#39;, 1, &#39;INDEX&#39;, 2, &#39;TABLE&#39;, 3, &#39;CLUSTER&#39;  
     , 4, &#39;VIEW&#39;, 5, &#39;SYNONYM&#39;, 6, &#39;SEQUENCE&#39;, 7, &#39;PROCEDURE&#39;  
     , 8, &#39;FUNCTION&#39;, 9, &#39;PACKAGE&#39;, 10, &#39;NON-EXISTENT&#39; 
      , 11, &#39;PACKAGE BODY&#39;, 12, &#39;TRIGGER&#39; 
      , 13, &#39;TYPE&#39;, 14, &#39;TYPE BODY&#39;, 22, &#39;LIBRARY&#39; 
      , 28, &#39;JAVA SOURCE&#39;, 29, &#39;JAVA CLASS&#39; 
      , 32, &#39;INDEXTYPE&#39;, 33, &#39;OPERATOR&#39; 
      , 42, &#39;MATERIALIZED VIEW&#39;, 43, &#39;DIMENSION&#39; 
      , 46, &#39;RULE SET&#39;, 55, &#39;XML SCHEMA&#39;, 56, &#39;JAVA DATA&#39; 
      , 59, &#39;RULE&#39;, 62, &#39;EVALUATION CONTXT&#39; 
      , 92, &#39;CUBE DIMENSION&#39;, 93, &#39;CUBE&#39; 
      , 94, &#39;MEASURE FOLDER&#39;, 95, &#39;CUBE BUILD PROCESS&#39; 
      , &#39;UNDEFINED&#39; 
      )                                                 type 
    , nvl2( d.po_linkname, d.po_remoteowner, d.pu_name) referenced_owner 
    , d.po_name                                         referenced_name 
    , decode 
      ( d.po_type# 
      , 0, &#39;NEXT OBJECT&#39;, 1, &#39;INDEX&#39;, 2, &#39;TABLE&#39;, 3, &#39;CLUSTER&#39; 
      , 4, &#39;VIEW&#39;, 5, &#39;SYNONYM&#39;, 6, &#39;SEQUENCE&#39;, 7, &#39;PROCEDURE&#39; 
      , 8, &#39;FUNCTION&#39;, 9, &#39;PACKAGE&#39;, 10, &#39;NON-EXISTENT&#39; 
      , 11, &#39;PACKAGE BODY&#39;, 12, &#39;TRIGGER&#39; 
      , 13, &#39;TYPE&#39;, 14, &#39;TYPE BODY&#39;, 22, &#39;LIBRARY&#39; 
      , 28, &#39;JAVA SOURCE&#39;, 29, &#39;JAVA CLASS&#39; 
      , 32, &#39;INDEXTYPE&#39;, 33, &#39;OPERATOR&#39; 
      , 42, &#39;MATERIALIZED VIEW&#39;, 43, &#39;DIMENSION&#39; 
      , 46, &#39;RULE SET&#39;, 55, &#39;XML SCHEMA&#39;, 56, &#39;JAVA DATA&#39; 
      , 59, &#39;RULE&#39;, 62, &#39;EVALUATION CONTXT&#39; 
      , 92, &#39;CUBE DIMENSION&#39;, 93, &#39;CUBE&#39; 
      , 94, &#39;MEASURE FOLDER&#39;, 95, &#39;CUBE BUILD PROCESS&#39; 
      , &#39;UNDEFINED&#39; 
      )                                                 referenced_type 
    , d.po_linkname                                     referenced_link_name 
    , c.name                                            referenced_column 
    , decode(bitand(d.d_property, 3), 2, &#39;REF&#39;, &#39;HARD&#39;) dependency_type 
 from ( select obj# 
             , u_name 
             , o_name 
             , o_type# 
             , pu_name 
             , po_name 
             , po_type# 
             , po_remoteowner 
             , po_linkname 
             , d_property 
             , colpos 
          from sys.&quot;_CURRENT_EDITION_OBJ&quot; o 
             , sys.disk_and_fixed_objects po 
             , sys.dependency$ d 
             , sys.user$ u 
             , sys.user$ pu 
         where o.obj# = d.d_obj# 
           and o.owner# = u.user# 
           and po.obj# = d.p_obj# 
           and po.owner# = pu.user# 
           and d.d_attrs is not null 
         model 
               return updated rows 
               partition by 
               ( po.obj#        obj# 
               , u.name         u_name 
               , o.name         o_name 
               , o.type#        o_type# 
               , po.linkname    po_linkname 
               , pu.name        pu_name 
               , po.remoteowner po_remoteowner 
               , po.name        po_name 
               , po.type#       po_type# 
               , d.property     d_property 
               ) 
               dimension by (0 i) 
               measures (0 colpos, substr(d.d_attrs,9) attrs) 
               rules iterate (1000) 
                     until (iteration_number = 4 * length(attrs[0]) - 2) 
               ( colpos[iteration_number+1] 
                 = case bitand 
                        ( to_number 
                          ( substr 
                            ( attrs[0] 
                            , 1 + 2*trunc((iteration_number+1)/8) 
                            , 2 
                            ) 
                          ,&#39;XX&#39; 
                          ) 
                        , power(2,mod(iteration_number+1,8)) 
                        ) 
                   when 0 then null 
                   else iteration_number+1 
                   end 
               ) 
      ) d 
    , sys.col$ c 
where d.obj# = c.obj#
   and d.colpos = c.col#
;

grant select on dba_dependency_columns to select_catalog_role
;

create public synonym dba_dependency_columns for dba_dependency_columns
;
&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://cbohl.blogspot.com/feeds/668171018043702597/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/27939696/668171018043702597' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/27939696/posts/default/668171018043702597'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/27939696/posts/default/668171018043702597'/><link rel='alternate' type='text/html' href='http://cbohl.blogspot.com/2012/11/column-dependencies.html' title='Column Dependencies'/><author><name>Christoph Bohl</name><uri>http://www.blogger.com/profile/13659990813733751317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-27939696.post-7236783783070737302</id><published>2012-11-09T09:35:00.001+01:00</published><updated>2012-11-09T09:35:59.742+01:00</updated><title type='text'>Check Installed Features And Options</title><content type='html'>To see a list of installed features and their status:
&lt;pre class=&quot;sql&quot; name=&quot;code&quot;&gt;
select *
from   dba_registry
order by comp_name
;
&lt;/pre&gt;
To see which options are available:
&lt;pre class=&quot;sql&quot; name=&quot;code&quot;&gt;
select * 
from   v$option
order by parameter
;
&lt;/pre&gt;
</content><link rel='replies' type='application/atom+xml' href='http://cbohl.blogspot.com/feeds/7236783783070737302/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/27939696/7236783783070737302' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/27939696/posts/default/7236783783070737302'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/27939696/posts/default/7236783783070737302'/><link rel='alternate' type='text/html' href='http://cbohl.blogspot.com/2012/11/check-installed-features-and-options.html' title='Check Installed Features And Options'/><author><name>Christoph Bohl</name><uri>http://www.blogger.com/profile/13659990813733751317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-27939696.post-5832903333956397328</id><published>2012-11-08T07:34:00.000+01:00</published><updated>2012-11-08T07:34:21.143+01:00</updated><title type='text'>Check Default Tablespaces</title><content type='html'>Check default tablespaces of the database:
&lt;pre class=&quot;sql&quot; name=&quot;code&quot;&gt;
select * 
from   database_properties
where  property_name like &#39;%TABLESPACE&#39;
order by property_name
;
&lt;/pre&gt;
And the users:
&lt;pre class=&quot;sql&quot; name=&quot;code&quot;&gt;
select username
,      default_tablespace
,      temporary_tablespace
from   dba_users
order by username
;
&lt;/pre&gt;
</content><link rel='replies' type='application/atom+xml' href='http://cbohl.blogspot.com/feeds/5832903333956397328/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/27939696/5832903333956397328' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/27939696/posts/default/5832903333956397328'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/27939696/posts/default/5832903333956397328'/><link rel='alternate' type='text/html' href='http://cbohl.blogspot.com/2012/11/check-default-tablespaces.html' title='Check Default Tablespaces'/><author><name>Christoph Bohl</name><uri>http://www.blogger.com/profile/13659990813733751317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-27939696.post-8318306397545750252</id><published>2012-11-01T11:11:00.001+01:00</published><updated>2012-11-01T11:11:26.630+01:00</updated><title type='text'>VARCHAR2 column length in a Multi Byte Characterset Database</title><content type='html'>When migrating data from a single-byte characterset database into a multi-byte characterset database, you will very likely encounter problems with column lenghts.
&lt;BR&gt;&lt;BR&gt;
Oracle uses by default BYTE length sematics for VARCHAR2 columns.
&lt;BR&gt;&lt;BR&gt;
As many characters need more than one byte in a multi-byte characterset database, the field lengths in BYTE will not be sufficient in many cases.
&lt;BR&gt;&lt;BR&gt;
It will therefore be preferable in most cases to use CHAR length semantics in your multi-byte characterset database. This can be configured either on system or session level:

&lt;pre class=&quot;sql&quot; name=&quot;code&quot;&gt;
ALTER SYSTEM SET NLS_LENGTH_SEMANTICS=CHAR;
ALTER SESSION SET NLS_LENGTH_SEMANTICS=CHAR;
&lt;/pre&gt;

This way, you do not have to specify CHAR in each and every VARCHAR2 column definition.</content><link rel='replies' type='application/atom+xml' href='http://cbohl.blogspot.com/feeds/8318306397545750252/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/27939696/8318306397545750252' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/27939696/posts/default/8318306397545750252'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/27939696/posts/default/8318306397545750252'/><link rel='alternate' type='text/html' href='http://cbohl.blogspot.com/2012/11/varchar2-column-length-in-multi-byte.html' title='VARCHAR2 column length in a Multi Byte Characterset Database'/><author><name>Christoph Bohl</name><uri>http://www.blogger.com/profile/13659990813733751317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-27939696.post-3853909854655353042</id><published>2012-08-07T15:05:00.000+02:00</published><updated>2012-08-07T15:05:18.452+02:00</updated><title type='text'>SQL Monitoring in 11g</title><content type='html'>With Oracle 11g, especially R2, Oracle is making it very easy to get an overview of the SQL statements (both running and finished) and how they perform.

See all cursors:

&lt;pre class=&quot;sql&quot; name=&quot;code&quot;&gt;select dbms_sqltune.report_sql_monitor_list(type=&gt;&#39;HTML&#39;, report_level=&gt;&#39;ALL&#39;) from dual;
&lt;/pre&gt;

Show detailed information for any given SQL ID:

&lt;pre class=&quot;sql&quot; name=&quot;code&quot;&gt;select dbms_sqltune.report_sql_monitor(type=&gt;&#39;ACTIVE&#39;, sql_id=&gt;&#39;SQL ID&#39;) monitor_report from dual;
&lt;/pre&gt;

There are many options available, such as reporting on the last statement executed in the session, etc.

&lt;pre class=&quot;sql&quot; name=&quot;code&quot;&gt;select dbms_sqltune.report_sql_monitor(type=&gt;&#39;ACTIVE&#39;) monitor_report from dual;

--set echo off timing off pagesize 0 linesize 1000 trimspool on trim on
--set long 2000000 longchunksize 2000000
select dbms_sqltune.report_sql_monitor
       (session_id=&gt;sys_context(&#39;userenv&#39;,&#39;sid&#39;)
       ,session_serial=&gt;dbms_debug_jdwp.current_session_serial
       ,report_level=&gt;&#39;ALL&#39;
       ,type=&gt;&#39;TEXT&#39;
       ) as monitor_report
from   dual
;
&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://cbohl.blogspot.com/feeds/3853909854655353042/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/27939696/3853909854655353042' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/27939696/posts/default/3853909854655353042'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/27939696/posts/default/3853909854655353042'/><link rel='alternate' type='text/html' href='http://cbohl.blogspot.com/2012/08/sql-monitoring-in-11g.html' title='SQL Monitoring in 11g'/><author><name>Christoph Bohl</name><uri>http://www.blogger.com/profile/13659990813733751317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-27939696.post-1577020804032016432</id><published>2012-06-12T00:24:00.000+02:00</published><updated>2012-06-12T00:24:03.776+02:00</updated><title type='text'>Oracle Exadata Database Machine Tutorials</title><content type='html'>Our education partner, &lt;a href=&quot;http://www.skillbuilders.com/&quot; target=&quot;_blank&quot;&gt;Skillbuilders&lt;/a&gt;, is&lt;span style=&quot;background-color: white; font-family: Arial, Helvetica, sans-serif; font-size: 10pt; text-align: left;&quot;&gt;&amp;nbsp;pleased to announce that their first series of&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: Arial, Helvetica, sans-serif; font-size: 10pt; text-align: left;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;http://www.skillbuilders.com/Oracle/Oracle-Consulting-Training.cfm?tab=exadata-tutorials&quot; shape=&quot;rect&quot; style=&quot;background-color: white; color: blue; font-family: Arial, Helvetica, sans-serif; font-size: 10pt; text-align: left;&quot; target=&quot;_blank&quot;&gt;Oracle Exadata Tutorials&lt;/a&gt;&lt;span style=&quot;background-color: white; font-family: Arial, Helvetica, sans-serif; font-size: 10pt; text-align: left;&quot;&gt;&amp;nbsp;are now available. The series consists of the following eleven sessions, all delivered by SkillBuilders Oracle Certified Master&lt;/span&gt;&lt;span style=&quot;background-color: white; font-family: Arial, Helvetica, sans-serif; font-size: 10pt; text-align: left;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;http://www.skillbuilders.com/our-instructors/john-watson.cfm&quot; shape=&quot;rect&quot; style=&quot;background-color: white; color: blue; font-family: Arial, Helvetica, sans-serif; font-size: 10pt; text-align: left;&quot; target=&quot;_blank&quot;&gt;John Watson&lt;/a&gt;&lt;span style=&quot;background-color: white; font-family: Arial, Helvetica, sans-serif; font-size: 10pt; text-align: left;&quot;&gt;:&lt;/span&gt;&lt;br /&gt;
&lt;ul style=&quot;background-color: white; font-family: Arial, Helvetica, sans-serif; font-size: 19px; text-align: left;&quot;&gt;
&lt;li style=&quot;font-size: 9pt; margin-left: 15px;&quot;&gt;About the Exadata Hardware&lt;/li&gt;
&lt;li style=&quot;font-size: 9pt; margin-left: 15px;&quot;&gt;What Makes the DB Machine Special&lt;/li&gt;
&lt;li style=&quot;font-size: 9pt; margin-left: 15px;&quot;&gt;Smart Scan in Theory&lt;/li&gt;
&lt;li style=&quot;font-size: 9pt; margin-left: 15px;&quot;&gt;How Smart Scan Functions - Demo&amp;nbsp;&lt;/li&gt;
&lt;li style=&quot;font-size: 9pt; margin-left: 15px;&quot;&gt;Smart Scan in Practice&amp;nbsp;&lt;/li&gt;
&lt;li style=&quot;font-size: 9pt; margin-left: 15px;&quot;&gt;Making Smart Scan Work - Demo&lt;/li&gt;
&lt;li style=&quot;font-size: 9pt; margin-left: 15px;&quot;&gt;HCC in Theory&amp;nbsp;&lt;/li&gt;
&lt;li style=&quot;font-size: 9pt; margin-left: 15px;&quot;&gt;HCC performance and Compression Ratio - Demo&amp;nbsp;&lt;/li&gt;
&lt;li style=&quot;font-size: 9pt; margin-left: 15px;&quot;&gt;HCC Limitations and Best Practices&amp;nbsp;&lt;/li&gt;
&lt;li style=&quot;font-size: 9pt; margin-left: 15px;&quot;&gt;HCC Compression Degradation Issue - Demo&amp;nbsp;&lt;/li&gt;
&lt;li style=&quot;font-size: 9pt; margin-left: 15px;&quot;&gt;Exadata is Good But Not Easy&lt;/li&gt;
&lt;/ul&gt;
&lt;div style=&quot;background-color: white; text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 12px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cbohl.blogspot.com/feeds/1577020804032016432/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/27939696/1577020804032016432' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/27939696/posts/default/1577020804032016432'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/27939696/posts/default/1577020804032016432'/><link rel='alternate' type='text/html' href='http://cbohl.blogspot.com/2012/06/oracle-exadata-database-machine.html' title='Oracle Exadata Database Machine Tutorials'/><author><name>Christoph Bohl</name><uri>http://www.blogger.com/profile/13659990813733751317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-27939696.post-2638344390941171286</id><published>2012-06-04T13:49:00.002+02:00</published><updated>2012-06-04T13:49:44.142+02:00</updated><title type='text'>11g Optimizer Statistics</title><content type='html'>Earlier this year, Oracle posted two excellent white papers about Optimizer Statistics:&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://www.oracle.com/ocom/groups/public/@otn/documents/webcontent/1354477.pdf&quot; target=&quot;_blank&quot;&gt;Understanding Optimizer Statistics (January 2012)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.oracle.com/ocom/groups/public/@otn/documents/webcontent/1577139.pdf&quot; target=&quot;_blank&quot;&gt;Best Practices for Gathering Optimizer Statistics (April 2012)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
They are worth reading!</content><link rel='replies' type='application/atom+xml' href='http://cbohl.blogspot.com/feeds/2638344390941171286/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/27939696/2638344390941171286' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/27939696/posts/default/2638344390941171286'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/27939696/posts/default/2638344390941171286'/><link rel='alternate' type='text/html' href='http://cbohl.blogspot.com/2012/06/11g-optimizer-statistics.html' title='11g Optimizer Statistics'/><author><name>Christoph Bohl</name><uri>http://www.blogger.com/profile/13659990813733751317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-27939696.post-7822244443721127301</id><published>2012-02-27T10:23:00.000+01:00</published><updated>2012-02-27T10:23:18.981+01:00</updated><title type='text'>Generate Optimizer Trace Files</title><content type='html'>After starting this post about generating optimizer trace files, I found that Greg Rahn has already written a perfect overview of all methods to achieve this &lt;a href=&quot;http://structureddata.org/2011/08/18/creating-optimizer-trace-files/&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;.</content><link rel='replies' type='application/atom+xml' href='http://cbohl.blogspot.com/feeds/7822244443721127301/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/27939696/7822244443721127301' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/27939696/posts/default/7822244443721127301'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/27939696/posts/default/7822244443721127301'/><link rel='alternate' type='text/html' href='http://cbohl.blogspot.com/2012/02/generate-optimizer-trace-files.html' title='Generate Optimizer Trace Files'/><author><name>Christoph Bohl</name><uri>http://www.blogger.com/profile/13659990813733751317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-27939696.post-4660455939739067907</id><published>2012-02-14T08:18:00.001+01:00</published><updated>2012-02-14T08:18:11.990+01:00</updated><title type='text'>Upgrading to 11g: Optimizer Changes</title><content type='html'>When migrating to Oracle to a newer version, there is and will always be an impact on the performance of existing queries. Hence, it is wise to perform a full performance regression test with your software against the new version.&lt;br /&gt;
&lt;br /&gt;
Oracle has published a good white paper which explains the new features of the Optimizer in 11g and lists important pre- and post-upgrade tasks. Check it out here: &lt;a href=&quot;http://www.oracle.com/technetwork/database/focus-areas/bi-datawarehousing/twp-upgrading-10g-to-11g-what-to-ex-133707.pdf&quot;&gt;Upgrading from Oracle Database 10g to 11g: What to expect from the Optimizer&lt;/a&gt;.</content><link rel='replies' type='application/atom+xml' href='http://cbohl.blogspot.com/feeds/4660455939739067907/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/27939696/4660455939739067907' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/27939696/posts/default/4660455939739067907'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/27939696/posts/default/4660455939739067907'/><link rel='alternate' type='text/html' href='http://cbohl.blogspot.com/2012/02/upgrading-to-11g-optimizer-changes.html' title='Upgrading to 11g: Optimizer Changes'/><author><name>Christoph Bohl</name><uri>http://www.blogger.com/profile/13659990813733751317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-27939696.post-358359089104775043</id><published>2011-10-21T09:24:00.000+02:00</published><updated>2011-10-21T09:24:15.099+02:00</updated><title type='text'>Lock / Hang Analysis</title><content type='html'>When I have to analyze database lock or even hang issues, I use the following SQL statements, scripts and references:

&lt;br /&gt;
&lt;pre class=&quot;sql&quot; name=&quot;code&quot;&gt;-- all sessions involved in blocking
-- - blocked sessions
select * 
from   v$session ses
where  ses.blocking_session is not null
union
-- - blockers
select * 
from   v$session ses
where  sid in ( select blocking_session from v$session where blocking_session is not null )
;

-- find root blocker
select &#39;alter system kill session &#39;&#39;&#39;||sid||&#39;,&#39;||serial#||&#39;&#39;&#39; immediate;&#39; kill_db_cmd
,      &#39;kill -9 &#39;||process as kill_os_cmd
,      s.*
from   v$session s
where  sid in ( 
   select blocking_session
   from   v$session
              )
and    blocking_session is null              
--and    username = &#39;DBUSER&#39;
--and    osuser = &#39;osuser&#39;
;

-- ddl lock information
select dlk.session_id
,      ses.serial#
,      ses.username
,      ses.schemaname
,      ses.machine
,      ses.logon_time
,      dlk.owner
,      dlk.name
,      dlk.type
,      dlk.mode_held
,      dlk.mode_requested
,      &#39;alter system kill session &#39;&#39;&#39;||ses.sid||&#39;,&#39;||ses.serial#||&#39;&#39;&#39; immediate;&#39;
from   dba_ddl_locks dlk
  inner join v$session ses
          on dlk.session_id = ses.sid
where (mode_held &amp;lt;&amp;gt; &#39;Null&#39; or mode_requested &amp;lt;&amp;gt; &#39;None&#39;)
order by dlk.session_id    
;

-- library cache lock information
select distinct ses.ksusenum as sid
,      ses.ksuseser          as serial#
,      ses.ksuudlna          as username
,      ses.ksusemnm          as module
,      obj.kglnaown          as object_owner
,      obj.kglnaobj          as object_name
,      lck.kgllkcnt          as lock_count
,      lck.kgllkmod          as lock_mode
,      lck.kgllkreq          as lock_req
,      swt.state             as wait_state
,      swt.event             as wait_event
,      swt.seconds_in_wait   as sec_in_wait
from   x$kgllk lck        -- library object locks (both held and requested)
,      x$kglob obj        -- objects
,      x$ksuse ses        -- sessions
,      v$session_wait swt -- session wait
where  lck.kgllkreq &amp;gt; 0   -- a lock is requested
and    obj.kglhdadr = lck.kgllkhdl
and    lck.kgllkuse = ses.addr
and    swt.sid = ses.indx
order by swt.seconds_in_wait desc
;

sta ?/rdbms/admin/utllockt
--WAITING_SESSION   LOCK_TYPE         MODE_REQUESTED MODE_HELD      LOCK_ID1          LOCK_ID2
------------------- ----------------- -------------- -------------- ----------------- -----------------
--524               None
--   511            Transaction       Exclusive      Exclusive      1835044           8310

-- it might also be of interest to look into ash
-- history, query coordinator, etc
select * 
from   v$active_session_history
where  time_waited &amp;gt; 0
;

-- displays a row for each lock or latch that is being held, and one row for each outstanding request for a lock or latch.
--  http://download.oracle.com/docs/cd/B14117_01/server.101/b10755/statviews_2210.htm
select * 
from   dba_lock_internal
;

-- all locked objects
select oracle_username
,      os_user_name
,      session_id
,      locked_mode
,      object_name
,      object_type
from   v$locked_object lob
,      dba_objects obj
where  lob.object_id = obj.object_id
order by oracle_username
,        os_user_name
,        session_id
;

-- enqueues
select sid
,      event
,      chr(bitand(p1,-16777216)/16777215)|| chr(bitand(p1, 16711680)/65535) &quot;type&quot;
,      mod(p1,16) as &quot;mode&quot; 
,      p2
,      p3 
from   v$session_wait 
where  event like &#39;enq%&#39;
; 

-- cumulated statistics on enqueues
select * 
from   v$enqueue_statistics
;


-- see who accesses an object
select *
from   v$access
where  object like &#39;BLA&#39;
;

-- oradebug dump systemstate
-- - shows complete dump of all processes including locks held/requested
-- - dump created in user dump dest
-- - connect as sysdba
oradebug setmypid
oradebug unlimit
oradebug dump systemstate 266
oradebug tracefile_name
&lt;/pre&gt;
&lt;br /&gt;
Links / References:&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;MOS: How to Find which Session is Holding a Particular Library Cache Lock [ID 122793.1]&lt;/li&gt;
&lt;li&gt;
&lt;a href=&quot;http://orainternals.wordpress.com/2009/06/02/library-cache-lock-and-library-cache-pin-waits/&quot;&gt;http://orainternals.wordpress.com/2009/06/02/library-cache-lock-and-library-cache-pin-waits/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.evdbt.com/enqwaits.sql&quot;&gt;http://www.evdbt.com/enqwaits.sql&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.perfvision.com/papers/09_enqueues.ppt&quot;&gt;http://www.perfvision.com/papers/09_enqueues.ppt&lt;/a&gt;

&lt;/li&gt;
&lt;/ul&gt;</content><link rel='replies' type='application/atom+xml' href='http://cbohl.blogspot.com/feeds/358359089104775043/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/27939696/358359089104775043' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/27939696/posts/default/358359089104775043'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/27939696/posts/default/358359089104775043'/><link rel='alternate' type='text/html' href='http://cbohl.blogspot.com/2011/10/lock-hang-analysis.html' title='Lock / Hang Analysis'/><author><name>Christoph Bohl</name><uri>http://www.blogger.com/profile/13659990813733751317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-27939696.post-3797913745978654319</id><published>2011-08-16T16:01:00.004+02:00</published><updated>2011-08-16T16:23:32.548+02:00</updated><title type='text'>Oracle Performance Diagnostic Guide</title><content type='html'>The Oracle way of identifying database hang and performance issues: &lt;a href=&quot;https://support.oracle.com/CSP/main/article?cmd=show&amp;type=NOT&amp;doctype=TROUBLESHOOTING&amp;id=390374.1&quot;&gt;Oracle Support Note 390374.1&lt;/a&gt;.</content><link rel='replies' type='application/atom+xml' href='http://cbohl.blogspot.com/feeds/3797913745978654319/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/27939696/3797913745978654319' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/27939696/posts/default/3797913745978654319'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/27939696/posts/default/3797913745978654319'/><link rel='alternate' type='text/html' href='http://cbohl.blogspot.com/2011/08/oracle-performance-diagnostic-guide.html' title='Oracle Performance Diagnostic Guide'/><author><name>Christoph Bohl</name><uri>http://www.blogger.com/profile/13659990813733751317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-27939696.post-2829554581993637187</id><published>2011-06-21T07:12:00.004+02:00</published><updated>2011-06-21T07:16:06.362+02:00</updated><title type='text'>Check Database Character Set</title><content type='html'>There are several possible ways to find out the database character set:&lt;br /&gt;&lt;br /&gt;&lt;pre name=&quot;code&quot; class=&quot;sql&quot;&gt;select value&lt;br /&gt;from   nls_database_parameters&lt;br /&gt;where  parameter = &#39;NLS_CHARACTERSET&#39;&lt;br /&gt;;&lt;br /&gt;&lt;br /&gt;select property_value&lt;br /&gt;from   database_properties&lt;br /&gt;where  property_name = &#39;NLS_CHARACTERSET&#39;&lt;br /&gt;;&lt;br /&gt;&lt;br /&gt;select value$&lt;br /&gt;from   sys.props$&lt;br /&gt;where  name = &#39;NLS_CHARACTERSET&#39;&lt;br /&gt;;&lt;br /&gt;&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://cbohl.blogspot.com/feeds/2829554581993637187/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/27939696/2829554581993637187' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/27939696/posts/default/2829554581993637187'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/27939696/posts/default/2829554581993637187'/><link rel='alternate' type='text/html' href='http://cbohl.blogspot.com/2011/06/check-database-character-set.html' title='Check Database Character Set'/><author><name>Christoph Bohl</name><uri>http://www.blogger.com/profile/13659990813733751317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-27939696.post-6153700395675198998</id><published>2011-06-20T08:45:00.002+02:00</published><updated>2011-06-20T08:49:08.794+02:00</updated><title type='text'>Exadata - finally!</title><content type='html'>Just connected to an exadata database! An awesome feeling!&lt;br /&gt;&lt;br /&gt;We are doing a POC on a X2-2 half rack. The first results are extremely promising!</content><link rel='replies' type='application/atom+xml' href='http://cbohl.blogspot.com/feeds/6153700395675198998/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/27939696/6153700395675198998' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/27939696/posts/default/6153700395675198998'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/27939696/posts/default/6153700395675198998'/><link rel='alternate' type='text/html' href='http://cbohl.blogspot.com/2011/06/exadata-finally.html' title='Exadata - finally!'/><author><name>Christoph Bohl</name><uri>http://www.blogger.com/profile/13659990813733751317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-27939696.post-1661870699202879086</id><published>2011-06-06T17:01:00.003+02:00</published><updated>2011-06-06T17:05:31.235+02:00</updated><title type='text'>Get Explain Plan From AWR</title><content type='html'>To get an explain plan from the AWR for a statement that ran in the past, use the queries below:&lt;br /&gt;&lt;br /&gt;&lt;pre name=&quot;code&quot; class=&quot;sql&quot;&gt;select *&lt;br /&gt;from   dba_hist_sqltext&lt;br /&gt;where  sql_text like &#39;%SQL Text you are looking for%&#39;&lt;br /&gt;;&lt;br /&gt;&lt;br /&gt;select *&lt;br /&gt;from   table(dbms_xplan.display_awr(&#39;&amp;lt;sql_id&amp;gt;&#39;,null,null,&#39;ALL&#39;))&lt;br /&gt;;&lt;br /&gt;&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://cbohl.blogspot.com/feeds/1661870699202879086/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/27939696/1661870699202879086' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/27939696/posts/default/1661870699202879086'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/27939696/posts/default/1661870699202879086'/><link rel='alternate' type='text/html' href='http://cbohl.blogspot.com/2011/06/get-explain-plan-from-awr.html' title='Get Explain Plan From AWR'/><author><name>Christoph Bohl</name><uri>http://www.blogger.com/profile/13659990813733751317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-27939696.post-6629345435232824231</id><published>2011-05-10T12:52:00.002+02:00</published><updated>2011-05-10T12:53:23.435+02:00</updated><title type='text'>Explain The Explain Plan</title><content type='html'>Oracle has published a good introduction to reading execution plans on &lt;a href=&quot;http://www.oracle.com/technetwork/database/focus-areas/bi-datawarehousing/twp-explain-the-explain-plan-052011-393674.pdf&quot;&gt;OTN&lt;/a&gt;.</content><link rel='replies' type='application/atom+xml' href='http://cbohl.blogspot.com/feeds/6629345435232824231/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/27939696/6629345435232824231' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/27939696/posts/default/6629345435232824231'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/27939696/posts/default/6629345435232824231'/><link rel='alternate' type='text/html' href='http://cbohl.blogspot.com/2011/05/explain-explain-plan.html' title='Explain The Explain Plan'/><author><name>Christoph Bohl</name><uri>http://www.blogger.com/profile/13659990813733751317</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-27939696.post-2631662353590743775</id><published>2011-03-21T13:00:00.002+01:00</published><updated>2011-09-26T14:38:39.596+02:00</updated><title type='text'>Show Temporary Space Usage</title><content type='html'>Need to know how much temp space is in use? By which session/SQL command?&lt;br /&gt;
&lt;br /&gt;
Show the current temporary space usage:&lt;br /&gt;
&lt;pre class=&quot;sql&quot; name=&quot;code&quot;&gt;
-- current temp space usage
select tablespace
,      contents
,      segtype
,      used_mb
,      round(used_mb/1024) used_gb
from   (
  select tsu.tablespace
  ,      tsu.contents
  ,      tsu.segtype
  ,      round((tsu.blocks * tsp.block_size / 1024 / 1024)) used_mb
  from   v$tempseg_usage tsu
    inner join dba_tablespaces tsp
            on tsu.tablespace = tsp.tablespace_name
    )
;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
Show the current temporary space usage per tablespace:&lt;br /&gt;
&lt;pre class=&quot;sql&quot; name=&quot;code&quot;&gt;
-- current temp space usage per tablespace
select tablespace
,      size_mb
,      used_mb
,      size_mb - used_mb as free_mb
,      round(size_mb/1024) size_gb
,      round(used_mb/1024) used_gb
,      round(size_mb/1024) - round(used_mb/1024) as free_gb
,      round(nvl((size_mb - used_mb)/size_mb * 100, 0)) pct_free
from   (
  select tsu.tablespace
  ,      df.size_mb
  ,      round((tsu.blocks * tsp.block_size / 1024 / 1024)) used_mb
  from   (
            select tablespace
            ,      sum(blocks) blocks
            from   v$tempseg_usage
            group by tablespace
         ) tsu
    inner join (
                  select tablespace_name
                  ,      round(sum(bytes)/1014/124) size_mb 
                  from   dba_temp_files
                  group by tablespace_name
                  union all
                  select tablespace_name
                  ,      round(sum(bytes)/1014/124) size_mb 
                  from   dba_data_files
                  group by tablespace_name
               ) df
            on tsu.tablespace = df.tablespace_name
    inner join dba_tablespaces tsp
            on tsu.tablespace = tsp.tablespace_name
    )
;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
Show the current temporary space usage per session:&lt;br /&gt;
&lt;pre class=&quot;sql&quot; name=&quot;code&quot;&gt;
-- temp space usage per session
select ses.sid
,      ses.serial#
,      ses.username
,      ses.osuser
,      ses.process
,      ses.machine
,      ses.module
,      ses.program
,      tsu.tablespace
,      tsu.contents
,      tsu.segtype
,      round(tsu.blocks * tsp.block_size / 1024 / 1024) as used_mb
,      round(tsu.blocks * tsp.block_size / 1024 / 1024 / 1024) as used_gb
,      sql.sql_fulltext
from   v$tempseg_usage tsu
  inner join v$session ses
          on tsu.session_addr = ses.saddr
  inner join dba_tablespaces tsp
          on tsu.tablespace = tsp.tablespace_name
  left outer join v$sql sql
          on tsu.sql_id = sql.sql_id
;&lt;/pre&gt;
</content><link rel='replies' type='application/atom+xml' href='http://cbohl.blogspot.com/feeds/2631662353590743775/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/27939696/2631662353590743775' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/27939696/posts/default/2631662353590743775'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/27939696/posts/default/2631662353590743775'/><link rel='alternate' type='text/html' href='http://cbohl.blogspot.com/2011/03/show-temporary-space-usage.html' title='Show Temporary Space Usage'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-27939696.post-6341651065993828458</id><published>2011-02-17T10:36:00.002+01:00</published><updated>2011-02-17T10:42:00.910+01:00</updated><title type='text'>Find Tracefile Name</title><content type='html'>The SQL below shows the tracefile name and location for the current session:&lt;br /&gt;&lt;br /&gt;&lt;pre name=&quot;code&quot; class=&quot;sql&quot;&gt;&lt;br /&gt;select ud.value || &#39;/&#39; || &lt;br /&gt;       dn.value || &#39;_ora_&#39; || &lt;br /&gt;       p.spid || &lt;br /&gt;       nvl2(p.traceid,  &#39;_&#39; || p.traceid, null ) ||&lt;br /&gt;       &#39;.trc&#39;  &quot;Trace File&quot;&lt;br /&gt;from   v$session s&lt;br /&gt;  inner join v$process p&lt;br /&gt;          on s.paddr = p.addr&lt;br /&gt;  cross join (&lt;br /&gt;     select value &lt;br /&gt;     from   v$parameter&lt;br /&gt;     where  name = &#39;user_dump_dest&#39;&lt;br /&gt;             ) ud&lt;br /&gt;  cross join (&lt;br /&gt;     select value &lt;br /&gt;     from   v$parameter&lt;br /&gt;     where  name = &#39;db_name&#39;&lt;br /&gt;             ) dn&lt;br /&gt;where s.audsid = sys_context(&#39;userenv&#39;,&#39;sessionid&#39;)&lt;br /&gt;;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;With Oracle 11g, the tracefile is available directly in v$process:&lt;br /&gt;&lt;br /&gt;&lt;pre name=&quot;code&quot; class=&quot;sql&quot;&gt;&lt;br /&gt;select p.tracefile &lt;br /&gt;from   v$session s &lt;br /&gt;  inner join v$process p&lt;br /&gt;          on s.paddr = p.addr&lt;br /&gt;where  sys_context(&#39;userenv&#39;,&#39;sessionid&#39;) = s.audsid&lt;br /&gt;;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Note that there seems to be a bug in pre Oracle 11g releases. v$process.traceid returns to the tracefile_identifier you have set for your session on all non-background processes... Therefore the result of the query below is wrong for pre 11g releases.&lt;br /&gt;&lt;br /&gt;&lt;pre name=&quot;code&quot; class=&quot;sql&quot;&gt;&lt;br /&gt;alter session set tracefile_identifier = &#39;mytraceid&#39;;&lt;br /&gt;&lt;br /&gt;select ud.value || &#39;/&#39; || &lt;br /&gt;       dn.value || &#39;_ora_&#39; || &lt;br /&gt;       p.spid || &lt;br /&gt;       nvl2(p.traceid,  &#39;_&#39; || p.traceid, null ) ||&lt;br /&gt;       &#39;.trc&#39;  &quot;Trace File&quot;&lt;br /&gt;from   v$session s&lt;br /&gt;  inner join v$process p&lt;br /&gt;          on s.paddr = p.addr&lt;br /&gt;  cross join (&lt;br /&gt;     select value &lt;br /&gt;     from   v$parameter&lt;br /&gt;     where  name = &#39;user_dump_dest&#39;&lt;br /&gt;             ) ud&lt;br /&gt;  cross join (&lt;br /&gt;     select value &lt;br /&gt;     from   v$parameter&lt;br /&gt;     where  name = &#39;db_name&#39;&lt;br /&gt;             ) dn&lt;br /&gt;&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://cbohl.blogspot.com/feeds/6341651065993828458/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/27939696/6341651065993828458' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/27939696/posts/default/6341651065993828458'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/27939696/posts/default/6341651065993828458'/><link rel='alternate' type='text/html' href='http://cbohl.blogspot.com/2011/02/find-tracefile-name.html' title='Find Tracefile Name'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-27939696.post-6063218641322163135</id><published>2011-01-07T09:07:00.002+01:00</published><updated>2011-01-18T09:05:34.445+01:00</updated><title type='text'>Determine The Owner Of A Package</title><content type='html'>Sometimes it is useful to know the owner of a PL/SQL Package at runtime.&lt;br /&gt;&lt;br /&gt;Hm, why would we not know which owner a package belongs to? There are multiple reasons. A utility package might be installed in several schemata, or in development, every developer might have his own copy of the application schemata.&lt;br /&gt;&lt;br /&gt;One way to find the owner, is by inspecting the PL/SQL call stack. The latest entry on the stack references the current PL/SQL object and its owner.&lt;br /&gt;&lt;br /&gt;Example of a call stack:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;----- PL/SQL Call Stack -----&lt;br /&gt;  object      line  object&lt;br /&gt;  handle    number&lt;br /&gt;name&lt;br /&gt;3e218c390        13  package body PKG_OWNER.PKG_DEFINER_RIGHTS&lt;br /&gt;3e5e67860         6  package body PKG_OWNER2.PKG_REAL&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Why don&#39;t we just use &lt;code&gt;sys_context(&#39;userenv&#39;, &#39;current_schema&#39;)&lt;/code&gt;? The current schema is not always the package owner. If you are using a PL/SQL package with invoker rights (&lt;code&gt;authid current_user&lt;/code&gt;), it shows the caller.&lt;br /&gt;&lt;br /&gt;OK, let&#39;s start with the preparation for a simple example. We&#39;ll create two database users first, pkg_owner (which will own the PL/SQL packages) and pkg_caller (which will invoke them).&lt;br /&gt;&lt;br /&gt;&lt;pre name=&quot;code&quot; class=&quot;sql&quot;&gt;&lt;br /&gt;create user pkg_owner identified by pkg_owner;&lt;br /&gt;grant connect, create procedure to pkg_owner;&lt;br /&gt;&lt;br /&gt;create user pkg_caller identified by pkg_caller;&lt;br /&gt;grant connect to pkg_caller;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Next, we create to packages, pkg_definer_rights with definer rights and pkg_invoker_rights with invoker rights in the pkg_owner schema. Both have a function to retrieve the current schema and another function to get the owner from the callstack.&lt;br /&gt;&lt;br /&gt;&lt;pre name=&quot;code&quot; class=&quot;sql&quot;&gt;&lt;br /&gt;-- create the test packages in the pkg_owner schema&lt;br /&gt;connect pkg_owner/pkg_owner;&lt;br /&gt;--/&lt;br /&gt;create or replace package pkg_definer_rights&lt;br /&gt;is&lt;br /&gt;  -- get current schema always returns the owner for AUTHID DEFINER packages&lt;br /&gt;  function get_current_schema return varchar2;&lt;br /&gt;  -- the call stack always shows the correct owner, no matter what AUTHID is set to&lt;br /&gt;  function get_owner_by_callstack return varchar2;&lt;br /&gt;&lt;br /&gt;end;&lt;br /&gt;/&lt;br /&gt;--/&lt;br /&gt;create or replace package body pkg_definer_rights&lt;br /&gt;is&lt;br /&gt;&lt;br /&gt;  function get_current_schema return varchar2 &lt;br /&gt;  is&lt;br /&gt;  begin&lt;br /&gt;    return sys_context(&#39;userenv&#39;, &#39;current_schema&#39;);&lt;br /&gt;  end;&lt;br /&gt;&lt;br /&gt;  function get_owner_by_callstack return varchar2&lt;br /&gt;  is&lt;br /&gt;  begin&lt;br /&gt;    -- the first occurrence of the pattern &lt;word&gt;.&lt;word&gt; in the call stack&lt;br /&gt;    --   is &lt;owner&gt;.&lt;package&gt; of the least recently called package (i.e. this one)&lt;br /&gt;    -- therefore take the &lt;owner&gt;.&lt;package&gt; string out of the call stack and&lt;br /&gt;    --   then take just the first part before the dot as the owner&lt;br /&gt;    return regexp_replace(regexp_substr(dbms_utility.format_call_stack&lt;br /&gt;                                       ,&#39;[A-Z][A-Z0-9_$#]*\.[A-Z][A-Z0-9_$#]*&#39;,1,1,&#39;i&#39;&lt;br /&gt;                                       )&lt;br /&gt;                         ,&#39;([A-Z][A-Z0-9_$#]*)\.([A-Z][A-Z0-9_$#]*)&#39;,&#39;\1&#39;,1,1,&#39;i&#39;&lt;br /&gt;                         );&lt;br /&gt;  end;&lt;br /&gt;&lt;br /&gt;end;&lt;br /&gt;/&lt;br /&gt;&lt;br /&gt;--/&lt;br /&gt;create or replace package pkg_invoker_rights&lt;br /&gt;authid current_user&lt;br /&gt;is&lt;br /&gt;&lt;br /&gt;  -- get current schema returns the current schema, not the package owner for &lt;br /&gt;  --   AUTHID CURRENT_USER packages&lt;br /&gt;  function get_current_schema return varchar2;&lt;br /&gt;  -- the call stack always shows the correct owner, no matter what AUTHID is set to&lt;br /&gt;  function get_owner_by_callstack return varchar2;&lt;br /&gt;&lt;br /&gt;end;&lt;br /&gt;/&lt;br /&gt;--/&lt;br /&gt;create or replace package body pkg_invoker_rights&lt;br /&gt;is&lt;br /&gt;&lt;br /&gt;  function get_current_schema return varchar2 &lt;br /&gt;  is&lt;br /&gt;  begin&lt;br /&gt;    return sys_context(&#39;userenv&#39;, &#39;current_schema&#39;);&lt;br /&gt;  end;&lt;br /&gt;&lt;br /&gt;  function get_owner_by_callstack return varchar2&lt;br /&gt;  is&lt;br /&gt;  begin&lt;br /&gt;    -- the first occurrence of the pattern &lt;word&gt;.&lt;word&gt; in the call stack&lt;br /&gt;    --   is &lt;owner&gt;.&lt;package&gt; of the least recently called package (i.e. this one)&lt;br /&gt;    -- therefore take the &lt;owner&gt;.&lt;package&gt; string out of the call stack and&lt;br /&gt;    --   then take just the first part before the dot as the owner&lt;br /&gt;    return regexp_replace(regexp_substr(dbms_utility.format_call_stack&lt;br /&gt;                                       ,&#39;[A-Z][A-Z0-9_$#]*\.[A-Z][A-Z0-9_$#]*&#39;,1,1,&#39;i&#39;&lt;br /&gt;                                       )&lt;br /&gt;                         ,&#39;([A-Z][A-Z0-9_$#]*)\.([A-Z][A-Z0-9_$#]*)&#39;,&#39;\1&#39;,1,1,&#39;i&#39;&lt;br /&gt;                         );&lt;br /&gt;  end;&lt;br /&gt;&lt;br /&gt;end;&lt;br /&gt;/&lt;br /&gt;&lt;br /&gt;grant execute on pkg_definer_rights to pkg_caller;&lt;br /&gt;grant execute on pkg_invoker_rights to pkg_caller;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;OK, we&#39;re prepared. So let&#39;s test them:&lt;br /&gt;&lt;pre name=&quot;code&quot; class=&quot;sql&quot;&gt;&lt;br /&gt;-- connect as caller to invoke the test packages&lt;br /&gt;connect pkg_caller/pkg_caller;&lt;br /&gt;--&lt;br /&gt;select pkg_owner.pkg_definer_rights.get_current_schema definer_current_schema&lt;br /&gt;,      pkg_owner.pkg_invoker_rights.get_current_schema invoker_current_schema&lt;br /&gt;,      pkg_owner.pkg_definer_rights.get_owner_by_callstack definer_owner_by_callstack&lt;br /&gt;,      pkg_owner.pkg_invoker_rights.get_owner_by_callstack invoker_owner_by_callstack&lt;br /&gt;from   dual&lt;br /&gt;;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;DEFINER_CURRENT_SCHEMA:        PKG_OWNER&lt;br /&gt;INVOKER_CURRENT_SCHEMA:        PKG_CALLER&lt;br /&gt;DEFINER_OWNER_BY_CALLSTACK:    PKG_OWNER&lt;br /&gt;INVOKER_OWNER_BY_CALLSTACK:    PKG_OWNER&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;As expected, the function pkg_invoker_rights.get_current_schema does not return the package owner, but the current schema. It can be changed using &lt;code&gt;alter session set current_schema=schema&lt;/code&gt;.&lt;br /&gt;&lt;br /&gt;&lt;pre name=&quot;code&quot; class=&quot;sql&quot;&gt;&lt;br /&gt;alter session set current_schema = pkg_owner;&lt;br /&gt;select pkg_owner.pkg_definer_rights.get_current_schema definer_current_schema&lt;br /&gt;,      pkg_owner.pkg_invoker_rights.get_current_schema invoker_current_schema&lt;br /&gt;,      pkg_owner.pkg_definer_rights.get_owner_by_callstack owner_by_callstack&lt;br /&gt;,      pkg_owner.pkg_invoker_rights.get_owner_by_callstack invoker_owner_by_callstack&lt;br /&gt;from   dual&lt;br /&gt;;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;DEFINER_CURRENT_SCHEMA:        PKG_OWNER&lt;br /&gt;INVOKER_CURRENT_SCHEMA:        PKG_OWNER&lt;br /&gt;DEFINER_OWNER_BY_CALLSTACK:    PKG_OWNER&lt;br /&gt;INVOKER_OWNER_BY_CALLSTACK:    PKG_OWNER&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Yes, the invoker current schema now reflects our alter session command.&lt;br /&gt;&lt;br /&gt;If we&#39;d like to include the code of the function &lt;code&gt;get_owner_by_callstack&lt;/code&gt; in a common utility package and not include it in each and every PL/SQL Unit we are developing, does our example still work?&lt;br /&gt;&lt;br /&gt;To find out, we create a package pkg_real in a new schema, pkg_owner2. This package is a mock up for one of our actual application package that want to make use of our utility to show the package owner:&lt;br /&gt;&lt;br /&gt;&lt;pre name=&quot;code&quot; class=&quot;sql&quot;&gt;&lt;br /&gt;create user pkg_owner2 identified by pkg_owner2;&lt;br /&gt;grant connect, create procedure to pkg_owner2;&lt;br /&gt;&lt;br /&gt;-- grant permissions to pkg_owner2&lt;br /&gt;connect pkg_owner/pkg_owner;&lt;br /&gt;grant execute on pkg_definer_rights to pkg_owner2;&lt;br /&gt;&lt;br /&gt;-- create an invoking package&lt;br /&gt;connect pkg_owner2/pkg_owner2;&lt;br /&gt;&lt;br /&gt;create or replace package pkg_real&lt;br /&gt;is&lt;br /&gt;  function real_function return varchar2;&lt;br /&gt;end;&lt;br /&gt;/&lt;br /&gt;create or replace package body pkg_real&lt;br /&gt;is&lt;br /&gt;  function real_function return varchar2&lt;br /&gt;  is&lt;br /&gt;  begin&lt;br /&gt;    return pkg_owner.pkg_definer_rights.get_owner_by_callstack;&lt;br /&gt;  end;&lt;br /&gt;end;&lt;br /&gt;/&lt;br /&gt;&lt;br /&gt;grant execute on pkg_real to pkg_caller;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;OK, now we test our package:&lt;br /&gt;&lt;br /&gt;&lt;pre name=&quot;code&quot; class=&quot;sql&quot;&gt;&lt;br /&gt;-- call the real one&lt;br /&gt;connect pkg_caller/pkg_caller&lt;br /&gt;--&lt;br /&gt;select pkg_owner2.pkg_real.real_function&lt;br /&gt;from   dual&lt;br /&gt;;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;PKG_REAL_OWNER&lt;br /&gt;--------------&lt;br /&gt;PKG_OWNER&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Is this correct? No! The owner is pkg_owner2, not pkg_owner... What went wrong? Let&#39;s look at the call stack:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;----- PL/SQL Call Stack -----&lt;br /&gt;  object      line  object&lt;br /&gt;  handle    number&lt;br /&gt;name&lt;br /&gt;3e218c390        13  package body PKG_OWNER.PKG_DEFINER_RIGHTS&lt;br /&gt;3e5e67860         6  package body PKG_OWNER2.PKG_REAL&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Of course! The top most entry in the call stack is now the utility function, not the real application package that we&#39;re interested in. So we change the method to get the second line in the call stack which will be the actual package that uses the utility function:&lt;br /&gt;&lt;br /&gt;&lt;pre name=&quot;code&quot; class=&quot;sql&quot;&gt;&lt;br /&gt;connect pkg_owner/pkg_owner&lt;br /&gt;--&lt;br /&gt;create or replace package body pkg_definer_rights&lt;br /&gt;is&lt;br /&gt;&lt;br /&gt;  function get_current_schema return varchar2 &lt;br /&gt;  is&lt;br /&gt;  begin&lt;br /&gt;    return sys_context(&#39;userenv&#39;, &#39;current_schema&#39;);&lt;br /&gt;  end;&lt;br /&gt;&lt;br /&gt;  function get_owner_by_callstack return varchar2&lt;br /&gt;  is&lt;br /&gt;  begin&lt;br /&gt;    -- the first occurrence of the pattern &lt;word&gt;.&lt;word&gt; in the call stack&lt;br /&gt;    --   is &lt;owner&gt;.&lt;package&gt; of the least recently called package (i.e. this one)&lt;br /&gt;    -- therefore take the &lt;owner&gt;.&lt;package&gt; string out of the call stack and&lt;br /&gt;    --   then take just the first part before the dot as the owner&lt;br /&gt;    return regexp_replace(regexp_substr(dbms_utility.format_call_stack&lt;br /&gt;                                       ,&#39;[A-Z][A-Z0-9_$#]*\.[A-Z][A-Z0-9_$#]*&#39;,1,2,&#39;i&#39;&lt;br /&gt;                                       )&lt;br /&gt;                         ,&#39;([A-Z][A-Z0-9_$#]*)\.([A-Z][A-Z0-9_$#]*)&#39;,&#39;\1&#39;,1,1,&#39;i&#39;&lt;br /&gt;                         );&lt;br /&gt;  end;&lt;br /&gt;&lt;br /&gt;end;&lt;br /&gt;/&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;And we try again:&lt;br /&gt;&lt;br /&gt;&lt;pre name=&quot;code&quot; class=&quot;sql&quot;&gt;&lt;br /&gt;-- try again&lt;br /&gt;connect pkg_caller/pkg_caller&lt;br /&gt;--&lt;br /&gt;select pkg_owner2.pkg_real.real_function&lt;br /&gt;from   dual&lt;br /&gt;;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;REAL_FUNCTION&lt;br /&gt;-------------&lt;br /&gt;PKG_OWNER2&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;OK, that looks better :-)</content><link rel='replies' type='application/atom+xml' href='http://cbohl.blogspot.com/feeds/6063218641322163135/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/27939696/6063218641322163135' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/27939696/posts/default/6063218641322163135'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/27939696/posts/default/6063218641322163135'/><link rel='alternate' type='text/html' href='http://cbohl.blogspot.com/2011/01/determine-owner-of-package.html' title='Determine The Owner Of A Package'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-27939696.post-3774797155858318152</id><published>2010-12-03T12:10:00.003+01:00</published><updated>2010-12-03T12:13:07.515+01:00</updated><title type='text'>Dynamic Memory Components</title><content type='html'>&lt;pre name=&quot;code&quot; class=&quot;sql&quot;&gt;&lt;br /&gt;-- version 10g&lt;br /&gt;show sga;&lt;br /&gt;-- sga dynamic components (ASMM, SGA_TARGET)&lt;br /&gt;select component&lt;br /&gt;,      current_size/1024/1024 &quot;CURRENT_SIZE&quot;&lt;br /&gt;,      min_size/1024/1024 &quot;MIN_SIZE&quot;&lt;br /&gt;,      user_specified_size/1024/1024 &quot;USER_SPECIFIED_SIZE&quot;&lt;br /&gt;,      last_oper_type &quot;TYPE&quot; &lt;br /&gt;from   v$sga_dynamic_components&lt;br /&gt;;&lt;br /&gt;-- sga dynamic free memory (to be allocated by oracle)&lt;br /&gt;select current_size/1024/1024 &quot;Current Size MB&quot;&lt;br /&gt;from   v$sga_dynamic_free_memory&lt;br /&gt;;&lt;br /&gt;-- sga resize operations&lt;br /&gt;select component&lt;br /&gt;,      oper_type&lt;br /&gt;,      oper_mode&lt;br /&gt;,      initial_size/1024/1024 &quot;INITIAL&quot;&lt;br /&gt;,      TARGET_SIZE/1024/1024 &quot;TARGET&quot;&lt;br /&gt;,      FINAL_SIZE/1024/1024 &quot;FINAL&quot;&lt;br /&gt;,      status &lt;br /&gt;,      TO_CHAR(end_time, &#39;YYYY-MM-DD HH24:MI:SS&#39;) &quot;DATE&quot; &lt;br /&gt;from   v$sga_resize_ops&lt;br /&gt;;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre name=&quot;code&quot; class=&quot;sql&quot;&gt;&lt;br /&gt;-- version 11g&lt;br /&gt;show sga;&lt;br /&gt;-- memory dynamic components (ASMM, MEMORY_TARGET)&lt;br /&gt;select component&lt;br /&gt;,      current_size/1024/1024 &quot;CURRENT_SIZE&quot;&lt;br /&gt;,      min_size/1024/1024 &quot;MIN_SIZE&quot;&lt;br /&gt;,      user_specified_size/1024/1024 &quot;USER_SPECIFIED_SIZE&quot;&lt;br /&gt;,      last_oper_type &quot;TYPE&quot; &lt;br /&gt;,      TO_CHAR(last_oper_time, &#39;YYYY-MM-DD HH24:MI:SS&#39;) &quot;DATE&quot; &lt;br /&gt;from   v$memory_dynamic_components&lt;br /&gt;;&lt;br /&gt;-- memory resize operations&lt;br /&gt;select component&lt;br /&gt;,      oper_type&lt;br /&gt;,      oper_mode&lt;br /&gt;,      initial_size/1024/1024 &quot;INITIAL&quot;&lt;br /&gt;,      TARGET_SIZE/1024/1024 &quot;TARGET&quot;&lt;br /&gt;,      FINAL_SIZE/1024/1024 &quot;FINAL&quot;&lt;br /&gt;,      status &lt;br /&gt;,      TO_CHAR(end_time, &#39;YYYY-MM-DD HH24:MI:SS&#39;) &quot;DATE&quot; &lt;br /&gt;from   v$memory_resize_ops&lt;br /&gt;;&lt;br /&gt;&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://cbohl.blogspot.com/feeds/3774797155858318152/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/27939696/3774797155858318152' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/27939696/posts/default/3774797155858318152'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/27939696/posts/default/3774797155858318152'/><link rel='alternate' type='text/html' href='http://cbohl.blogspot.com/2010/12/dynamic-memory-components.html' title='Dynamic Memory Components'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-27939696.post-4010638469209609071</id><published>2010-11-10T16:16:00.004+01:00</published><updated>2010-12-17T14:06:37.312+01:00</updated><title type='text'>Manually Recompile Objects</title><content type='html'>Sometimes one needs to manually recompile objects in the database. The query below generates the commands required. It does however not take care of any sequencing that might be required.&lt;br /&gt;&lt;br /&gt;I have posted tips for &quot;automatic&quot; re-compilation &lt;a href=&quot;http://cbohl.blogspot.com/2007/02/re-compile-invalid-objects.html&quot;&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;&lt;pre name=&quot;code&quot; class=&quot;sql&quot;&gt;&lt;br /&gt;select &#39;alter &#39;||&lt;br /&gt;          case when object_type = &#39;PACKAGE BODY&#39; then &#39;PACKAGE&#39;&lt;br /&gt;               when object_type = &#39;TYPE BODY&#39; then &#39;TYPE&#39;&lt;br /&gt;               when (object_type = &#39;SYNONYM&#39; and owner = &#39;PUBLIC&#39;) then &#39;PUBLIC SYNONYM&#39;&lt;br /&gt;            else object_type &lt;br /&gt;          end||&#39; &#39;||&lt;br /&gt;          case when (object_type = &#39;SYNONYM&#39; and owner = &#39;PUBLIC&#39;) then null&lt;br /&gt;            else owner||&#39;.&#39; &lt;br /&gt;          end||&lt;br /&gt;          object_name||&#39; compile&#39;||&lt;br /&gt;          case when object_type in (&#39;PACKAGE BODY&#39;,&#39;TYPE BODY&#39;) then &#39; BODY&#39;&lt;br /&gt;            else null &lt;br /&gt;          end||&#39;;&#39;&lt;br /&gt;from   dba_objects&lt;br /&gt;where  status != &#39;VALID&#39;&lt;br /&gt;and    owner like &#39;T136291%&#39;&lt;br /&gt;;&lt;br /&gt;&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://cbohl.blogspot.com/feeds/4010638469209609071/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/27939696/4010638469209609071' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/27939696/posts/default/4010638469209609071'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/27939696/posts/default/4010638469209609071'/><link rel='alternate' type='text/html' href='http://cbohl.blogspot.com/2010/11/manually-recompile-objects.html' title='Manually Recompile Objects'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-27939696.post-241361297356697509</id><published>2010-11-03T15:07:00.003+01:00</published><updated>2010-11-03T15:14:36.602+01:00</updated><title type='text'>Killing A Datapump Job</title><content type='html'>If you need to kill a datapump import or export job (impdp/expdp), it is not sufficient to just kill the operating system process.&lt;br&gt;&lt;br /&gt;The oracle job will still be pending. It can be stopped by using the PL/SQL API or the impdp/expdp utilities.&lt;br&gt;&lt;br /&gt;Here is an example of how to attach to the job and stop it immediately.&lt;br /&gt;&lt;br /&gt;&lt;pre name=&quot;code&quot; class=&quot;shell&quot;&gt;&lt;br /&gt;expdp &#39;userid=&quot;/ as sysdba&quot;&#39; attach=&amp;lt;NAME_OF_JOB&amp;gt;&lt;br /&gt;Export&gt; stop_job=immediate&lt;br /&gt;Are you sure you wish to stop this job ([y]/n): y&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Here&#39;s how to find running impdp/expdp jobs:&lt;br /&gt;&lt;pre name=&quot;code&quot; class=&quot;sql&quot;&gt;&lt;br /&gt;select * &lt;br /&gt;from   dba_datapump_jobs&lt;br /&gt;;&lt;br /&gt;&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://cbohl.blogspot.com/feeds/241361297356697509/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/27939696/241361297356697509' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/27939696/posts/default/241361297356697509'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/27939696/posts/default/241361297356697509'/><link rel='alternate' type='text/html' href='http://cbohl.blogspot.com/2010/11/killing-datapump-job.html' title='Killing A Datapump Job'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>