Oracle 11g: Reading alert log via SQL

Oracle has done some major improvements in the diagnosability infrastructure in version 11g. Here’s one little detail.

Before Oracle 11g it is possible to access the alert log via SQL using an external table or a pipelined function which in turn uses utl_file.
After reading the text you need to parse it to extract the information you need from there.

Starting from 11g Oracle does all this work for you. There is a fixed table X$DBGALERTEXT, when you query it, Oracle reads the log.xml from alert directory (which contains all the data what alert.log does), parses it and returns the details back as rows:

SQL> select message_text from X$DBGALERTEXT where rownum <= 20;

MESSAGE_TEXT
-----------------------------------------------------------------------------------------------------------------
Starting ORACLE instance (normal)
LICENSE_MAX_SESSION = 0
LICENSE_SESSIONS_WARNING = 0
Shared memory segment for instance monitoring created
Picked latch-free SCN scheme 2
Using LOG_ARCHIVE_DEST_10 parameter default value as USE_DB_RECOVERY_FILE_DEST
Autotune of undo retention is turned on.
IMODE=BR
ILAT =18
LICENSE_MAX_USERS = 0
SYS auditing is disabled
Starting up ORACLE RDBMS Version: 11.1.0.7.0.
Using parameter settings in client-side pfile /u01/app/oracle/admin/LIN11G/pfile/init.ora on machine linux03
System parameters with non-default values:
  processes                = 150
  memory_target            = 404M
  control_files            = "/u01/oradata/LIN11G/control01.ctl"
  control_files            = "/u01/oradata/LIN11G/control02.ctl"
  control_files            = "/u01/oradata/LIN11G/control03.ctl"
  db_block_size            = 8192

20 rows selected.

This is the text representation, but you can get individual details from other columns as listed below:

[Read more...]

Miladin Modrakovic’s blog: lots of undocumented Oracle stuff

If you get a kick out of learning Oracle internals, especially undocumented commands then check out Miladin’s blog:

http://www.oraclue.com/

His blog uses the same wordpress template as mine, but the content and authors are different!

He has also published detailed notes about Oracle diagnostic events and about some serious improvements in 11g event syntax (as the whole diagnostics infrastructure got a major upgrade in 11g).

Just beware to not run anything in your non-toy databases without seriously thinking & testing why should the feature help and whether it’s safe to use it at all. Most undocumented stuff (in anyone’s blogs, including mine) should be used only in those rare cases where conventional, documented or at least widely used methods dont help.

New presentation slides plus AOT seminars in Hong-Kong and Dallas

Conferences & Slides

Here are the slides of my recent presentations at Hotsos Symposium and UTOUG events:

Advanced Oracle Troubleshooting Seminar

I have added Dallas, Salt Lake City, Denver and Hong-Kong to my Advanced Oracle Troubleshooting seminar list for first half of 2009, the full list is below. Check http://blog.tanelpoder.com/seminar/ for outline, scripts, example slides and details.

Seminar dates and locations 2009:

2-3. April – Miracle @ Utrecht, Netherlandshttp://www.miraclebenelux.nl/tanel/

13-14. April – Oracle @ Singaporehttp://www.oracle.com/education/apac/sg_tanel_poder.html

16-17. April – Oracle @ Sydneyhttp://www.oracle.com/education/apac/au_tanel_poder.html

20-21. April – Oracle @ Melbournehttp://www.oracle.com/education/apac/au_tanel_poder.html

23-24. April Oracle @ Hong-Konghttp://www.oracle.com/education/apac/hk_tanel_poder.html

27.-28. April – PiSec Ltd @ Edinburghhttp://www.pisec.org/index.php?option=com_content&view=article&id=6&Itemid=12

11-12. May – Oracle @ Spainhttp://education.oracle.com/pls/web_prod-plq-dad/show_desc.redirect?dc=D70365_1060245&p_org_id=51&lang=E&source_call=

18-19. May – Miracle @ Denmarkhttp://www.miracleas.dk/index.php?option=com_content&view=article&id=100:advanced-oracle-troubleshooting&catid=19:info&Itemid=71

3.-5. June – Method-R @ Dallas, TXhttp://www.method-r.com

10-12. June – Trutek @ Salt Lake City, UThttp://www.trutek.com/index.php?id=165

15-17. June – Trutek @ Denver, COhttp://www.trutek.com/index.php?id=165

Oracle, Timesten and PL/SQL support

I thought to post about another new interest of mine, TimestTen, as I’ve worked with it in past and I have become a fan of it, especially after Oracle bought the company.

Oracle has announced that TimesTen in-memory database will support PL/SQL in the upcoming release. That’s in 11gR2, where TimesTen is named the “in-memory database cache”.

I’m happy to see the deep level of integration Oracle is doing with it. It looks like both classic Oracle RDBMS and the TimesTen based code will have a (partially) shared PL/SQL code base.
There’s already a package called UTL_IDENT in Oracle 11.1.0.7 which stores couple variables used for conditional compilation depedent on the database product the packages are installed:

SQL> select dbms_metadata.get_ddl('PACKAGE', 'UTL_IDENT') from dual;

DBMS_METADATA.GET_DDL('PACKAGE','UTL_IDENT')
--------------------------------------------------------------------

  CREATE OR REPLACE PACKAGE "SYS"."UTL_IDENT" is

  /* A typical usage of these boolean constants is

         $if utl_ident.is_oracle_server $then
           code supported for Oracle Database
         $elsif utl_ident.is_timesten $then
           code supported for TimesTen Database
         $end
   */

  is_oracle_server     constant boolean := TRUE;
  is_oracle_client     constant boolean := FALSE;
  is_timesten          constant boolean := FALSE;

end utl_ident;
/

It looks that there will be at least some utility packages which share common code base with classic Oracle RDBMS and just use different code internally if needed, based on the UTL_IDENT variables.

This was a nice surprise as such approach promises to have full PL/SQL utilities in TimesTen cache and no discrepancy between the PL/SQL utility capabilities available in different platforms. So (I hope) there will be just one PL/SQL, not one PL/SQL version for Oracle and other for the cache.
Back before 9i days, it was quite annoying to hit the SQL interface discrepancies between PL/SQL and native SQL engines. So there’s hope that there are gonna be less porting issues between Oracle classic RDBMS and TimesTen cache (both for application developers and TimesTen coders as only low level interfaces need to be changed).

Well, at least in theory it’s like that… But I hope Oracle/TimesTen coders will do a good job with this as I’ve worked with some algorithmic trading apps doing extreme transaction processing and in this world you don’t even like wasted microseconds as this directly translates to lost trading opportunities and lost potential revenue. The legacy solutions for such apps are usually some in-memory data stores, often built in house and lots of C++ code around it for procedural work. The data is then loaded / dumped to some disk-based RDBMS asynchronously (as the multi-millisecond response times of a classic RDBMS take ages!!!)

I’m waiting to get my hands on the 11gR2 (as everyone who’s reading this blog I suspect :), but especially the integrated in-memory database cache engine as it promises to make the life easier for a lot of algorithmic trading systems developers (and also the ability adapt quicker to ever-changing markets and growing complexity of products for investment banks and trading houses).

New US seminar dates

Here are two more US dates of my Advanced Oracle Troubleshooting seminars, organized by Trutek.

These seminars are 3 days each, so there will be more time to thoroughly explain things and do even more demos!!! :)

10-12. June – Trutek @ Salt Lake City, UThttp://www.trutek.com/index.php?id=165
15-17. June – Trutek @ Denver, COhttp://www.trutek.com/index.php?id=165

New version of TPT script set uploaded

The latest version of my TPT scripts are downloadable from the link below (TPT means Tanel Poder’s Troubleshooting (or tuning) scripts ;)

http://www.tanelpoder.com/files/TPT_public.zip

In the zip file there are over 300 Oracle sql scripts which I use for my everyday work. Also the demo scripts I show at Advanced Oracle Troubleshooting seminar are in there as well (in aot subdirectory).

To my seminar attendees in New York this week: I had a typo in the TPT script download link, the link above is the correct one!

Multipart cursor subexecution and PRECOMPUTE_SUBQUERY hint

There was a question about PRECOMPUTE_SUBQUERY hint in an Oracle Forums thread.

Here I will post the answer I gave there and also elaborate it more as it explains a little known interesting fact about Oracle cursor management. Also it allows me to introduce few advanced Oracle troubleshooting scripts by example. This is a fairly long post, but if you are interested in some Oracle cursor management and SQL execution internals, keep on reading ;)

Consider the following test case with two tables, T1 and T2:

SQL> create table t1 as select rownum a from dual connect by level < 10;

Table created.

SQL> create table t2 as select rownum+10 b from dual connect by level < 10;

Table created.

SQL>
SQL> select * from t1;

         A
----------
         1
         2
         3
         4
         5
         6
         7
         8
         9

9 rows selected.

SQL>
SQL> select * from t2;

         B
----------
        11
        12
        13
        14
        15
        16
        17
        18
        19

9 rows selected.

Now lets run a query with a simple subquery in it:

SQL> select a
  2  from   t1
  3  where  a in (select b from t2);

no rows selected

SQL> select * from table(dbms_xplan.display_cursor(null,null,'ALLSTATS LAST'));

PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------
SQL_ID  aucw6byq3d5q8, child number 0
-------------------------------------
select a from   t1 where  a in (select b from t2)

Plan hash value: 561629455

----------------------------------------------------------------------------
| Id  | Operation           | Name     | E-Rows |  OMem |  1Mem | Used-Mem |
----------------------------------------------------------------------------
|   0 | SELECT STATEMENT    |          |        |       |       |          |
|*  1 |  HASH JOIN SEMI     |          |      1 |  1066K|  1066K| 1056K (0)|
|   2 |   TABLE ACCESS FULL | T1       |      9 |       |       |          |
|   3 |   VIEW              | VW_NSO_1 |      9 |       |       |          |
|   4 |    TABLE ACCESS FULL| T2       |      9 |       |       |          |
----------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   1 - access("A"="B")

Note that a hash semijoin was performed which semijoined two of its child rowsources with join condition “A=B”.

Now lets run exactly the same query with PRECOMPUTE_SUBQUERY hint in subquery block:

SQL> select a
  2  from   t1
  3  where  a in (select /*+ PRECOMPUTE_SUBQUERY */b from t2);

no rows selected

SQL>
SQL> select * from table(dbms_xplan.display_cursor(null,null,'ALLSTATS LAST'));

PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------
SQL_ID  fvnqhjkcjnybx, child number 0
-------------------------------------
select a from   t1 where  a in (select /*+ PRECOMPUTE_SUBQUERY */b from
t2)

Plan hash value: 3617692013

-------------------------------------------
| Id  | Operation         | Name | E-Rows |
-------------------------------------------
|   0 | SELECT STATEMENT  |      |        |
|*  1 |  TABLE ACCESS FULL| T1   |      5 |
-------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   1 - filter(("A"=11 OR "A"=12 OR "A"=13 OR "A"=14 OR "A"=15 OR "A"=16
              OR "A"=17 OR "A"=18 OR "A"=19))

See what happened! The join is gone and it looks like table T2 is not accessed at all (as there is only one TABLE ACCESS rowsource which reads from table T1 ).

However, there has appeared a filter condition which has all the values from T2 in it! How are these values retrieved?

A simple sql_trace reveals this:

[Read more...]

New year and some news…

First, Happy New Year to you all!

This year I promise to organize my blog a little better, to have some index of my articles, scripts etc :)

Here are the news…

I’ve moved my blog…

In December, when visiting Shanghai, I noticed that my blog was not accessible from there. Apparently the state firewall blocks all access to wordpress.com IPs.

So I have moved my blog to a virtual private server, off wordpress.com – my blog should be accessible from China now as well.

My Advanced Oracle Troubleshooting Seminars in year 2009

If you like the contents of my blog or conference presentations, you’ll sure like my 2-day seminar!

 

Here are the dates and links for more info:

3-4. February – NYOUG @ New York Cityhttp://www.nyoug.org/etc/training/htm/NYOUG_Training_Session.htm

NB! As this is my first public seminar in US, you’ll be able to attend it for a very very good price! And the early bird registration (which gives you even better price) is open until end of today! More seminars in other US cities are planned for 2nd half of 2009.

2-3. April – Miracle @ Netherlandshttp://www.miraclebv.nl/

Probably happens in Utrecht, I’ll keep you updated if it changes.

13-14. April – Oracle @ Singaporehttp://www.oracle.com/education/apac/sg_tanel_poder.html

16-17. April – Oracle @ Sydneyhttp://www.oracle.com/education/apac/au_tanel_poder.html

20-21. April – Oracle @ Melbournehttp://www.oracle.com/education/apac/au_tanel_poder.html

23-24. April Oracle @ Aucklandhttp://www.oracle.com/education/apac/nz_tanel_poder.html

27-28. April – PiSec Ltd @ Edinburghhttp://www.pisec.org/index.php?option=com_content&view=article&id=6&Itemid=12

11-12. May – Oracle @ Spainhttp://education.oracle.com/pls/web_prod-plq-dad/show_desc.redirect?dc=D70365_1060245&p_org_id=51&lang=E&source_call=

18-19. May – Miracle @ Denmarkhttp://www.miracleas.dk/index.php?option=com_content&view=article&id=100:advanced-oracle-troubleshooting&catid=19:info&Itemid=71

 

Note that the Advanced Oracle Troubleshooting seminar is meant mainly for experienced DBAs and performance engineers as I go very deep in Oracle internals and OS/hardware details.

See more details about my seminar here

Conferences in 2009

11-12. February – RMOUG Conference @ Denver, Colorado

I will be delivering two presentations about advanced Oracle troubleshooting, tuning and internals:

8-12. March – Hotsos Symposium @ Dallas, Texas

I will be delivering two presentations:

As the second title says, I don’t use any slides at that presentation, I will just demo some of the scripts and tools I use every day plus few case studies. It will be fun!

Also, I look forward attending the Training Day by Jonathan Lewis on Oracle troubleshooting, on last day of the Symposium.

Updated links

If you haven’t seen Dan Morgan’s Oracle library yet at http://www.psoug.org/library.html then now it’s time to do so!

I think what he’s done is awesome and I use his library almost every day when I don’t remember some syntax off the top of my head. I normally just google for keywords like “create hash cluster psoug” so I get the wanted page first in search results.

I’ve added the link into my blogroll.

Little oradebug enhancement in Oracle 11g

There’s a command called: ORADEBUG SETORAPNAME in 11g.

It allows you to attach to a named background process as shown below, so you don’t need to figure out what’s the PID or SPID of the target process.

SQL> oradebug setorapname dbw0
Oracle pid: 9, Unix process pid: 5506, image: oracle@linux03 (DBW0)
SQL>
SQL> oradebug setorapname pmon
Oracle pid: 2, Unix process pid: 5490, image: oracle@linux03 (PMON)
SQL>

Even though you probably don’t want to mess around with background processes in production DBs, in demos and just Oracle research it can help you save couple of seconds every now and then.